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 f53129c..1f4b5c8 100644 --- a/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java +++ b/app/src/main/java/it/danieleverducci/ojo/ui/MainActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; +import android.util.Log; import android.view.View; import androidx.navigation.NavController; @@ -13,8 +14,10 @@ import it.danieleverducci.ojo.R; import it.danieleverducci.ojo.databinding.ActivityMainBinding; public class MainActivity extends AppCompatActivity { + private static final String TAG = "MainActivity"; private ActivityMainBinding binding; + private NavController navController; @Override protected void onCreate(Bundle savedInstanceState) { @@ -24,7 +27,7 @@ public class MainActivity extends AppCompatActivity { setContentView(binding.getRoot()); // Show FAB only on first fragment - NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main); + navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main); navController.addOnDestinationChangedListener((controller, destination, arguments) -> { if (destination.getId() == R.id.HomeFragment) binding.fab.show(); @@ -35,8 +38,17 @@ public class MainActivity extends AppCompatActivity { binding.fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - navController.navigate(R.id.action_homeToSettings); + navigateToFragment(R.id.action_homeToSettings); } }); } + + public void navigateToFragment(int actionId) { + if (navController == null) { + Log.e(TAG, "Not initialized"); + return; + } + + navController.navigate(actionId); + } } \ No newline at end of file diff --git a/app/src/main/java/it/danieleverducci/ojo/ui/SettingsFragment.java b/app/src/main/java/it/danieleverducci/ojo/ui/SettingsFragment.java index 14f4a88..f542a94 100644 --- a/app/src/main/java/it/danieleverducci/ojo/ui/SettingsFragment.java +++ b/app/src/main/java/it/danieleverducci/ojo/ui/SettingsFragment.java @@ -55,6 +55,13 @@ public class SettingsFragment extends Fragment { touchHelper.attachToRecyclerView(recyclerView); adapter.setOnDragListener(touchHelper::startDrag); recyclerView.setAdapter(adapter); + // Onclick listener + adapter.setOnClickListener(new SettingsRecyclerViewAdapter.OnClickListener() { + @Override + public void onItemClick(Camera c) { + ((MainActivity)getActivity()).navigateToFragment(R.id.action_homeToSettings); + } + }); } return view; } diff --git a/app/src/main/java/it/danieleverducci/ojo/ui/adapters/SettingsRecyclerViewAdapter.java b/app/src/main/java/it/danieleverducci/ojo/ui/adapters/SettingsRecyclerViewAdapter.java index 5628cef..0211aa3 100644 --- a/app/src/main/java/it/danieleverducci/ojo/ui/adapters/SettingsRecyclerViewAdapter.java +++ b/app/src/main/java/it/danieleverducci/ojo/ui/adapters/SettingsRecyclerViewAdapter.java @@ -24,6 +24,7 @@ public class SettingsRecyclerViewAdapter extends RecyclerView.Adapter mValues; private OnDragListener dragListener; + private OnClickListener clickListener; public SettingsRecyclerViewAdapter(List items) { mValues = items; @@ -38,6 +39,12 @@ public class SettingsRecyclerViewAdapter extends RecyclerView.Adapter