Select songs for Concert

This commit is contained in:
sebastian 2024-11-02 09:37:07 +01:00
parent 2ca805134c
commit 747fcdc429
16 changed files with 414 additions and 58 deletions

View File

@ -6,20 +6,7 @@
<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>

View File

@ -9,7 +9,7 @@ android {
defaultConfig { defaultConfig {
applicationId = "core.notevault" applicationId = "core.notevault"
minSdk = 26 minSdk = 28
targetSdk = 34 targetSdk = 34
versionCode = 1 versionCode = 1
versionName = "1.0" versionName = "1.0"
@ -44,6 +44,7 @@ dependencies {
implementation(libs.room.common) implementation(libs.room.common)
implementation("androidx.recyclerview:recyclerview:1.3.2") implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("com.github.chrisbanes:PhotoView:2.3.0") implementation("com.github.chrisbanes:PhotoView:2.3.0")
implementation(libs.car.ui.lib)
testImplementation(libs.junit) testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit) androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core) androidTestImplementation(libs.espresso.core)

View File

@ -17,12 +17,10 @@ import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI; import androidx.navigation.ui.NavigationUI;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import core.notevault.data.Concert; import core.notevault.data.*;
import core.notevault.data.MusicDatabase;
import core.notevault.data.MusicNote;
import core.notevault.data.NoteSheet;
import core.notevault.databinding.ActivityMainBinding; import core.notevault.databinding.ActivityMainBinding;
import core.notevault.ui.gallery.GalleryFragment; import core.notevault.ui.gallery.GalleryFragment;
import core.notevault.ui.gallery.detail.ConcertSongSelector;
import core.notevault.ui.gallery.editor.ConcertEditorDialog; import core.notevault.ui.gallery.editor.ConcertEditorDialog;
import core.notevault.ui.home.HomeFragment; import core.notevault.ui.home.HomeFragment;
import core.notevault.ui.metadatadialog.MetaDataDialog; import core.notevault.ui.metadatadialog.MetaDataDialog;
@ -30,9 +28,12 @@ import core.notevault.util.NoteSheetsUtil;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
public class MainActivity extends AppCompatActivity implements MetaDataDialog.OnMetadataListener, ConcertEditorDialog.OnConcertEditorListener { public class MainActivity extends AppCompatActivity implements MetaDataDialog.OnMetadataListener,
ConcertEditorDialog.OnConcertEditorListener, ConcertSongSelector.OnSongSelectedListener {
private AppBarConfiguration mAppBarConfiguration; private AppBarConfiguration mAppBarConfiguration;
private ActivityMainBinding binding; private ActivityMainBinding binding;
@ -164,4 +165,13 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On
}).start(); }).start();
} }
@Override
public void onSongsSelected(List<MusicNote> songs, int concertID) {
new Thread(() -> {
for(MusicNote musicNote : songs) {
ConcertSong concertSong = new ConcertSong(musicNote.getMusicNoteId(), concertID);
}
}).start();
}
} }

View File

@ -0,0 +1,55 @@
package core.notevault.data;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;
@Entity(tableName = "concert_songs")
public class ConcertSong {
@PrimaryKey(autoGenerate = true)
private int id;
private long musicNoteID;
private int concertID;
@Ignore
public ConcertSong(long musicNoteID, int concertID) {
this.musicNoteID = musicNoteID;
this.concertID = concertID;
}
@Ignore
public ConcertSong(int id, long musicNoteID, int concertID) {
this.id = id;
this.musicNoteID = musicNoteID;
this.concertID = concertID;
}
public ConcertSong() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public long getMusicNoteID() {
return musicNoteID;
}
public void setMusicNoteID(long musicNoteID) {
this.musicNoteID = musicNoteID;
}
public int getConcertID() {
return concertID;
}
public void setConcertID(int concertID) {
this.concertID = concertID;
}
}

View File

