Adds top level navigation and placeholder fragments.

This commit is contained in:
2020-08-31 23:04:56 -07:00
parent cf1578d504
commit cfe7265238
19 changed files with 203 additions and 71 deletions

View File

@@ -31,7 +31,10 @@ public class MainActivity extends AppCompatActivity {
// Passing each menu ID as a set of Ids because each // Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations. // menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder( 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(); .build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);

View File

@@ -1,4 +1,4 @@
package com.majinnaibu.monstercards.ui.notifications; package com.majinnaibu.monstercards.ui.collections;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -14,17 +14,17 @@ import androidx.lifecycle.ViewModelProviders;
import com.majinnaibu.monstercards.R; 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, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
notificationsViewModel = collectionsViewModel =
ViewModelProviders.of(this).get(NotificationsViewModel.class); ViewModelProviders.of(this).get(CollectionsViewModel.class);
View root = inflater.inflate(R.layout.fragment_notifications, container, false); View root = inflater.inflate(R.layout.fragment_collections, container, false);
final TextView textView = root.findViewById(R.id.text_notifications); final TextView textView = root.findViewById(R.id.text_collections);
notificationsViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() { collectionsViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override @Override
public void onChanged(@Nullable String s) { public void onChanged(@Nullable String s) {
textView.setText(s); textView.setText(s);

View File

@@ -1,19 +1,19 @@
package com.majinnaibu.monstercards.ui.notifications; package com.majinnaibu.monstercards.ui.collections;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
public class NotificationsViewModel extends ViewModel { public class CollectionsViewModel extends ViewModel {
private MutableLiveData<String> mText; private MutableLiveData<String> mText;
public NotificationsViewModel() { public CollectionsViewModel() {
mText = new MutableLiveData<>(); mText = new MutableLiveData<>();
mText.setValue("This is notifications fragment"); mText.setValue("This is collections fragment");
} }
public LiveData<String> getText() { public LiveData<String> getText() {
return mText; return mText;
} }
} }

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -1,4 +1,4 @@
package com.majinnaibu.monstercards.ui.home; package com.majinnaibu.monstercards.ui.search;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -14,17 +14,17 @@ import androidx.lifecycle.ViewModelProviders;
import com.majinnaibu.monstercards.R; 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, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
homeViewModel = searchViewModel =
ViewModelProviders.of(this).get(HomeViewModel.class); ViewModelProviders.of(this).get(SearchViewModel.class);
View root = inflater.inflate(R.layout.fragment_home, container, false); View root = inflater.inflate(R.layout.fragment_search, container, false);
final TextView textView = root.findViewById(R.id.text_home); final TextView textView = root.findViewById(R.id.text_search);
homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() { searchViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override @Override
public void onChanged(@Nullable String s) { public void onChanged(@Nullable String s) {
textView.setText(s); textView.setText(s);
@@ -32,4 +32,4 @@ public class HomeFragment extends Fragment {
}); });
return root; return root;
} }
} }

View File

@@ -1,16 +1,16 @@
package com.majinnaibu.monstercards.ui.home; package com.majinnaibu.monstercards.ui.search;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
public class HomeViewModel extends ViewModel { public class SearchViewModel extends ViewModel {
private MutableLiveData<String> mText; private MutableLiveData<String> mText;
public HomeViewModel() { public SearchViewModel() {
mText = new MutableLiveData<>(); mText = new MutableLiveData<>();
mText.setValue("This is home fragment"); mText.setValue("This is search fragment");
} }
public LiveData<String> getText() { public LiveData<String> getText() {

View 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>

View File

@@ -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>

View 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>

View File

@@ -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>

View 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>

View File

@@ -3,8 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container" android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view" android:id="@+id/nav_view"
@@ -20,14 +19,17 @@
<fragment <fragment
android:id="@+id/nav_host_fragment" android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment" android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="0dp"
app:defaultNavHost="true" app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view" app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:navGraph="@navigation/mobile_navigation" /> app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -4,10 +4,10 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.notifications.NotificationsFragment"> tools:context=".ui.collections.CollectionsFragment">
<TextView <TextView
android:id="@+id/text_notifications" android:id="@+id/text_collections"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"

View 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>

View File

@@ -4,10 +4,10 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.home.HomeFragment"> tools:context=".ui.search.SearchFragment">
<TextView <TextView
android:id="@+id/text_home" android:id="@+id/text_search"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
@@ -19,4 +19,5 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -2,9 +2,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item <item
android:id="@+id/navigation_home" android:id="@+id/navigation_search"
android:icon="@drawable/ic_home_black_24dp" android:icon="@drawable/ic_search_black_24dp"
android:title="@string/title_home" /> android:title="@string/title_search" />
<item <item
android:id="@+id/navigation_dashboard" android:id="@+id/navigation_dashboard"
@@ -12,8 +12,13 @@
android:title="@string/title_dashboard" /> android:title="@string/title_dashboard" />
<item <item
android:id="@+id/navigation_notifications" android:id="@+id/navigation_collections"
android:icon="@drawable/ic_notifications_black_24dp" android:icon="@drawable/ic_collections_black_24dp"
android:title="@string/title_notifications" /> android:title="@string/title_collections" />
<item
android:id="@+id/navigation_library"
android:icon="@drawable/ic_library_black_24dp"
android:title="@string/title_library" />
</menu> </menu>

View File

@@ -3,23 +3,52 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation" android:id="@+id/mobile_navigation"
app:startDestination="@+id/navigation_home"> app:startDestination="@+id/navigation_dashboard">
<fragment <fragment
android:id="@+id/navigation_home" android:id="@+id/navigation_search"
android:name="com.majinnaibu.monstercards.ui.home.HomeFragment" android:name="com.majinnaibu.monstercards.ui.search.SearchFragment"
android:label="@string/title_home" android:label="@string/title_search"
tools:layout="@layout/fragment_home" /> tools:layout="@layout/fragment_search" >
<action
android:id="@+id/action_navigation_search_to_navigation_monster"
app:destination="@id/navigation_monster" />
</fragment>
<fragment <fragment
android:id="@+id/navigation_dashboard" android:id="@+id/navigation_dashboard"
android:name="com.majinnaibu.monstercards.ui.dashboard.DashboardFragment" android:name="com.majinnaibu.monstercards.ui.dashboard.DashboardFragment"
android:label="@string/title_dashboard" 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 <fragment
android:id="@+id/navigation_notifications" android:id="@+id/navigation_collections"
android:name="com.majinnaibu.monstercards.ui.notifications.NotificationsFragment" android:name="com.majinnaibu.monstercards.ui.collections.CollectionsFragment"
android:label="@string/title_notifications" android:label="@string/title_collections"
tools:layout="@layout/fragment_notifications" /> 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> </navigation>

View File

@@ -1,6 +1,7 @@
<resources> <resources>
<string name="app_name">MonsterCards</string> <string name="app_name">MonsterCards</string>
<string name="title_home">Home</string>
<string name="title_dashboard">Dashboard</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> </resources>