From 63b08fe718626af3b9211fe4a75a459f517eee4e Mon Sep 17 00:00:00 2001 From: "Daniele Verducci (Slimpenguin)" Date: Mon, 31 Jan 2022 08:35:57 +0100 Subject: [PATCH] Navigation refactoring --- .../danieleverducci/ojo/ui/MainActivity.java | 11 ++--------- app/src/main/res/navigation/nav_graph.xml | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java b/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java index 1542681..f53129c 100644 --- a/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java +++ b/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java @@ -2,23 +2,16 @@ package it.danieleverducci.ojo.ui; import android.os.Bundle; -import com.google.android.material.snackbar.Snackbar; - import androidx.appcompat.app.AppCompatActivity; import android.view.View; import androidx.navigation.NavController; import androidx.navigation.Navigation; -import androidx.navigation.ui.AppBarConfiguration; -import androidx.navigation.ui.NavigationUI; import it.danieleverducci.ojo.R; import it.danieleverducci.ojo.databinding.ActivityMainBinding; -import android.view.Menu; -import android.view.MenuItem; - public class MainActivity extends AppCompatActivity { private ActivityMainBinding binding; @@ -33,7 +26,7 @@ public class MainActivity extends AppCompatActivity { // Show FAB only on first fragment NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main); navController.addOnDestinationChangedListener((controller, destination, arguments) -> { - if (destination.getId() == R.id.FirstFragment) + if (destination.getId() == R.id.HomeFragment) binding.fab.show(); else binding.fab.hide(); @@ -42,7 +35,7 @@ public class MainActivity extends AppCompatActivity { binding.fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - navController.navigate(R.id.action_FirstFragment_to_SecondFragment); + navController.navigate(R.id.action_homeToSettings); } }); } diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 4967b66..11b6d44 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -3,23 +3,26 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/nav_graph" - app:startDestination="@id/FirstFragment"> + app:startDestination="@id/HomeFragment"> + + android:id="@+id/action_settingsToHome" + app:destination="@id/HomeFragment" /> + \ No newline at end of file