Search in sources :

Example 6 with UserViewModel

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();
}
Also used : NavigationView(com.google.android.material.navigation.NavigationView) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) NavHostFragment(androidx.navigation.fragment.NavHostFragment) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) NavigationView(com.google.android.material.navigation.NavigationView) AppBarConfiguration(androidx.navigation.ui.AppBarConfiguration) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

View (android.view.View)6 ViewModelProvider (androidx.lifecycle.ViewModelProvider)6 UserViewModel (com.example.first_responder_app.viewModels.UserViewModel)6 NavDirections (androidx.navigation.NavDirections)5 NavHostFragment (androidx.navigation.fragment.NavHostFragment)5 Bundle (android.os.Bundle)4 LayoutInflater (android.view.LayoutInflater)4 FirestoreDatabase (com.example.first_responder_app.FirestoreDatabase)4 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)4 TAG (android.content.ContentValues.TAG)3 Log (android.util.Log)3 ViewGroup (android.view.ViewGroup)3 Toast (android.widget.Toast)3 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 DataBindingUtil (androidx.databinding.DataBindingUtil)3 Fragment (androidx.fragment.app.Fragment)3 NavController (androidx.navigation.NavController)3 Navigation (androidx.navigation.Navigation)3 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)3