1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-18 21:16:48 -06:00

Adds fragments and simple navigation between them

This commit is contained in:
RicomenPL 2017-07-13 17:26:37 +02:00
parent ae61ebc52a
commit 4bebc831ad
13 changed files with 206 additions and 40 deletions

View File

@ -30,5 +30,6 @@ dependencies {
compile 'org.jsoup:jsoup:1.10.2'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
testCompile 'junit:junit:4.12'
}

View File

@ -1,39 +1,59 @@
package io.github.wulkanowy.activity.dashboard;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;
import android.support.v4.app.FragmentTransaction;
import io.github.wulkanowy.R;
import io.github.wulkanowy.activity.dashboard.attendance.AttendanceFragment;
import io.github.wulkanowy.activity.dashboard.board.BoardFragment;
import io.github.wulkanowy.activity.dashboard.lessonplan.LessonplanFragment;
import io.github.wulkanowy.activity.dashboard.marks.MarksFragment;
public class DashboardActivity extends AppCompatActivity {
private TextView mTextMessage;
MarksFragment marksFragment = new MarksFragment();
AttendanceFragment attendanceFragment = new AttendanceFragment();
BoardFragment boardFragment = new BoardFragment();
LessonplanFragment lessonplanFragment = new LessonplanFragment();
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
switch (item.getItemId()) {
case R.id.navigation_marks:
mTextMessage.setText(R.string.title_marks);
transaction.replace(R.id.fragment_container, marksFragment);
transaction.commit();
return true;
case R.id.navigation_attendance:
mTextMessage.setText(R.string.title_attendance);
transaction.replace(R.id.fragment_container, attendanceFragment);
transaction.commit();
return true;
case R.id.navigation_dashboard:
mTextMessage.setText(R.string.title_dashboard);
transaction.replace(R.id.fragment_container, boardFragment);
transaction.commit();
return true;
case R.id.navigation_lessonplan:
mTextMessage.setText(R.string.title_lessonplan);
transaction.replace(R.id.fragment_container, lessonplanFragment);
transaction.commit();
return true;
case R.id.navigation_settings:
mTextMessage.setText(R.string.title_settings);
/*
case R.id.navigation_settings:
return true;
*/
}
return false;
}
@ -44,10 +64,28 @@ public class DashboardActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setSelectedItemId(R.id.navigation_dashboard);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, boardFragment).commit();
}
public void onBackPressed() {
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
if (navigation.getSelectedItemId() != R.id.navigation_dashboard) {
navigation.setSelectedItemId(R.id.navigation_dashboard);
}
else if (navigation.getSelectedItemId() == R.id.navigation_dashboard){
moveTaskToBack(true);
}
}
}

View File

@ -0,0 +1,25 @@
package io.github.wulkanowy.activity.dashboard.attendance;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import io.github.wulkanowy.R;
public class AttendanceFragment extends Fragment {
public AttendanceFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_attendance, container, false);
}
}

View File

@ -0,0 +1,25 @@
package io.github.wulkanowy.activity.dashboard.board;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import io.github.wulkanowy.R;
public class BoardFragment extends Fragment {
public BoardFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_board, container, false);
}
}

View File

@ -0,0 +1,25 @@
package io.github.wulkanowy.activity.dashboard.lessonplan;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import io.github.wulkanowy.R;
public class LessonplanFragment extends Fragment {
public LessonplanFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_lessonplan, container, false);
}
}

View File

@ -0,0 +1,25 @@
package io.github.wulkanowy.activity.dashboard.marks;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import io.github.wulkanowy.R;
public class MarksFragment extends Fragment {
public MarksFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_marks, container, false);
}
}

View File

@ -6,25 +6,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="io.github.wulkanowy.activity.dashboard.DashboardActivity">
tools:context="io.github.wulkanowy.activity.dashboard.DashboardActivity"
android:weightSum="1">
<FrameLayout
android:id="@+id/content"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
android:layout_weight="1" />
<TextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:text="@string/title_dashboard" />
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"

View File

@ -0,0 +1,12 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.github.wulkanowy.activity.dashboard.attendance.AttendanceFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Fragment Frekwencja" />
</FrameLayout>

View File

@ -0,0 +1,14 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.github.wulkanowy.activity.dashboard.board.BoardFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Fragment Dashboard" />
</FrameLayout>

View File

@ -1,16 +0,0 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="io.github.wulkanowy.activity.dashboard.DashboardActivity$PlaceholderFragment">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

View File

@ -0,0 +1,12 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.github.wulkanowy.activity.dashboard.lessonplan.LessonplanFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Fragment Plan lekcji" />
</FrameLayout>

View File

@ -0,0 +1,13 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.github.wulkanowy.activity.dashboard.marks.MarksFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Fragment Oceny" />
</FrameLayout>

View File

@ -19,4 +19,6 @@
<string name="title_attendance">Attendance</string>
<string name="title_lessonplan">Lesson Plan</string>
<string name="title_settings">Settings</string>
<string name="hello_blank_fragment">TO JEST FRAGMENT</string>
</resources>