From b6f43b1114582dd5133b10bd00a7126ff29c4cc5 Mon Sep 17 00:00:00 2001 From: Fawkes100 Date: Tue, 7 Jan 2025 07:21:21 +0100 Subject: [PATCH] (Local) Edit of Song --- .idea/dataSources.xml | 18 +++ .../java/core/notevault/MainActivity.java | 11 +- .../core/notevault/data/MusicNoteDAO.java | 3 +- .../gallery/detail/ConcertDetailFragment.java | 9 +- .../core/notevault/ui/home/HomeFragment.java | 11 +- .../notevault/ui/home/NoteSongAdapter.java | 23 +++- .../ui/metadatadialog/SongEditDialog.java | 85 ++++++++++++ .../res/layout/song_metadata_edit_dialog.xml | 126 ++++++++++++++++++ 8 files changed, 276 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/core/notevault/ui/metadatadialog/SongEditDialog.java create mode 100644 app/src/main/res/layout/song_metadata_edit_dialog.xml diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index e9b8f7c..3ca65a2 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -21,5 +21,23 @@ $ProjectFileDir$ + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$USER_HOME$/.cache/JetBrains/IntelliJIdea2024.1/device-explorer/Pixel Tablet API 30/_/data/data/core.notevault/databases/music_database + + + + $ProjectFileDir$ + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/xerial/sqlite-jdbc/3.45.1.0/sqlite-jdbc-3.45.1.0.jar + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar + + + \ No newline at end of file diff --git a/app/src/main/java/core/notevault/MainActivity.java b/app/src/main/java/core/notevault/MainActivity.java index 8f7076d..d15ea25 100644 --- a/app/src/main/java/core/notevault/MainActivity.java +++ b/app/src/main/java/core/notevault/MainActivity.java @@ -35,6 +35,7 @@ import core.notevault.ui.login.LoginCallBackImpl; import core.notevault.ui.login.LoginDialogFragment; import core.notevault.ui.login.RegisterCallback; import core.notevault.ui.metadatadialog.MetaDataDialog; +import core.notevault.ui.metadatadialog.SongEditDialog; import core.notevault.util.NoteSheetsUtil; import java.io.*; @@ -46,7 +47,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; public class MainActivity extends AppCompatActivity implements MetaDataDialog.OnMetadataListener, - ConcertEditorDialog.OnConcertEditorListener, ConcertSongSelector.OnSongSelectedListener, LoginCallback { + ConcertEditorDialog.OnConcertEditorListener, ConcertSongSelector.OnSongSelectedListener, LoginCallback, SongEditDialog.SongEditorListener { private AppBarConfiguration mAppBarConfiguration; private ActivityMainBinding binding; @@ -286,4 +287,12 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On Toast.makeText(this, error, Toast.LENGTH_LONG).show(); Log.d("LoginError", error); } + + @Override + public void onSongEdited(MusicNote updatedSong) { + new Thread(() -> { + musicDB.musicNoteDao().updateSong(updatedSong); + Log.d("MainActivity", "Updated Song: " + updatedSong.getTitle()); + }).start(); + } } \ No newline at end of file diff --git a/app/src/main/java/core/notevault/data/MusicNoteDAO.java b/app/src/main/java/core/notevault/data/MusicNoteDAO.java index 580af49..210cec8 100644 --- a/app/src/main/java/core/notevault/data/MusicNoteDAO.java +++ b/app/src/main/java/core/notevault/data/MusicNoteDAO.java @@ -66,5 +66,6 @@ public interface MusicNoteDAO { @Query("UPDATE music_notes SET syncStatus = :status, last_sync = :currentTime WHERE serverID IN (:serverIDs)") void storeSongSyncModifyResponses(List serverIDs, SyncStatus status, LocalDateTime currentTime); - + @Update + void updateSong(MusicNote musicNote); } 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 index 42b1895..e9ab23e 100644 --- a/app/src/main/java/core/notevault/ui/gallery/detail/ConcertDetailFragment.java +++ b/app/src/main/java/core/notevault/ui/gallery/detail/ConcertDetailFragment.java @@ -19,6 +19,7 @@ import core.notevault.data.MusicNote; import core.notevault.data.MusicNoteDAO; import core.notevault.databinding.FragmentConcertDetailBinding; import core.notevault.ui.home.NoteSongAdapter; +import core.notevault.ui.metadatadialog.SongEditDialog; import java.util.Collections; import java.util.List; @@ -48,7 +49,7 @@ public class ConcertDetailFragment extends Fragment { binding.textConcertDetailsDate.setText(concertDate); RecyclerView recyclerView = binding.noteRecyclerView; - noteSongAdapter = new NoteSongAdapter(this::deleteSongFromConcert); + noteSongAdapter = new NoteSongAdapter(this::deleteSongFromConcert, this::editSongFromConcert); recyclerView.setAdapter(noteSongAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); @@ -88,6 +89,12 @@ public class ConcertDetailFragment extends Fragment { }).start(); } + private void editSongFromConcert(MusicNote musicNote) { + SongEditDialog songEditDialog = new SongEditDialog(); + songEditDialog.setSong(musicNote); + songEditDialog.show(getParentFragmentManager(), SongEditDialog.TAG); + } + private class LoadConcertSongsTask extends AsyncTask> { private final int concertID; private final OnConcertSongsLoadedListener listener; diff --git a/app/src/main/java/core/notevault/ui/home/HomeFragment.java b/app/src/main/java/core/notevault/ui/home/HomeFragment.java index c65696c..f749deb 100644 --- a/app/src/main/java/core/notevault/ui/home/HomeFragment.java +++ b/app/src/main/java/core/notevault/ui/home/HomeFragment.java @@ -25,6 +25,7 @@ import core.notevault.data.MusicNote; import core.notevault.data.MusicNoteDAO; import core.notevault.databinding.FragmentHomeBinding; import core.notevault.ui.metadatadialog.MetaDataDialog; +import core.notevault.ui.metadatadialog.SongEditDialog; import core.notevault.util.NoteSheetsUtil; import java.util.List; @@ -49,7 +50,7 @@ public class HomeFragment extends Fragment { importBtn.setOnClickListener(v -> openFileChooser()); RecyclerView recyclerView = root.findViewById(R.id.note_recycler_view); - noteSongAdapter = new NoteSongAdapter(this::deleteSong); + noteSongAdapter = new NoteSongAdapter(this::deleteSong, this::editSong); recyclerView.setAdapter(noteSongAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); @@ -65,6 +66,14 @@ public class HomeFragment extends Fragment { return root; } + private void editSong(MusicNote musicNote) { + //Open Dialog + SongEditDialog songEditDialog = new SongEditDialog(); + songEditDialog.setSong(musicNote); + songEditDialog.show(getParentFragmentManager(), SongEditDialog.TAG); + + } + public void deleteSong(MusicNote musicNote) { new Thread(() -> { MusicDatabase musicDatabase = MusicDatabase.getDatabase(getContext()); diff --git a/app/src/main/java/core/notevault/ui/home/NoteSongAdapter.java b/app/src/main/java/core/notevault/ui/home/NoteSongAdapter.java index 5d98726..10f92c3 100644 --- a/app/src/main/java/core/notevault/ui/home/NoteSongAdapter.java +++ b/app/src/main/java/core/notevault/ui/home/NoteSongAdapter.java @@ -23,19 +23,25 @@ public class NoteSongAdapter extends RecyclerView.Adapter noteTitles; private final OnSongDeleteListener onSongDeleteListener; - + private final OnSongEditListener onSongEditListener; public interface OnSongDeleteListener { void onSongDeleted(MusicNote song); } - public NoteSongAdapter(List noteTitles, OnSongDeleteListener onSongDeleteListener) { - this.noteTitles = noteTitles; - this.onSongDeleteListener = onSongDeleteListener; + public interface OnSongEditListener { + void onSongEdit(MusicNote song); } - public NoteSongAdapter(OnSongDeleteListener onSongDeleteListener) { + public NoteSongAdapter(List noteTitles, OnSongDeleteListener onSongDeleteListener, OnSongEditListener onSongEditListener) { + this.noteTitles = noteTitles; + this.onSongDeleteListener = onSongDeleteListener; + this.onSongEditListener = onSongEditListener; + } + + public NoteSongAdapter(OnSongDeleteListener onSongDeleteListener, OnSongEditListener onSongEditListener) { this.onSongDeleteListener = onSongDeleteListener; this.noteTitles = new ArrayList<>(); + this.onSongEditListener = onSongEditListener; } @NonNull @@ -55,6 +61,10 @@ public class NoteSongAdapter extends RecyclerView.Adapter { onSongDeleteListener.onSongDeleted(noteTitles.get(position)); }); + + holder.editButton.setOnClickListener(v -> { + onSongEditListener.onSongEdit(noteTitles.get(position)); + }); } @Override @@ -74,6 +84,7 @@ public class NoteSongAdapter extends RecyclerView.Adapter { int position = getAdapterPosition(); if(position != RecyclerView.NO_POSITION) { diff --git a/app/src/main/java/core/notevault/ui/metadatadialog/SongEditDialog.java b/app/src/main/java/core/notevault/ui/metadatadialog/SongEditDialog.java new file mode 100644 index 0000000..1931c80 --- /dev/null +++ b/app/src/main/java/core/notevault/ui/metadatadialog/SongEditDialog.java @@ -0,0 +1,85 @@ +package core.notevault.ui.metadatadialog; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; +import core.notevault.R; +import core.notevault.data.MusicNote; + +public class SongEditDialog extends DialogFragment { + + private MusicNote song; + private SongEditorListener songEditorListener; + + public interface SongEditorListener { + void onSongEdited(MusicNote updatedSong); + } + + @NonNull + @Override + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + LayoutInflater inflater = requireActivity().getLayoutInflater(); + View dialogView = inflater.inflate(R.layout.song_metadata_edit_dialog, null); // Ersetze 'your_dialog_layout' durch deinen Dateinamen + + EditText title_input = dialogView.findViewById(R.id.title_input); + title_input.setText(song.getTitle()); + EditText composer_input = dialogView.findViewById(R.id.composer_input); + composer_input.setText(song.getComposer()); + EditText year_input = dialogView.findViewById(R.id.year_input); + year_input.setText(String.valueOf(song.getYear())); + EditText genre_input = dialogView.findViewById(R.id.genre_input); + genre_input.setText(song.getGenre()); + + return new AlertDialog.Builder(requireContext()) + .setView(dialogView) + .setPositiveButton("Speichern", (dialog, which) -> { + String title = title_input.getText().toString(); + String composer = composer_input.getText().toString(); + + String year_string = year_input.getText().toString(); + int year = 0; + if(!year_string.isEmpty()) { + year = Integer.parseInt(year_input.getText().toString()); + } + + String genre = genre_input.getText().toString(); + + song.setTitle(title); + song.setComposer(composer); + song.setGenre(genre); + song.setYear(year); + + songEditorListener.onSongEdited(song); + } ) + .setNegativeButton("Abbrechen", (dialog, which) -> {} ) + .create(); + } + + public MusicNote getSong() { + return song; + } + + public void setSong(MusicNote song) { + this.song = song; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + if (context instanceof MetaDataDialog.OnMetadataListener) { + songEditorListener = (SongEditorListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnMetadataListener"); + } + } + + public static String TAG = "SONGEDITDIALOG"; +} diff --git a/app/src/main/res/layout/song_metadata_edit_dialog.xml b/app/src/main/res/layout/song_metadata_edit_dialog.xml new file mode 100644 index 0000000..a8182ed --- /dev/null +++ b/app/src/main/res/layout/song_metadata_edit_dialog.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file