@ -5,7 +5,7 @@ import androidx.room.Room;
import androidx.room.RoomDatabase; import androidx.room.RoomDatabase;
import androidx.room.Database; import androidx.room.Database;
@Database(entities = {MusicNote.class, NoteSheet.class, Concert.class}, version = 2, exportSchema = false) @Database(entities = {MusicNote.class, NoteSheet.class, Concert.class, ConcertSong.class}, version = 2, exportSchema = false)
public abstract class MusicDatabase extends RoomDatabase { public abstract class MusicDatabase extends RoomDatabase {
public abstract MusicNoteDAO musicNoteDao(); public abstract MusicNoteDAO musicNoteDao();

View File

@ -22,6 +22,14 @@ public class MusicNote {
this.genre = genre; this.genre = genre;
} }
public MusicNote(long musicNoteId, String title) {
this.musicNoteId = musicNoteId;
this.title = title;
}
@Ignore
public MusicNote() { public MusicNote() {
} }

View File

@ -33,4 +33,15 @@ public interface MusicNoteDAO {
@Delete @Delete
void deleteSong(MusicNote musicNote); void deleteSong(MusicNote musicNote);
@Insert
void insertConcertSong(ConcertSong concertSong);
@Query("SELECT m.* FROM music_notes m JOIN concert_songs cs ON m.musicNoteId = cs.musicNoteID WHERE cs.id = :concertID")
List<MusicNote> getAllMusicNotesOfConcert(long concertID);
@Delete
void deleteConcertSong(ConcertSong concertSong);
} }

View File

@ -5,6 +5,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import core.notevault.data.Concert; import core.notevault.data.Concert;
import core.notevault.databinding.FragmentConcertDetailBinding; import core.notevault.databinding.FragmentConcertDetailBinding;
@ -24,6 +25,22 @@ public class ConcertDetailFragment extends Fragment {
binding.textConcertDetailsTitle.setText(concertTitle); binding.textConcertDetailsTitle.setText(concertTitle);
binding.textConcertDetailsDate.setText(concertDate); binding.textConcertDetailsDate.setText(concertDate);
FloatingActionButton fab = binding.addSongConcert;
fab.setOnClickListener(view -> {
ConcertSongSelector concertSongSelector = new ConcertSongSelector();
Bundle bundle = new Bundle();
bundle.putString("concertTitle", concertTitle);
bundle.putString("concertDate", concertDate);
bundle.putInt("concertID", concertId);
concertSongSelector.setArguments(bundle);
concertSongSelector.show(getParentFragmentManager(), ConcertSongSelector.TAG);
});
return binding.getRoot(); return binding.getRoot();
} }
} }

View File

@ -0,0 +1,116 @@
package core.notevault.ui.gallery.detail;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.SearchView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import core.notevault.R;
import core.notevault.data.ConcertSong;
import core.notevault.data.MusicDatabase;
import core.notevault.data.MusicNote;
import core.notevault.data.MusicNoteDAO;
import core.notevault.ui.metadatadialog.MetaDataDialog;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ConcertSongSelector extends DialogFragment {
private ConcertSongSelectorAdapter adapter;
private OnSongSelectedListener listener;
private int concertID;
public interface OnSongSelectedListener {
void onSongsSelected(List<MusicNote> songs, int concertID);
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.dialog_concert_song_selector, null);
String concertTitle = getArguments().getString("concertTitle");
String concertDate = getArguments().getString("concertDate");
concertID = getArguments().getInt("concertID");
TextView dialogTitle = dialogView.findViewById(R.id.dialog_title_concert_song_selector);
dialogTitle.setText("Wähle Stücke für das Konzert '" + concertTitle + "' am " + concertDate + " aus");
RecyclerView recyclerView = dialogView.findViewById(R.id.concert_song_selector_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new ConcertSongSelectorAdapter(new ArrayList<>());
recyclerView.setAdapter(adapter);
SearchView searchView = dialogView.findViewById(R.id.search_view);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
adapter.filter(s);
return true;
}
});
fetchAllSongs();
return new AlertDialog.Builder(requireContext())
.setView(dialogView)
.setPositiveButton("Speichern", (dialog, which) -> {
List<MusicNote> selectedSongs = adapter.getSelectedSongs();
listener.onSongsSelected(selectedSongs, concertID);
})
.setNegativeButton("Abbrechen", (dialog, which) -> {} )
.create();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
if (context instanceof ConcertSongSelector.OnSongSelectedListener) {
listener = (ConcertSongSelector.OnSongSelectedListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnMetadataListener");
}
}
private void fetchAllSongs() {
// Ersetze dies durch das Laden der Songs aus der Datenbank oder einer anderen Quelle
new LoadSongTitlesTask().execute();
}
private class LoadSongTitlesTask extends AsyncTask<Void, Void, List<MusicNote>> {
@Override
protected List<MusicNote> doInBackground(Void... voids) {
MusicDatabase db = MusicDatabase.getDatabase(getContext());
MusicNoteDAO musicNoteDAO = db.musicNoteDao();
return musicNoteDAO.getAllNotes();
}
@Override
protected void onPostExecute(List<MusicNote> songs) {
adapter.setSongs(songs);
}
}
public static String TAG = "ConcertSongSelector";
}

