use of com.example.first_responder_app.viewModels.UserViewModel in project FirstResponse by mattpost1700.
the class MainActivity method setupAppBar.
/**
* Setup the appbar for the application
*/
public void setupAppBar() {
// setup toolbar
toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("");
setSupportActionBar(toolbar);
// setup navigation drawer
drawer = findViewById(R.id.drawerLayout);
toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.open, R.string.close);
drawer.addDrawerListener(toggle);
toggle.syncState();
// setup navigation for drawer
NavHostFragment navHostFragment = (NavHostFragment) this.getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
navController = null;
if (navHostFragment != null) {
navController = navHostFragment.getNavController();
}
if (navController != null) {
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).setOpenableLayout(drawer).build();
NavigationView navView = findViewById(R.id.navView);
NavigationUI.setupWithNavController(navView, navController);
navView.setNavigationItemSelectedListener(this);
// Setup Nav Drawer user click event
View headerView = navView.getHeaderView(0);
headerView.findViewById(R.id.user_info).setOnClickListener(v -> {
if (activeUser != null) {
UserViewModel userViewModel = new ViewModelProvider(this).get(UserViewModel.class);
userViewModel.setUserDataModel(activeUser);
navController.navigate(R.id.userFragment);
closeNavDrawer();
} else {
Toast.makeText(this, "You must be logged in", Toast.LENGTH_LONG).show();
}
});
}
// save the navigation icon to use later
icon = toolbar.getNavigationIcon();
}
Aggregations