(Local) Edit of Song

This commit is contained in:
Fawkes100 2025-01-07 07:21:21 +01:00
parent b7c62f2328
commit b6f43b1114
8 changed files with 276 additions and 10 deletions

View File

@ -21,5 +21,23 @@
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="music_database [3]" uuid="3acbe0c9-6415-4726-8c75-c07350984fcc">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$USER_HOME$/.cache/JetBrains/IntelliJIdea2024.1/device-explorer/Pixel Tablet API 30/_/data/data/core.notevault/databases/music_database</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
<libraries>
<library>
<url>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</url>
</library>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar</url>
</library>
</libraries>
</data-source>
</component>
</project>

View File

@ -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();
}
}

View File

@ -66,5 +66,6 @@ public interface MusicNoteDAO {
@Query("UPDATE music_notes SET syncStatus = :status, last_sync = :currentTime WHERE serverID IN (:serverIDs)")
void storeSongSyncModifyResponses(List<String> serverIDs, SyncStatus status, LocalDateTime currentTime);
@Update
void updateSong(MusicNote musicNote);
}

View File

@ -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<Void, Void, List<MusicNote>> {
private final int concertID;
private final OnConcertSongsLoadedListener listener;

View File

@ -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());

View File

@ -23,19 +23,25 @@ public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteVi
private final List<MusicNote> noteTitles;
private final OnSongDeleteListener onSongDeleteListener;
private final OnSongEditListener onSongEditListener;
public interface OnSongDeleteListener {
void onSongDeleted(MusicNote song);
}
public NoteSongAdapter(List<MusicNote> noteTitles, OnSongDeleteListener onSongDeleteListener) {
this.noteTitles = noteTitles;
this.onSongDeleteListener = onSongDeleteListener;
public interface OnSongEditListener {
void onSongEdit(MusicNote song);
}
public NoteSongAdapter(OnSongDeleteListener onSongDeleteListener) {
public NoteSongAdapter(List<MusicNote> 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<NoteSongAdapter.NoteVi
holder.deleteButton.setOnClickListener(v -> {
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<NoteSongAdapter.NoteVi
TextView compositionTextView;
ImageButton deleteButton;
ImageButton editButton;
NoteViewHolder(View itemView) {
super(itemView);
@ -82,7 +93,7 @@ public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteVi
compositionTextView = itemView.findViewById(R.id.text_composition);
deleteButton = itemView.findViewById(R.id.delete_song_button);
editButton = itemView.findViewById(R.id.edit_song_button);
titleTextView.setOnClickListener(v -> {
int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION) {

View File

@ -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";
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:id="@+id/metadata_dialog">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Import-Einstellungen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/dialog_title"
android:textStyle="bold"
android:textSize="18sp"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Titel: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title_label"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text"
android:ems="10"
android:id="@+id/title_input"
android:hint="Titel eingeben"
android:foregroundTint="#000000"
android:minHeight="48dp"
android:padding="16dp"
android:minWidth="48dp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Komponisten: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/concert_date_label"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:id="@+id/composer_input"
android:hint="Komponisten eingeben"
android:layout_weight="1"
android:minWidth="48dp"
android:minHeight="48dp"
android:padding="16dp"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Jahr: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/year_label"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="numberSigned"
android:ems="10"
android:id="@+id/year_input"
android:hint="Erscheinungsjahr eingeben"
android:padding="16dp"
android:minWidth="48dp"
android:minHeight="48dp"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Genre: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/genre_label"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:id="@+id/genre_input"
android:hint="Genre eingeben"
android:minWidth="48dp"
android:minHeight="48dp"
android:padding="16dp"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>