View File

@ -0,0 +1,85 @@
package core.notevault.ui.gallery.detail;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import core.notevault.R;
import core.notevault.data.MusicNote;
import java.util.ArrayList;
import java.util.List;
public class ConcertSongSelectorAdapter extends RecyclerView.Adapter<ConcertSongSelectorAdapter.ConcertSongSelectorViewHolder> {
private List<MusicNote> songs;
private List<MusicNote> selectedSongs = new ArrayList<>();
private List<MusicNote> filteredSongs;
public ConcertSongSelectorAdapter(List<MusicNote> songs) {
this.songs = songs;
this.filteredSongs = new ArrayList<>(songs);
}
@NonNull
@Override
public ConcertSongSelectorViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_concert_song, parent, false);
return new ConcertSongSelectorViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ConcertSongSelectorViewHolder holder, int position) {
MusicNote song = filteredSongs.get(position);
holder.bind(song);
}
@Override
public int getItemCount() {
return filteredSongs.size();
}
public List<MusicNote> getSelectedSongs() {
return selectedSongs;
}
public void setSongs(List<MusicNote> musicNotes) {
songs = musicNotes;
filteredSongs = new ArrayList<>(musicNotes);
notifyDataSetChanged();
}
public void filter(String query) {
filteredSongs.clear();
if (query.isEmpty()) {
filteredSongs.addAll(songs);
} else {
for (MusicNote song : songs) {
if (song.getTitle().toLowerCase().contains(query.toLowerCase())) {
filteredSongs.add(song);
}
}
}
notifyDataSetChanged();
}
class ConcertSongSelectorViewHolder extends RecyclerView.ViewHolder {
private final TextView songTitle;
private final CheckBox songCheckbox;
ConcertSongSelectorViewHolder(View itemView) {
super(itemView);
songTitle = itemView.findViewById(R.id.song_title);
songCheckbox = itemView.findViewById(R.id.song_checkbox);
}
void bind(MusicNote song) {
songTitle.setText(song.getTitle());
songCheckbox.setChecked(selectedSongs.contains(song));
}
}
}

View File

