Add Concerts

This commit is contained in:
sebastian 2024-11-01 10:19:11 +01:00
parent f632a08256
commit 395a374ac9
12 changed files with 256 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -20,4 +20,7 @@ public interface MusicNoteDAO {
@Query("SELECT * FROM note_sheets WHERE musicNoteId = :musicNoteId")
List<NoteSheet> getNoteSheetsForMusicSong(long musicNoteId);
@Insert
void insertConcert(Concert concert);
}

View File

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

View File

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

View File

@ -0,0 +1,81 @@
<?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/concert_editor_dialog">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Konzerteinstellungen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/concert_settings"
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_concert_label"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text"
android:ems="10"
android:id="@+id/concert_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="Datum"
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:layout_weight="1"
android:inputType="date"
android:ems="10"
android:id="@+id/concert_date_input"
android:hint="Datum eingeben"
android:foregroundTint="#000000"
android:minHeight="48dp"
android:padding="16dp"
android:minWidth="48dp"
android:focusable="false"
android:clickable="true"/>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>

View File

@ -20,4 +20,11 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:src="@drawable/add_24dp_e8eaed_fill0_wght400_grad0_opsz24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true" android:id="@+id/add_concert_btn"
android:layout_marginEnd="16dp" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="16dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -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"/>
<EditText
android:layout_width="0dp"

View File

@ -8,6 +8,6 @@
<string name="action_settings">Settings</string>
<string name="menu_home">Home</string>
<string name="menu_gallery">Gallery</string>
<string name="menu_gallery">Concerts</string>
<string name="menu_slideshow">Slideshow</string>
</resources>

Binary file not shown.

View File