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,19 +1,19 @@
|
||||
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() {
|
||||
return mText;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
@@ -32,4 +32,4 @@ public class HomeFragment extends Fragment {
|
||||
});
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
Reference in New Issue
Block a user