diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1a5c8e7..6dfbb44 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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") } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 71d1156..8fc0a28 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,6 +23,11 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/stormtales/notevault/data/dao/SongDao.java b/app/src/main/java/com/stormtales/notevault/data/dao/SongDao.java index 6b6744f..2bb4809 100644 --- a/app/src/main/java/com/stormtales/notevault/data/dao/SongDao.java +++ b/app/src/main/java/com/stormtales/notevault/data/dao/SongDao.java @@ -26,4 +26,7 @@ public interface SongDao { @Query("SELECT * FROM NoteSheet WHERE songID = :songID") List getNoteSheetsBySong(int songID); + + @Query("SELECT localFileName FROM NoteSheet WHERE songID = :songID") + List getNoteSheetFilesBySongID(int songID); } diff --git a/app/src/main/java/com/stormtales/notevault/data/repositories/SongRepository.java b/app/src/main/java/com/stormtales/notevault/data/repositories/SongRepository.java index 8eaea1e..a9923c8 100644 --- a/app/src/main/java/com/stormtales/notevault/data/repositories/SongRepository.java +++ b/app/src/main/java/com/stormtales/notevault/data/repositories/SongRepository.java @@ -76,4 +76,11 @@ public class SongRepository { songDao.deleteNoteSheets(noteSheets); }); } + + public void getNoteSheetFilesBySongID(int songID, Callback> callback) { + Executors.newSingleThreadExecutor().execute(()-> { + List noteSheetFiles = songDao.getNoteSheetFilesBySongID(songID); + callback.onResult(noteSheetFiles); + }); + } } diff --git a/app/src/main/java/com/stormtales/notevault/ui/home/HomeFragment.java b/app/src/main/java/com/stormtales/notevault/ui/home/HomeFragment.java index aa976fb..72990d6 100644 --- a/app/src/main/java/com/stormtales/notevault/ui/home/HomeFragment.java +++ b/app/src/main/java/com/stormtales/notevault/ui/home/HomeFragment.java @@ -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); + + }); + } } \ No newline at end of file diff --git a/app/src/main/java/com/stormtales/notevault/ui/home/HomeViewModel.java b/app/src/main/java/com/stormtales/notevault/ui/home/HomeViewModel.java index 51d79cd..37ea293 100644 --- a/app/src/main/java/com/stormtales/notevault/ui/home/HomeViewModel.java +++ b/app/src/main/java/com/stormtales/notevault/ui/home/HomeViewModel.java @@ -81,4 +81,8 @@ public class HomeViewModel extends ViewModel { allSongs.setValue(currentSongs); } } + + public SongRepository getSongRepository() { + return songRepository; + } } \ No newline at end of file diff --git a/app/src/main/java/com/stormtales/notevault/ui/home/SongAdapter.java b/app/src/main/java/com/stormtales/notevault/ui/home/SongAdapter.java index 5b797df..81a4df2 100644 --- a/app/src/main/java/com/stormtales/notevault/ui/home/SongAdapter.java +++ b/app/src/main/java/com/stormtales/notevault/ui/home/SongAdapter.java @@ -20,11 +20,13 @@ public class SongAdapter extends RecyclerView.Adapter songList; private OnEditSongListener onEditSongListener; private OnDeleteSongListener onDeleteSongListener; + private OnOpenSongListener onOpenSongListener; - public SongAdapter(List songList, OnEditSongListener onEditSongListener, OnDeleteSongListener onDeleteSongListener) { + public SongAdapter(List songList, OnEditSongListener onEditSongListener, OnDeleteSongListener onDeleteSongListener, OnOpenSongListener onOpenSongListener) { this.songList = songList; this.onEditSongListener = onEditSongListener; this.onDeleteSongListener = onDeleteSongListener; + this.onOpenSongListener = onOpenSongListener; } public void updateData(List songs) { @@ -37,7 +39,7 @@ public class SongAdapter extends RecyclerView.Adapter { + 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 { + private final List imageUris; + private final Context context; + + public ImagePagerAdapter(Context context, List 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); + } + } +} diff --git a/app/src/main/java/com/stormtales/notevault/ui/sheetdisplay/NoteSheetDisplayActivity.java b/app/src/main/java/com/stormtales/notevault/ui/sheetdisplay/NoteSheetDisplayActivity.java new file mode 100644 index 0000000..843a6fc --- /dev/null +++ b/app/src/main/java/com/stormtales/notevault/ui/sheetdisplay/NoteSheetDisplayActivity.java @@ -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 uriList = Arrays.asList(imageUris); + ImagePagerAdapter adapter = new ImagePagerAdapter(this, uriList); + imageView.setAdapter(adapter); // Setze die URI in das ImageView + } else { + throw new NullPointerException(); + } + } +} diff --git a/app/src/main/res/layout/activity_note_sheet_viewer.xml b/app/src/main/res/layout/activity_note_sheet_viewer.xml new file mode 100644 index 0000000..d771ad9 --- /dev/null +++ b/app/src/main/res/layout/activity_note_sheet_viewer.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/main/res/layout/item_image.xml b/app/src/main/res/layout/item_image.xml new file mode 100644 index 0000000..1ccfcc7 --- /dev/null +++ b/app/src/main/res/layout/item_image.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/settings.gradle.kts b/settings.gradle.kts index e043b35..c55cbb2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,6 +16,7 @@ dependencyResolutionManagement { repositories { google() mavenCentral() + maven { url = uri("https://www.jitpack.io") } } }