@ -6,12 +6,10 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.provider.OpenableColumns;
import android.util.Log; 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.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -29,7 +27,6 @@ import core.notevault.databinding.FragmentHomeBinding;
import core.notevault.ui.metadatadialog.MetaDataDialog; import core.notevault.ui.metadatadialog.MetaDataDialog;
import core.notevault.util.NoteSheetsUtil; import core.notevault.util.NoteSheetsUtil;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class HomeFragment extends Fragment { public class HomeFragment extends Fragment {
@ -48,7 +45,7 @@ public class HomeFragment extends Fragment {
binding = FragmentHomeBinding.inflate(inflater, container, false); binding = FragmentHomeBinding.inflate(inflater, container, false);
View root = binding.getRoot(); View root = binding.getRoot();
FloatingActionButton importBtn = root.findViewById(R.id.importMusicNotesBtn); FloatingActionButton importBtn = root.findViewById(R.id.add_song_concert);
importBtn.setOnClickListener(v -> openFileChooser()); importBtn.setOnClickListener(v -> openFileChooser());
RecyclerView recyclerView = root.findViewById(R.id.note_recycler_view); RecyclerView recyclerView = root.findViewById(R.id.note_recycler_view);

View File

@ -0,0 +1,29 @@
<?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_song_selector_dialgog">
<TextView
android:text="Wähle Songs für das Konzert 'Jubiläum' am 19.10.2024 aus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/dialog_title_concert_song_selector"
android:textStyle="bold"
android:textSize="18sp"/>
<SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:queryHint="Suche Stücke..." />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/concert_song_selector_recycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

View File

@ -1,43 +1,62 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android">
android:orientation="vertical"
android:padding="16dp">
<androidx.cardview.widget.CardView <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_marginBottom="16dp" android:orientation="vertical" android:layout_above="@+id/add_song_concert"
app:cardCornerRadius="8dp" android:padding="16dp" android:id="@+id/linearLayout">
app:cardElevation="4dp">
<LinearLayout
<androidx.cardview.widget.CardView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_marginBottom="16dp"
android:padding="16dp"> app:cardCornerRadius="8dp"
app:cardElevation="4dp">
<TextView <LinearLayout
android:id="@+id/text_concert_details_title" android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:orientation="horizontal"
android:text="Konzerttitel" android:padding="16dp">
android:textSize="18sp"
android:textStyle="bold"/>
<TextView <TextView
android:id="@+id/text_concert_details_date" android:id="@+id/text_concert_details_title"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="01.01.2024" android:layout_weight="1"
android:textSize="16sp"/> android:text="Konzerttitel"
android:textSize="18sp"
android:textStyle="bold"/>
</LinearLayout> <TextView
</androidx.cardview.widget.CardView> android:id="@+id/text_concert_details_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="01.01.2024"
android:textSize="16sp"/>
<!-- Hier können weitere Details hinzugefügt werden --> </LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout> <!-- Hier können weitere Details hinzugefügt werden -->
</LinearLayout>
<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_song_concert"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"
app:backgroundTint="@color/teal_200"
android:contentDescription="Add Concert Song"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -11,14 +11,14 @@
android:id="@+id/note_recycler_view" android:id="@+id/note_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_above="@+id/importMusicNotesBtn"/> android:layout_above="@+id/add_song_concert"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton <com.google.android.material.floatingactionbutton.FloatingActionButton
android:src="@drawable/add_24dp_e8eaed_fill0_wght400_grad0_opsz24" android:src="@drawable/add_24dp_e8eaed_fill0_wght400_grad0_opsz24"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clickable="true" android:clickable="true"
android:id="@+id/importMusicNotesBtn" android:id="@+id/add_song_concert"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"

View File

@ -0,0 +1,19 @@
<?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="horizontal"
android:padding="8dp">
<TextView
android:id="@+id/song_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Song Title" />
<CheckBox
android:id="@+id/song_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -11,6 +11,7 @@ lifecycleViewmodelKtx = "2.6.1"
navigationFragment = "2.6.0" navigationFragment = "2.6.0"
navigationUi = "2.6.0" navigationUi = "2.6.0"
roomCommon = "2.6.1" roomCommon = "2.6.1"
carUiLib = "2.6.0"
[libraries] [libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" } junit = { group = "junit", name = "junit", version.ref = "junit" }
@ -24,6 +25,7 @@ lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-view
navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment", version.ref = "navigationFragment" } navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment", version.ref = "navigationFragment" }
navigation-ui = { group = "androidx.navigation", name = "navigation-ui", version.ref = "navigationUi" } navigation-ui = { group = "androidx.navigation", name = "navigation-ui", version.ref = "navigationUi" }
room-common = { group = "androidx.room", name = "room-common", version.ref = "roomCommon" } room-common = { group = "androidx.room", name = "room-common", version.ref = "roomCommon" }
car-ui-lib = { group = "com.android.car.ui", name = "car-ui-lib", version.ref = "carUiLib" }
[plugins] [plugins]
android-application = { id = "com.android.application", version.ref = "agp" } android-application = { id = "com.android.application", version.ref = "agp" }