From d3d1f482a8177cce9bd592789aca9151b60518c1 Mon Sep 17 00:00:00 2001 From: sebastian Date: Thu, 31 Oct 2024 19:54:32 +0100 Subject: [PATCH] Attempt to view notes --- .../ui/home/FullScreenImageActivity.java | 27 +++++++++++++++++++ .../core/notevault/ui/home/HomeFragment.java | 15 +++-------- .../notevault/ui/home/NoteSongAdapter.java | 25 ++++++++++++----- .../res/layout/activity_full_screen_image.xml | 12 +++++++++ 4 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/core/notevault/ui/home/FullScreenImageActivity.java create mode 100644 app/src/main/res/layout/activity_full_screen_image.xml diff --git a/app/src/main/java/core/notevault/ui/home/FullScreenImageActivity.java b/app/src/main/java/core/notevault/ui/home/FullScreenImageActivity.java new file mode 100644 index 0000000..9f72e9d --- /dev/null +++ b/app/src/main/java/core/notevault/ui/home/FullScreenImageActivity.java @@ -0,0 +1,27 @@ +package core.notevault.ui.home; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.widget.ImageView; +import androidx.appcompat.app.AppCompatActivity; +import core.notevault.R; + +public class FullScreenImageActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_full_screen_image); // Erstelle eine Layout-Datei + + ImageView imageView = findViewById(R.id.fullscreen_image_view); // Angenommen, du hast ein ImageView + + // Die URI aus dem Intent erhalten + Intent intent = getIntent(); + String imageUriString = intent.getStringExtra("imageUri"); + if (imageUriString != null) { + Uri imageUri = Uri.parse(imageUriString); + imageView.setImageURI(imageUri); // Setze die URI in das ImageView + } + } +} diff --git a/app/src/main/java/core/notevault/ui/home/HomeFragment.java b/app/src/main/java/core/notevault/ui/home/HomeFragment.java index ce58354..b2c7c1c 100644 --- a/app/src/main/java/core/notevault/ui/home/HomeFragment.java +++ b/app/src/main/java/core/notevault/ui/home/HomeFragment.java @@ -49,7 +49,6 @@ public class HomeFragment extends Fragment { RecyclerView recyclerView = root.findViewById(R.id.note_recycler_view); noteSongAdapter = new NoteSongAdapter(); - recyclerView.setAdapter(noteSongAdapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); new LoadSongTitlesTask().execute(); @@ -57,23 +56,17 @@ public class HomeFragment extends Fragment { return root; } - private class LoadSongTitlesTask extends AsyncTask> { + private class LoadSongTitlesTask extends AsyncTask> { @Override - protected List doInBackground(Void... voids) { + protected List doInBackground(Void... voids) { MusicDatabase db = MusicDatabase.getDatabase(getContext()); MusicNoteDAO musicNoteDAO = db.musicNoteDao(); - List songs = musicNoteDAO.getAllNotes(); - - List result = new ArrayList<>(); - for (MusicNote song : songs) { - result.add(song.getTitle()); - } - return result; + return musicNoteDAO.getAllNotes(); } @Override - protected void onPostExecute(List songTitles) { + protected void onPostExecute(List songTitles) { noteSongAdapter.updateSongTitles(songTitles); // Aktualisiere den Adapter mit den Titeln } } diff --git a/app/src/main/java/core/notevault/ui/home/NoteSongAdapter.java b/app/src/main/java/core/notevault/ui/home/NoteSongAdapter.java index 5330b92..e557188 100644 --- a/app/src/main/java/core/notevault/ui/home/NoteSongAdapter.java +++ b/app/src/main/java/core/notevault/ui/home/NoteSongAdapter.java @@ -1,5 +1,6 @@ package core.notevault.ui.home; +import android.content.Intent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -7,15 +8,16 @@ 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 NoteSongAdapter extends RecyclerView.Adapter { - private final List noteTitles; + private List noteTitles; - public NoteSongAdapter(List noteTitles) { + public NoteSongAdapter(List noteTitles) { this.noteTitles = noteTitles; } @@ -33,7 +35,7 @@ public class NoteSongAdapter extends RecyclerView.Adapter songTitles) { + public void updateSongTitles(List songTitles) { this.noteTitles.clear(); this.noteTitles.addAll(songTitles); notifyDataSetChanged(); } - static class NoteViewHolder extends RecyclerView.ViewHolder { + public class NoteViewHolder extends RecyclerView.ViewHolder { TextView titleTextView; - NoteViewHolder(View itemView) { + public NoteViewHolder(View itemView) { super(itemView); titleTextView = itemView.findViewById(R.id.note_title); + + titleTextView.setOnClickListener(v -> { + int position = getAdapterPosition(); + if(position != RecyclerView.NO_POSITION) { + MusicNote song = noteTitles.get(position); + + Intent intent = new Intent(itemView.getContext(), FullScreenImageActivity.class); + intent.putExtra("imageUri", song.getFilePath()); + itemView.getContext().startActivity(intent); + } + }); } } } diff --git a/app/src/main/res/layout/activity_full_screen_image.xml b/app/src/main/res/layout/activity_full_screen_image.xml new file mode 100644 index 0000000..c5a2929 --- /dev/null +++ b/app/src/main/res/layout/activity_full_screen_image.xml @@ -0,0 +1,12 @@ + + + + + +