Switch to new Fragment "Concert Details"

This commit is contained in:
sebastian 2024-11-01 18:49:07 +01:00
parent 22ad507745
commit 252320d07b
5 changed files with 60 additions and 16 deletions

View File

@ -19,26 +19,22 @@ import java.util.List;
public class ConcertAdapter extends RecyclerView.Adapter<ConcertAdapter.ConcertViewHolder> { public class ConcertAdapter extends RecyclerView.Adapter<ConcertAdapter.ConcertViewHolder> {
private final List<Concert> concertList; private final List<Concert> concertList;
private final OnConcertDeleteListener deleteListener; private final OnConcertClickListener concertClickListener;
private final OnOpenConcertEditorListener editorListener;
public interface OnConcertDeleteListener { public interface OnConcertClickListener {
void onDeleteConcert(Concert concert); void onDeleteConcert(Concert concert);
}
public interface OnOpenConcertEditorListener {
void onOpenConcertEditor(Concert concert); void onOpenConcertEditor(Concert concert);
void onConcertClick(Concert concert);
} }
public ConcertAdapter(List<Concert> concertList, OnConcertDeleteListener deleteListener, OnOpenConcertEditorListener editorListener) {
public ConcertAdapter(List<Concert> concertList, OnConcertClickListener concertClickListener) {
this.concertList = concertList; this.concertList = concertList;
this.deleteListener = deleteListener; this.concertClickListener = concertClickListener;
this.editorListener = editorListener;
} }
public ConcertAdapter(OnConcertDeleteListener deleteListener, OnOpenConcertEditorListener editorListener) { public ConcertAdapter(OnConcertClickListener onConcertClickListener) {
this.deleteListener = deleteListener; this.concertClickListener = onConcertClickListener;
this.editorListener = editorListener;
this.concertList = new ArrayList<>(); this.concertList = new ArrayList<>();
} }
@ -47,9 +43,9 @@ public class ConcertAdapter extends RecyclerView.Adapter<ConcertAdapter.ConcertV
holder.concertTitleView.setText(concertList.get(position).getTitle()); holder.concertTitleView.setText(concertList.get(position).getTitle());
holder.dateHolder.setText(concertList.get(position).getConcertDate()); holder.dateHolder.setText(concertList.get(position).getConcertDate());
holder.deleteButton.setOnClickListener(v -> deleteListener.onDeleteConcert(concertList.get(position))); holder.deleteButton.setOnClickListener(v -> concertClickListener.onDeleteConcert(concertList.get(position)));
holder.editButton.setOnClickListener(v -> editorListener.onOpenConcertEditor(concertList.get(position))); holder.editButton.setOnClickListener(v -> concertClickListener.onOpenConcertEditor(concertList.get(position)));
holder.itemView.setOnClickListener(v -> concertClickListener.onConcertClick(concertList.get(position)));
} }
@Override @Override

View File

@ -12,6 +12,9 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; 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.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -41,7 +44,29 @@ public class GalleryFragment extends Fragment {
View root = binding.getRoot(); View root = binding.getRoot();
RecyclerView recyclerView = root.findViewById(R.id.concert_recycler_view); 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.setAdapter(concertAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

View File

@ -0,0 +1,6 @@
package core.notevault.ui.gallery.detail;
import androidx.fragment.app.Fragment;
public class ConcertDetailFragment extends Fragment {
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/textView2" tools:layout_editor_absoluteY="313dp"
tools:layout_editor_absoluteX="372dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -22,4 +22,10 @@
android:name="core.notevault.ui.slideshow.SlideshowFragment" android:name="core.notevault.ui.slideshow.SlideshowFragment"
android:label="@string/menu_slideshow" android:label="@string/menu_slideshow"
tools:layout="@layout/fragment_slideshow"/> tools:layout="@layout/fragment_slideshow"/>
<!-- Concert Detail Fragment -->
<fragment
android:id="@+id/concertDetailFragment"
android:name="core.notevault.ui.gallery.detail.ConcertDetailFragment"
android:label="Concert Details"
tools:layout="@layout/fragment_concert_detail"/>
</navigation> </navigation>