Delete Concerts
This commit is contained in:
parent
d21a7499fe
commit
e39b164b10
@ -6,7 +6,20 @@
|
|||||||
<State />
|
<State />
|
||||||
</entry>
|
</entry>
|
||||||
<entry key="app">
|
<entry key="app">
|
||||||
<State />
|
<State>
|
||||||
|
<runningDeviceTargetSelectedWithDropDown>
|
||||||
|
<Target>
|
||||||
|
<type value="RUNNING_DEVICE_TARGET" />
|
||||||
|
<deviceKey>
|
||||||
|
<Key>
|
||||||
|
<type value="SERIAL_NUMBER" />
|
||||||
|
<value value="adb-R52N50NLGRT-9CB8rW._adb-tls-connect._tcp" />
|
||||||
|
</Key>
|
||||||
|
</deviceKey>
|
||||||
|
</Target>
|
||||||
|
</runningDeviceTargetSelectedWithDropDown>
|
||||||
|
<timeTargetWasSelectedWithDropDown value="2024-11-01T14:55:24.387595315Z" />
|
||||||
|
</State>
|
||||||
</entry>
|
</entry>
|
||||||
</value>
|
</value>
|
||||||
</component>
|
</component>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package core.notevault.data;
|
package core.notevault.data;
|
||||||
|
|
||||||
import androidx.room.Dao;
|
import androidx.room.Dao;
|
||||||
|
import androidx.room.Delete;
|
||||||
import androidx.room.Insert;
|
import androidx.room.Insert;
|
||||||
import androidx.room.Query;
|
import androidx.room.Query;
|
||||||
|
|
||||||
@ -26,4 +27,7 @@ public interface MusicNoteDAO {
|
|||||||
|
|
||||||
@Query("SELECT * FROM concerts")
|
@Query("SELECT * FROM concerts")
|
||||||
List<Concert> getAllConcerts();
|
List<Concert> getAllConcerts();
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
void deleteConcert(Concert concert);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import android.util.Log;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
@ -18,12 +19,19 @@ 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;
|
||||||
|
|
||||||
public ConcertAdapter(List<Concert> concertList) {
|
public interface OnConcertDeleteListener {
|
||||||
this.concertList = concertList;
|
void onDeleteConcert(Concert concert);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcertAdapter() {
|
public ConcertAdapter(List<Concert> concertList, OnConcertDeleteListener deleteListener) {
|
||||||
|
this.concertList = concertList;
|
||||||
|
this.deleteListener = deleteListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConcertAdapter(OnConcertDeleteListener deleteListener) {
|
||||||
|
this.deleteListener = deleteListener;
|
||||||
this.concertList = new ArrayList<>();
|
this.concertList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +39,11 @@ public class ConcertAdapter extends RecyclerView.Adapter<ConcertAdapter.ConcertV
|
|||||||
public void onBindViewHolder(@NonNull ConcertViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ConcertViewHolder holder, int position) {
|
||||||
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 ->{
|
||||||
|
Log.d("ConcertAdapter", "Delete button clicked for: " + concertList.get(position).getTitle());
|
||||||
|
deleteListener.onDeleteConcert(concertList.get(position));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -57,12 +70,13 @@ public class ConcertAdapter extends RecyclerView.Adapter<ConcertAdapter.ConcertV
|
|||||||
TextView concertTitleView;
|
TextView concertTitleView;
|
||||||
TextView dateHolder;
|
TextView dateHolder;
|
||||||
|
|
||||||
|
ImageButton deleteButton;
|
||||||
|
|
||||||
public ConcertViewHolder(@NonNull @NotNull View itemView) {
|
public ConcertViewHolder(@NonNull @NotNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
concertTitleView = itemView.findViewById(R.id.concert_title);
|
concertTitleView = itemView.findViewById(R.id.concert_title);
|
||||||
dateHolder = itemView.findViewById(R.id.concert_date);
|
dateHolder = itemView.findViewById(R.id.concert_date);
|
||||||
|
deleteButton = itemView.findViewById(R.id.delete_concert_button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package core.notevault.ui.gallery;
|
|||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -39,7 +41,7 @@ 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();
|
concertAdapter = new ConcertAdapter(this::deleteConcert);
|
||||||
recyclerView.setAdapter(concertAdapter);
|
recyclerView.setAdapter(concertAdapter);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
|
||||||
@ -58,6 +60,20 @@ public class GalleryFragment extends Fragment {
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteConcert(Concert concert) {
|
||||||
|
Log.d("GalleryFragment", "Delete Concert");
|
||||||
|
new Thread(() -> {
|
||||||
|
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() {
|
public void updateConcerts() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,12 @@ public class GalleryViewModel extends ViewModel {
|
|||||||
concerts.setValue(currentConcerts);
|
concerts.setValue(currentConcerts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteConcert(Concert concert) {
|
||||||
|
List<Concert> currentConcerts = concerts.getValue();
|
||||||
|
if(currentConcerts != null) {
|
||||||
|
currentConcerts.remove(concert);
|
||||||
|
concerts.setValue(currentConcerts);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -49,7 +49,7 @@
|
|||||||
android:background="?android:selectableItemBackgroundBorderless" />
|
android:background="?android:selectableItemBackgroundBorderless" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/delete_button"
|
android:id="@+id/delete_concert_button"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:src="@drawable/delete"
|
android:src="@drawable/delete"
|
||||||
|
Loading…
Reference in New Issue
Block a user