Display NoteSheets

This commit is contained in:
Fawkes100 2025-01-18 18:45:40 +01:00
parent 7e04b7c9f3
commit 2f38b0eed7
12 changed files with 156 additions and 3 deletions

View File

@ -45,4 +45,5 @@ dependencies {
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
annotationProcessor(libs.room.compiler)
implementation("com.github.chrisbanes:PhotoView:2.3.0")
}

View File

@ -23,6 +23,11 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".ui.sheetdisplay.NoteSheetDisplayActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
<!-- Intent Filter hinzufügen, wenn Activity vom Launcher oder externen Apps aufgerufen werden soll -->
</activity>
</application>
</manifest>

View File

@ -26,4 +26,7 @@ public interface SongDao {
@Query("SELECT * FROM NoteSheet WHERE songID = :songID")
List<NoteSheet> getNoteSheetsBySong(int songID);
@Query("SELECT localFileName FROM NoteSheet WHERE songID = :songID")
List<String> getNoteSheetFilesBySongID(int songID);
}

View File

@ -76,4 +76,11 @@ public class SongRepository {
songDao.deleteNoteSheets(noteSheets);
});
}
public void getNoteSheetFilesBySongID(int songID, Callback<List<String>> callback) {
Executors.newSingleThreadExecutor().execute(()-> {
List<String> noteSheetFiles = songDao.getNoteSheetFilesBySongID(songID);
callback.onResult(noteSheetFiles);
});
}
}

View File

@ -24,6 +24,7 @@ import com.stormtales.notevault.R;
import com.stormtales.notevault.data.entities.Song;
import com.stormtales.notevault.data.repositories.SongRepository;
import com.stormtales.notevault.databinding.FragmentHomeBinding;
import com.stormtales.notevault.ui.sheetdisplay.NoteSheetDisplayActivity;
import com.stormtales.notevault.ui.songeditor.SongEditorDialog;
import java.util.ArrayList;
@ -84,7 +85,7 @@ public class HomeFragment extends Fragment {
});
// RecyclerView einrichten
songAdapter = new SongAdapter(new ArrayList<>(), this::onEditSong, this::onDeleteSong);
songAdapter = new SongAdapter(new ArrayList<>(), this::onEditSong, this::onDeleteSong, this::onOpenSong);
recyclerView.setAdapter(songAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), LinearLayoutManager.VERTICAL);
@ -121,4 +122,17 @@ public class HomeFragment extends Fragment {
public void onDeleteSong(Song song) {
this.homeViewModel.deleteSong(song);
}
public void onOpenSong(Song song) {
homeViewModel.getSongRepository().getNoteSheetFilesBySongID(song.getLocalID(), result -> {
String[] noteSheetFiles = new String[result.size()];
for(int i = 0; i < result.size(); i++) {
noteSheetFiles[i] = result.get(i);
}
Intent intent = new Intent(getContext(), NoteSheetDisplayActivity.class);
intent.putExtra("imageUris", noteSheetFiles);
getContext().startActivity(intent);
});
}
}

View File

@ -81,4 +81,8 @@ public class HomeViewModel extends ViewModel {
allSongs.setValue(currentSongs);
}
}
public SongRepository getSongRepository() {
return songRepository;
}
}

View File

@ -20,11 +20,13 @@ public class SongAdapter extends RecyclerView.Adapter<SongAdapter.SongViewHolder
private List<Song> songList;
private OnEditSongListener onEditSongListener;
private OnDeleteSongListener onDeleteSongListener;
private OnOpenSongListener onOpenSongListener;
public SongAdapter(List<Song> songList, OnEditSongListener onEditSongListener, OnDeleteSongListener onDeleteSongListener) {
public SongAdapter(List<Song> songList, OnEditSongListener onEditSongListener, OnDeleteSongListener onDeleteSongListener, OnOpenSongListener onOpenSongListener) {
this.songList = songList;
this.onEditSongListener = onEditSongListener;
this.onDeleteSongListener = onDeleteSongListener;
this.onOpenSongListener = onOpenSongListener;
}
public void updateData(List<Song> songs) {
@ -37,7 +39,7 @@ public class SongAdapter extends RecyclerView.Adapter<SongAdapter.SongViewHolder
Log.d("SongAdapter", "Data updated: " + this.songList.size());
}
public static class SongViewHolder extends RecyclerView.ViewHolder {
public class SongViewHolder extends RecyclerView.ViewHolder {
TextView textYear, textComposition, textTitle;
ImageButton editButton, deleteButton;
@ -48,6 +50,14 @@ public class SongAdapter extends RecyclerView.Adapter<SongAdapter.SongViewHolder
textTitle = itemView.findViewById(R.id.text_title);
editButton = itemView.findViewById(R.id.edit_song_button);
deleteButton = itemView.findViewById(R.id.delete_song_button);
textTitle.setOnClickListener(v -> {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
Song song = songList.get(position);
onOpenSongListener.onOpenSong(song);
}
});
}
}
@ -82,4 +92,8 @@ public class SongAdapter extends RecyclerView.Adapter<SongAdapter.SongViewHolder
public interface OnDeleteSongListener {
void onDeleteSong(Song song);
}
public interface OnOpenSongListener {
void onOpenSong(Song song);
}
}

View File

@ -0,0 +1,51 @@
package com.stormtales.notevault.ui.sheetdisplay;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.github.chrisbanes.photoview.PhotoView;
import com.stormtales.notevault.R;
import java.util.List;
public class ImagePagerAdapter extends RecyclerView.Adapter<ImagePagerAdapter.ImageViewHolder> {
private final List<String> imageUris;
private final Context context;
public ImagePagerAdapter(Context context, List<String> imageUris) {
this.context = context;
this.imageUris = imageUris;
}
@NonNull
@Override
public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item_image, parent, false);
return new ImageViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
Uri uri = Uri.parse(imageUris.get(position));
holder.photoView.setImageURI(uri);
}
@Override
public int getItemCount() {
return imageUris.size();
}
static class ImageViewHolder extends RecyclerView.ViewHolder {
PhotoView photoView;
ImageViewHolder(View itemView) {
super(itemView);
photoView = itemView.findViewById(R.id.photoView);
}
}
}

View File

@ -0,0 +1,31 @@
package com.stormtales.notevault.ui.sheetdisplay;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;
import com.stormtales.notevault.R;
import java.util.Arrays;
import java.util.List;
public class NoteSheetDisplayActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_sheet_viewer); // Erstelle eine Layout-Datei
ViewPager2 imageView = findViewById(R.id.viewPager); // Angenommen, du hast ein ImageView
// Die URI aus dem Intent erhalten
Intent intent = getIntent();
String[] imageUris = intent.getStringArrayExtra("imageUris");
if (imageUris != null) {
List<String> uriList = Arrays.asList(imageUris);
ImagePagerAdapter adapter = new ImagePagerAdapter(this, uriList);
imageView.setAdapter(adapter); // Setze die URI in das ImageView
} else {
throw new NullPointerException();
}
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />
</FrameLayout>

View File

@ -16,6 +16,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url = uri("https://www.jitpack.io") }
}
}