Adds top level navigation and placeholder fragments.
This commit is contained in:
@@ -31,7 +31,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
|
||||
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
|
||||
R.id.navigation_search,
|
||||
R.id.navigation_dashboard,
|
||||
R.id.navigation_collections,
|
||||
R.id.navigation_library)
|
||||
.build();
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.majinnaibu.monstercards.ui.notifications;
|
||||
package com.majinnaibu.monstercards.ui.collections;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -14,17 +14,17 @@ import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.majinnaibu.monstercards.R;
|
||||
|
||||
public class NotificationsFragment extends Fragment {
|
||||
public class CollectionsFragment extends Fragment {
|
||||
|
||||
private NotificationsViewModel notificationsViewModel;
|
||||
private CollectionsViewModel collectionsViewModel;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
notificationsViewModel =
|
||||
ViewModelProviders.of(this).get(NotificationsViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_notifications, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_notifications);
|
||||
notificationsViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
collectionsViewModel =
|
||||
ViewModelProviders.of(this).get(CollectionsViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_collections, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_collections);
|
||||
collectionsViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable String s) {
|
||||
textView.setText(s);
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.majinnaibu.monstercards.ui.notifications;
|
||||
package com.majinnaibu.monstercards.ui.collections;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class NotificationsViewModel extends ViewModel {
|
||||
public class CollectionsViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public NotificationsViewModel() {
|
||||
public CollectionsViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is notifications fragment");
|
||||
mText.setValue("This is collections fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.majinnaibu.monstercards.ui.library;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.majinnaibu.monstercards.R;
|
||||
|
||||
public class LibraryFragment extends Fragment {
|
||||
|
||||
private LibraryViewModel libraryViewModel;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
libraryViewModel =
|
||||
ViewModelProviders.of(this).get(LibraryViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_library, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_library);
|
||||
libraryViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable String s) {
|
||||
textView.setText(s);
|
||||
}
|
||||
});
|
||||
return root;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.majinnaibu.monstercards.ui.library;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class LibraryViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public LibraryViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is library fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
return mText;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.majinnaibu.monstercards.ui.home;
|
||||
package com.majinnaibu.monstercards.ui.search;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -14,17 +14,17 @@ import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.majinnaibu.monstercards.R;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
public class SearchFragment extends Fragment {
|
||||
|
||||
private HomeViewModel homeViewModel;
|
||||
private SearchViewModel searchViewModel;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
homeViewModel =
|
||||
ViewModelProviders.of(this).get(HomeViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_home, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_home);
|
||||
homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
searchViewModel =
|
||||
ViewModelProviders.of(this).get(SearchViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_search, container, false);
|
||||
final TextView textView = root.findViewById(R.id.text_search);
|
||||
searchViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable String s) {
|
||||
textView.setText(s);
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.majinnaibu.monstercards.ui.home;
|
||||
package com.majinnaibu.monstercards.ui.search;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class HomeViewModel extends ViewModel {
|
||||
public class SearchViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<String> mText;
|
||||
|
||||
public HomeViewModel() {
|
||||
public SearchViewModel() {
|
||||
mText = new MutableLiveData<>();
|
||||
mText.setValue("This is home fragment");
|
||||
mText.setValue("This is search fragment");
|
||||
}
|
||||
|
||||
public LiveData<String> getText() {
|
||||
13
app/src/main/res/drawable/ic_collections_black_24dp.xml
Normal file
13
app/src/main/res/drawable/ic_collections_black_24dp.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M4,6H2v14c0,1.1 0.9,2 2,2h14v-2H4V6z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM20,12l-2.5,-1.5L15,12L15,4h5v8z"/>
|
||||
</vector>
|
||||
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
|
||||
</vector>
|
||||
10
app/src/main/res/drawable/ic_library_black_24dp.xml
Normal file
10
app/src/main/res/drawable/ic_library_black_24dp.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M2,20h20v-4L2,16v4zM4,17h2v2L4,19v-2zM2,4v4h20L22,4L2,4zM6,7L4,7L4,5h2v2zM2,14h20v-4L2,10v4zM4,11h2v2L4,13v-2z"/>
|
||||
</vector>
|
||||
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
|
||||
</vector>
|
||||
10
app/src/main/res/drawable/ic_search_black_24dp.xml
Normal file
10
app/src/main/res/drawable/ic_search_black_24dp.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
|
||||
</vector>
|
||||
@@ -3,8 +3,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="?attr/actionBarSize">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
android:id="@+id/nav_view"
|
||||
@@ -20,14 +19,17 @@
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_host_fragment"
|
||||
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:defaultNavHost="true"
|
||||
app:layout_constraintBottom_toTopOf="@id/nav_view"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
app:navGraph="@navigation/mobile_navigation" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -4,10 +4,10 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.notifications.NotificationsFragment">
|
||||
tools:context=".ui.collections.CollectionsFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_notifications"
|
||||
android:id="@+id/text_collections"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
22
app/src/main/res/layout/fragment_library.xml
Normal file
22
app/src/main/res/layout/fragment_library.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.library.LibraryFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_library"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -4,10 +4,10 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.home.HomeFragment">
|
||||
tools:context=".ui.search.SearchFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_home"
|
||||
android:id="@+id/text_search"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
@@ -19,4 +19,5 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -2,9 +2,9 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/navigation_home"
|
||||
android:icon="@drawable/ic_home_black_24dp"
|
||||
android:title="@string/title_home" />
|
||||
android:id="@+id/navigation_search"
|
||||
android:icon="@drawable/ic_search_black_24dp"
|
||||
android:title="@string/title_search" />
|
||||
|
||||
<item
|
||||
android:id="@+id/navigation_dashboard"
|
||||
@@ -12,8 +12,13 @@
|
||||
android:title="@string/title_dashboard" />
|
||||
|
||||
<item
|
||||
android:id="@+id/navigation_notifications"
|
||||
android:icon="@drawable/ic_notifications_black_24dp"
|
||||
android:title="@string/title_notifications" />
|
||||
android:id="@+id/navigation_collections"
|
||||
android:icon="@drawable/ic_collections_black_24dp"
|
||||
android:title="@string/title_collections" />
|
||||
|
||||
<item
|
||||
android:id="@+id/navigation_library"
|
||||
android:icon="@drawable/ic_library_black_24dp"
|
||||
android:title="@string/title_library" />
|
||||
|
||||
</menu>
|
||||
@@ -3,23 +3,52 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/mobile_navigation"
|
||||
app:startDestination="@+id/navigation_home">
|
||||
app:startDestination="@+id/navigation_dashboard">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_home"
|
||||
android:name="com.majinnaibu.monstercards.ui.home.HomeFragment"
|
||||
android:label="@string/title_home"
|
||||
tools:layout="@layout/fragment_home" />
|
||||
android:id="@+id/navigation_search"
|
||||
android:name="com.majinnaibu.monstercards.ui.search.SearchFragment"
|
||||
android:label="@string/title_search"
|
||||
tools:layout="@layout/fragment_search" >
|
||||
<action
|
||||
android:id="@+id/action_navigation_search_to_navigation_monster"
|
||||
app:destination="@id/navigation_monster" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_dashboard"
|
||||
android:name="com.majinnaibu.monstercards.ui.dashboard.DashboardFragment"
|
||||
android:label="@string/title_dashboard"
|
||||
tools:layout="@layout/fragment_dashboard" />
|
||||
tools:layout="@layout/fragment_dashboard" >
|
||||
<action
|
||||
android:id="@+id/action_navigation_dashboard_to_navigation_monster"
|
||||
app:destination="@id/navigation_monster" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_notifications"
|
||||
android:name="com.majinnaibu.monstercards.ui.notifications.NotificationsFragment"
|
||||
android:label="@string/title_notifications"
|
||||
tools:layout="@layout/fragment_notifications" />
|
||||
android:id="@+id/navigation_collections"
|
||||
android:name="com.majinnaibu.monstercards.ui.collections.CollectionsFragment"
|
||||
android:label="@string/title_collections"
|
||||
tools:layout="@layout/fragment_collections" >
|
||||
<action
|
||||
android:id="@+id/action_navigation_collections_to_navigation_monster"
|
||||
app:destination="@id/navigation_monster" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_library"
|
||||
android:name="com.majinnaibu.monstercards.ui.library.LibraryFragment"
|
||||
android:label="@string/title_library"
|
||||
tools:layout="@layout/fragment_library" >
|
||||
<action
|
||||
android:id="@+id/action_navigation_library_to_navigation_monster"
|
||||
app:destination="@id/navigation_monster" />
|
||||
</fragment>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/navigation_monster"
|
||||
android:name="com.majinnaibu.monstercards.ui.monster.MonsterFragment"
|
||||
android:label="Monster"
|
||||
tools:layout="@layout/fragment_monster" />
|
||||
|
||||
</navigation>
|
||||
@@ -1,6 +1,7 @@
|
||||
<resources>
|
||||
<string name="app_name">MonsterCards</string>
|
||||
<string name="title_home">Home</string>
|
||||
<string name="title_dashboard">Dashboard</string>
|
||||
<string name="title_notifications">Notifications</string>
|
||||
<string name="title_search">Search</string>
|
||||
<string name="title_collections">Collections</string>
|
||||
<string name="title_library">Library</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user