diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index 612ad88..341e9f7 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -6,7 +6,20 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/java/core/notevault/data/MusicNoteDAO.java b/app/src/main/java/core/notevault/data/MusicNoteDAO.java
index dc2d102..714eb5e 100644
--- a/app/src/main/java/core/notevault/data/MusicNoteDAO.java
+++ b/app/src/main/java/core/notevault/data/MusicNoteDAO.java
@@ -1,6 +1,7 @@
package core.notevault.data;
import androidx.room.Dao;
+import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
@@ -26,4 +27,7 @@ public interface MusicNoteDAO {
@Query("SELECT * FROM concerts")
List getAllConcerts();
+
+ @Delete
+ void deleteConcert(Concert concert);
}
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 524f7d6..7aac6a2 100644
--- a/app/src/main/java/core/notevault/ui/gallery/ConcertAdapter.java
+++ b/app/src/main/java/core/notevault/ui/gallery/ConcertAdapter.java
@@ -4,6 +4,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
@@ -18,12 +19,19 @@ import java.util.List;
public class ConcertAdapter extends RecyclerView.Adapter {
private final List concertList;
+ private final OnConcertDeleteListener deleteListener;
- public ConcertAdapter(List concertList) {
- this.concertList = concertList;
+ public interface OnConcertDeleteListener {
+ void onDeleteConcert(Concert concert);
}
- public ConcertAdapter() {
+ public ConcertAdapter(List concertList, OnConcertDeleteListener deleteListener) {
+ this.concertList = concertList;
+ this.deleteListener = deleteListener;
+ }
+
+ public ConcertAdapter(OnConcertDeleteListener deleteListener) {
+ this.deleteListener = deleteListener;
this.concertList = new ArrayList<>();
}
@@ -31,6 +39,11 @@ public class ConcertAdapter extends RecyclerView.Adapter{
+ Log.d("ConcertAdapter", "Delete button clicked for: " + concertList.get(position).getTitle());
+ deleteListener.onDeleteConcert(concertList.get(position));
+ });
}
@Override
@@ -57,12 +70,13 @@ public class ConcertAdapter extends RecyclerView.Adapter {
+ MusicDatabase musicDatabase = MusicDatabase.getDatabase(this.getContext());
+ MusicNoteDAO musicNoteDAO = musicDatabase.musicNoteDao();
+ musicNoteDAO.deleteConcert(concert);
+
+ new Handler(Looper.getMainLooper()).post(() -> {
+ galleryViewModel.deleteConcert(concert);
+ Log.d("GalleryFragment", "Concert deleted successfully and ViewModel updated");
+ });
+ }).start();
+ }
+
public void updateConcerts() {
}
diff --git a/app/src/main/java/core/notevault/ui/gallery/GalleryViewModel.java b/app/src/main/java/core/notevault/ui/gallery/GalleryViewModel.java
index 33b3268..4fe9641 100644
--- a/app/src/main/java/core/notevault/ui/gallery/GalleryViewModel.java
+++ b/app/src/main/java/core/notevault/ui/gallery/GalleryViewModel.java
@@ -33,4 +33,12 @@ public class GalleryViewModel extends ViewModel {
concerts.setValue(currentConcerts);
}
}
+
+ public void deleteConcert(Concert concert) {
+ List currentConcerts = concerts.getValue();
+ if(currentConcerts != null) {
+ currentConcerts.remove(concert);
+ concerts.setValue(currentConcerts);
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/concert_item.xml b/app/src/main/res/layout/concert_item.xml
index 38e2ec2..d1a8e0c 100644
--- a/app/src/main/res/layout/concert_item.xml
+++ b/app/src/main/res/layout/concert_item.xml
@@ -49,7 +49,7 @@
android:background="?android:selectableItemBackgroundBorderless" />