Navigation refactoring
This commit is contained in:
parent
8dc6da8b98
commit
63b08fe718
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/FirstFragment"
|
||||
android:id="@+id/HomeFragment"
|
||||
android:name="it.danieleverducci.ojo.ui.SurveillanceFragment"
|
||||
android:label="@string/first_fragment_label"
|
||||
tools:layout="@layout/fragment_surveillance">
|
||||
|
||||
<action
|
||||
android:id="@+id/action_FirstFragment_to_SecondFragment"
|
||||
android:id="@+id/action_homeToSettings"
|
||||
app:destination="@id/SettingsFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/SecondFragment"
|
||||
android:id="@+id/CameraUrlFragment"
|
||||
android:name="it.danieleverducci.ojo.ui.AddStreamFragment"
|
||||
android:label="@string/second_fragment_label"
|
||||
tools:layout="@layout/fragment_add_stream">
|
||||
<action
|
||||
android:id="@+id/action_cameraUrlToSettings"
|
||||
app:destination="@id/SettingsFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/SettingsFragment"
|
||||
@ -28,7 +31,10 @@
|
||||
tools:layout="@layout/fragment_settings_item_list" >
|
||||
|
||||
<action
|
||||
android:id="@+id/action_SecondFragment_to_FirstFragment"
|
||||
app:destination="@id/FirstFragment" />
|
||||
android:id="@+id/action_settingsToHome"
|
||||
app:destination="@id/HomeFragment" />
|
||||
<action
|
||||
android:id="@+id/action_settingsToCameraUrl"
|
||||
app:destination="@id/CameraUrlFragment" />
|
||||
</fragment>
|
||||
</navigation>
|
Loading…
Reference in New Issue
Block a user