From 252320d07bf59dc80d6555d113afb04c8cf6d1c3 Mon Sep 17 00:00:00 2001 From: sebastian Date: Fri, 1 Nov 2024 18:49:07 +0100 Subject: [PATCH] Switch to new Fragment "Concert Details" --- .../notevault/ui/gallery/ConcertAdapter.java | 26 ++++++++---------- .../notevault/ui/gallery/GalleryFragment.java | 27 ++++++++++++++++++- .../gallery/detail/ConcertDetailFragment.java | 6 +++++ .../res/layout/fragment_concert_detail.xml | 11 ++++++++ .../main/res/navigation/mobile_navigation.xml | 6 +++++ 5 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/core/notevault/ui/gallery/detail/ConcertDetailFragment.java create mode 100644 app/src/main/res/layout/fragment_concert_detail.xml diff --git a/app/src/main/java/core/notevault/ui/gallery/ConcertAdapter.java b/app/src/main/java/core/notevault/ui/gallery/ConcertAdapter.java index 38a2b37..6513eb2 100644 --- a/app/src/main/java/core/notevault/ui/gallery/ConcertAdapter.java +++ b/app/src/main/java/core/notevault/ui/gallery/ConcertAdapter.java @@ -19,26 +19,22 @@ import java.util.List; public class ConcertAdapter extends RecyclerView.Adapter { private final List concertList; - private final OnConcertDeleteListener deleteListener; - private final OnOpenConcertEditorListener editorListener; + private final OnConcertClickListener concertClickListener; - public interface OnConcertDeleteListener { + public interface OnConcertClickListener { void onDeleteConcert(Concert concert); - } - - public interface OnOpenConcertEditorListener { void onOpenConcertEditor(Concert concert); + void onConcertClick(Concert concert); } - public ConcertAdapter(List concertList, OnConcertDeleteListener deleteListener, OnOpenConcertEditorListener editorListener) { + + public ConcertAdapter(List concertList, OnConcertClickListener concertClickListener) { this.concertList = concertList; - this.deleteListener = deleteListener; - this.editorListener = editorListener; + this.concertClickListener = concertClickListener; } - public ConcertAdapter(OnConcertDeleteListener deleteListener, OnOpenConcertEditorListener editorListener) { - this.deleteListener = deleteListener; - this.editorListener = editorListener; + public ConcertAdapter(OnConcertClickListener onConcertClickListener) { + this.concertClickListener = onConcertClickListener; this.concertList = new ArrayList<>(); } @@ -47,9 +43,9 @@ public class ConcertAdapter extends RecyclerView.Adapter deleteListener.onDeleteConcert(concertList.get(position))); - holder.editButton.setOnClickListener(v -> editorListener.onOpenConcertEditor(concertList.get(position))); - + holder.deleteButton.setOnClickListener(v -> concertClickListener.onDeleteConcert(concertList.get(position))); + holder.editButton.setOnClickListener(v -> concertClickListener.onOpenConcertEditor(concertList.get(position))); + holder.itemView.setOnClickListener(v -> concertClickListener.onConcertClick(concertList.get(position))); } @Override diff --git a/app/src/main/java/core/notevault/ui/gallery/GalleryFragment.java b/app/src/main/java/core/notevault/ui/gallery/GalleryFragment.java index a6f2953..365250f 100644 --- a/app/src/main/java/core/notevault/ui/gallery/GalleryFragment.java +++ b/app/src/main/java/core/notevault/ui/gallery/GalleryFragment.java @@ -12,6 +12,9 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; +import androidx.navigation.NavController; +import androidx.navigation.NavDirections; +import androidx.navigation.Navigation; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -41,7 +44,29 @@ public class GalleryFragment extends Fragment { View root = binding.getRoot(); RecyclerView recyclerView = root.findViewById(R.id.concert_recycler_view); - concertAdapter = new ConcertAdapter(this::deleteConcert, this::editConcert); + concertAdapter = new ConcertAdapter(new ConcertAdapter.OnConcertClickListener() { + @Override + public void onDeleteConcert(Concert concert) { + deleteConcert(concert); + } + + @Override + public void onOpenConcertEditor(Concert concert) { + editConcert(concert); + } + + @Override + public void onConcertClick(Concert concert) { + Log.d("GalleryFragment", "Clicked on Concert: " + concert.getTitle()); + Bundle bundle = new Bundle(); + bundle.putInt("concertID", concert.getId()); + bundle.putString("concertTitle", concert.getTitle()); + bundle.putString("concertDate", concert.getConcertDate()); + + NavController navController = Navigation.findNavController(getActivity(), R.id.nav_host_fragment_content_main); + navController.navigate(R.id.concertDetailFragment, bundle); + } + }); recyclerView.setAdapter(concertAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); diff --git a/app/src/main/java/core/notevault/ui/gallery/detail/ConcertDetailFragment.java b/app/src/main/java/core/notevault/ui/gallery/detail/ConcertDetailFragment.java new file mode 100644 index 0000000..72dd339 --- /dev/null +++ b/app/src/main/java/core/notevault/ui/gallery/detail/ConcertDetailFragment.java @@ -0,0 +1,6 @@ +package core.notevault.ui.gallery.detail; + +import androidx.fragment.app.Fragment; + +public class ConcertDetailFragment extends Fragment { +} diff --git a/app/src/main/res/layout/fragment_concert_detail.xml b/app/src/main/res/layout/fragment_concert_detail.xml new file mode 100644 index 0000000..6dc1d74 --- /dev/null +++ b/app/src/main/res/layout/fragment_concert_detail.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index b2175c7..3d62d21 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -22,4 +22,10 @@ android:name="core.notevault.ui.slideshow.SlideshowFragment" android:label="@string/menu_slideshow" tools:layout="@layout/fragment_slideshow"/> + + \ No newline at end of file