From 395a374ac90c53759d82cc35abc2b9f5b9564080 Mon Sep 17 00:00:00 2001 From: sebastian Date: Fri, 1 Nov 2024 10:19:11 +0100 Subject: [PATCH] Add Concerts --- .../java/core/notevault/MainActivity.java | 15 +++- .../java/core/notevault/data/Concert.java | 52 +++++++++++ .../core/notevault/data/MusicDatabase.java | 2 +- .../core/notevault/data/MusicNoteDAO.java | 3 + .../notevault/ui/gallery/GalleryFragment.java | 13 ++- .../gallery/editor/ConcertEditorDialog.java | 85 ++++++++++++++++++ app/src/main/res/layout/concert_editor.xml | 81 +++++++++++++++++ app/src/main/res/layout/fragment_gallery.xml | 7 ++ .../res/layout/fragment_metadata_dialog.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- music_database-shm | Bin 32768 -> 0 bytes music_database-wal | 0 12 files changed, 256 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/core/notevault/data/Concert.java create mode 100644 app/src/main/java/core/notevault/ui/gallery/editor/ConcertEditorDialog.java create mode 100644 app/src/main/res/layout/concert_editor.xml delete mode 100644 music_database-shm delete mode 100644 music_database-wal diff --git a/app/src/main/java/core/notevault/MainActivity.java b/app/src/main/java/core/notevault/MainActivity.java index ebf6563..a3cfecc 100644 --- a/app/src/main/java/core/notevault/MainActivity.java +++ b/app/src/main/java/core/notevault/MainActivity.java @@ -14,17 +14,20 @@ import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.NavigationUI; import androidx.drawerlayout.widget.DrawerLayout; import androidx.appcompat.app.AppCompatActivity; +import core.notevault.data.Concert; import core.notevault.data.MusicDatabase; import core.notevault.data.MusicNote; import core.notevault.data.NoteSheet; import core.notevault.databinding.ActivityMainBinding; +import core.notevault.ui.gallery.editor.ConcertEditorDialog; import core.notevault.ui.metadatadialog.MetaDataDialog; import core.notevault.util.NoteSheetsUtil; import java.io.*; import java.nio.file.Files; +import java.util.Date; -public class MainActivity extends AppCompatActivity implements MetaDataDialog.OnMetadataListener { +public class MainActivity extends AppCompatActivity implements MetaDataDialog.OnMetadataListener, ConcertEditorDialog.OnConcertEditorListener { private AppBarConfiguration mAppBarConfiguration; private ActivityMainBinding binding; @@ -99,4 +102,14 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On return null; } } + + @Override + public void onConcertEditorClosed(String concertTitle, String concertDate) { + new Thread(() -> { + Concert concert = new Concert(concertTitle, concertDate); + Log.d("ConcertEditor", "Saved Concert: " + concertTitle + " on " + concertDate); + musicDB.musicNoteDao().insertConcert(concert); + + }).start(); + } } \ No newline at end of file diff --git a/app/src/main/java/core/notevault/data/Concert.java b/app/src/main/java/core/notevault/data/Concert.java new file mode 100644 index 0000000..b4fe639 --- /dev/null +++ b/app/src/main/java/core/notevault/data/Concert.java @@ -0,0 +1,52 @@ +package core.notevault.data; + +import androidx.room.Entity; +import androidx.room.Ignore; +import androidx.room.PrimaryKey; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +@Entity(tableName = "concerts") +public class Concert { + + @PrimaryKey(autoGenerate = true) + private int id; + + private String title; + private String concertDate; + + @Ignore + public Concert(String title, String concertDate) { + this.title = title; + this.concertDate = concertDate; + } + + public Concert() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getConcertDate() { + return concertDate; + } + + public void setConcertDate(String concertDate) { + this.concertDate = concertDate; + } +} diff --git a/app/src/main/java/core/notevault/data/MusicDatabase.java b/app/src/main/java/core/notevault/data/MusicDatabase.java index b064937..cba9f82 100644 --- a/app/src/main/java/core/notevault/data/MusicDatabase.java +++ b/app/src/main/java/core/notevault/data/MusicDatabase.java @@ -5,7 +5,7 @@ import androidx.room.Room; import androidx.room.RoomDatabase; import androidx.room.Database; -@Database(entities = {MusicNote.class, NoteSheet.class}, version = 1, exportSchema = false) +@Database(entities = {MusicNote.class, NoteSheet.class, Concert.class}, version = 2, exportSchema = false) public abstract class MusicDatabase extends RoomDatabase { public abstract MusicNoteDAO musicNoteDao(); diff --git a/app/src/main/java/core/notevault/data/MusicNoteDAO.java b/app/src/main/java/core/notevault/data/MusicNoteDAO.java index 21a9f9e..858fcf5 100644 --- a/app/src/main/java/core/notevault/data/MusicNoteDAO.java +++ b/app/src/main/java/core/notevault/data/MusicNoteDAO.java @@ -20,4 +20,7 @@ public interface MusicNoteDAO { @Query("SELECT * FROM note_sheets WHERE musicNoteId = :musicNoteId") List getNoteSheetsForMusicSong(long musicNoteId); + + @Insert + void insertConcert(Concert concert); } diff --git a/app/src/main/java/core/notevault/ui/gallery/GalleryFragment.java b/app/src/main/java/core/notevault/ui/gallery/GalleryFragment.java index 3adf3e4..32d9783 100644 --- a/app/src/main/java/core/notevault/ui/gallery/GalleryFragment.java +++ b/app/src/main/java/core/notevault/ui/gallery/GalleryFragment.java @@ -8,7 +8,10 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import core.notevault.R; import core.notevault.databinding.FragmentGalleryBinding; +import core.notevault.ui.gallery.editor.ConcertEditorDialog; public class GalleryFragment extends Fragment { @@ -22,11 +25,17 @@ public class GalleryFragment extends Fragment { binding = FragmentGalleryBinding.inflate(inflater, container, false); View root = binding.getRoot(); - final TextView textView = binding.textGallery; - galleryViewModel.getText().observe(getViewLifecycleOwner(), textView::setText); + + FloatingActionButton addConcertBtn = root.findViewById(R.id.add_concert_btn); + addConcertBtn.setOnClickListener(v -> onCreateNewConcert()); return root; } + public void onCreateNewConcert() { + ConcertEditorDialog concertEditorDialog = new ConcertEditorDialog(); + concertEditorDialog.show(getParentFragmentManager(), ConcertEditorDialog.TAG); + } + @Override public void onDestroyView() { super.onDestroyView(); diff --git a/app/src/main/java/core/notevault/ui/gallery/editor/ConcertEditorDialog.java b/app/src/main/java/core/notevault/ui/gallery/editor/ConcertEditorDialog.java new file mode 100644 index 0000000..0cce15f --- /dev/null +++ b/app/src/main/java/core/notevault/ui/gallery/editor/ConcertEditorDialog.java @@ -0,0 +1,85 @@ +package core.notevault.ui.gallery.editor; + +import android.app.AlertDialog; +import android.app.DatePickerDialog; +import android.app.Dialog; +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; +import androidx.annotation.NonNull; +import androidx.fragment.app.DialogFragment; +import core.notevault.R; +import core.notevault.ui.metadatadialog.MetaDataDialog; + +import java.util.Calendar; +import java.util.Date; + +public class ConcertEditorDialog extends DialogFragment { + + private EditText concert_input; + + private OnConcertEditorListener listener; + + public interface OnConcertEditorListener { + void onConcertEditorClosed(String concertTitle, String concertDate); + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + LayoutInflater inflater = requireActivity().getLayoutInflater(); + View dialogView = inflater.inflate(R.layout.concert_editor, null); + + EditText title_input = dialogView.findViewById(R.id.concert_title_input); + concert_input = dialogView.findViewById(R.id.concert_date_input); + + concert_input.setOnClickListener(v -> showDatePickerDialog()); + + return new AlertDialog.Builder(requireContext()) + .setView(dialogView) + .setPositiveButton("Speichern", (dialog, which) -> { + String title = title_input.getText().toString(); + String concertDate = concert_input.getText().toString(); + Log.d("ConcertEditor", "ConcertDate: " + concertDate); + + listener.onConcertEditorClosed(title, concertDate); + }) + .setNegativeButton("Abbrechen", (dialog, which) -> {} ) + .create(); + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + if (context instanceof OnConcertEditorListener) { + listener = (OnConcertEditorListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnMetadataListener"); + } + } + + private void showDatePickerDialog() { + // Erhalte das aktuelle Datum + final Calendar calendar = Calendar.getInstance(); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH); + int day = calendar.get(Calendar.DAY_OF_MONTH); + + // Erstelle den DatePickerDialog + DatePickerDialog datePickerDialog = new DatePickerDialog(this.getContext(), + (view, selectedYear, selectedMonth, selectedDay) -> { + // Setze das ausgewählte Datum in das EditText + concert_input.setText(selectedDay + "/" + (selectedMonth + 1) + "/" + selectedYear); + }, year, month, day); + + // Zeige den Dialog an + datePickerDialog.show(); + } + + + public static String TAG = "ConcertEditorDialog"; +} diff --git a/app/src/main/res/layout/concert_editor.xml b/app/src/main/res/layout/concert_editor.xml new file mode 100644 index 0000000..f9d07fb --- /dev/null +++ b/app/src/main/res/layout/concert_editor.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_gallery.xml b/app/src/main/res/layout/fragment_gallery.xml index 82d5b10..895f4e0 100644 --- a/app/src/main/res/layout/fragment_gallery.xml +++ b/app/src/main/res/layout/fragment_gallery.xml @@ -20,4 +20,11 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent"/> + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_metadata_dialog.xml b/app/src/main/res/layout/fragment_metadata_dialog.xml index e006006..a8182ed 100644 --- a/app/src/main/res/layout/fragment_metadata_dialog.xml +++ b/app/src/main/res/layout/fragment_metadata_dialog.xml @@ -57,7 +57,7 @@ android:text="Komponisten: " android:layout_width="wrap_content" android:layout_height="wrap_content" - android:id="@+id/composer_label"/> + android:id="@+id/concert_date_label"/> Settings Home - Gallery + Concerts Slideshow \ No newline at end of file diff --git a/music_database-shm b/music_database-shm deleted file mode 100644 index fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeIuAr62r3