Open Notes of Songs

This commit is contained in:
sebastian 2024-10-31 20:24:52 +01:00
parent 73fe1bf812
commit 3088f5e7b0
7 changed files with 73 additions and 6 deletions

View File

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

View File

@ -1,5 +1,7 @@
package core.notevault; package core.notevault;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -62,8 +64,14 @@ public class MainActivity extends AppCompatActivity implements MetaDataDialog.On
} }
@Override @Override
public void onMetadataEntered(String title, String composer, int year, String genre) { public void onMetadataEntered(Uri uri, String title, String composer, int year, String genre) {
MusicNote musicNote = new MusicNote(title, null, composer, year, genre); MusicNote musicNote = new MusicNote(title, uri.toString(), composer, year, genre);
// Anfordern der dauerhaften Lese-/Schreibberechtigungen für die URI
getContentResolver().takePersistableUriPermission(
uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
);
new Thread(() -> { new Thread(() -> {
musicDB.musicNoteDao().insert(musicNote); musicDB.musicNoteDao().insert(musicNote);

View File

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

View File

@ -94,7 +94,7 @@ public class HomeFragment extends Fragment {
} }
private void openFileChooser() { private void openFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*"); // Alle Dateitypen intent.setType("*/*"); // Alle Dateitypen
String[] mimeTypes = {"application/pdf", "image/png", "image/jpeg"}; String[] mimeTypes = {"application/pdf", "image/png", "image/jpeg"};

View File

@ -1,5 +1,6 @@
package core.notevault.ui.home; package core.notevault.ui.home;
import android.content.Intent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -48,12 +49,27 @@ public class NoteSongAdapter extends RecyclerView.Adapter<NoteSongAdapter.NoteVi
notifyDataSetChanged(); notifyDataSetChanged();
} }
static class NoteViewHolder extends RecyclerView.ViewHolder { public class NoteViewHolder extends RecyclerView.ViewHolder {
TextView titleTextView; TextView titleTextView;
NoteViewHolder(View itemView) { NoteViewHolder(View itemView) {
super(itemView); super(itemView);
titleTextView = itemView.findViewById(R.id.note_title); titleTextView = itemView.findViewById(R.id.note_title);
titleTextView.setOnClickListener(v -> {
int position = getAdapterPosition();
if(position != RecyclerView.NO_POSITION) {
MusicNote musicNote = noteTitles.get(position);
Intent intent = new Intent(itemView.getContext(), FullScreenImageActivity.class);
intent.putExtra("imageUri", musicNote.getFilePath()); // Hier URI hinzufügen
itemView.getContext().startActivity(intent);
}
});
}
public void bind(MusicNote note) {
titleTextView.setText(note.getTitle());
} }
} }
} }

View File

@ -19,7 +19,7 @@ public class MetaDataDialog extends DialogFragment {
private Uri fileUri; private Uri fileUri;
public interface OnMetadataListener { public interface OnMetadataListener {
void onMetadataEntered(String title, String composer, int year, String genre); void onMetadataEntered(Uri uri, String title, String composer, int year, String genre);
} }
private OnMetadataListener listener; private OnMetadataListener listener;
@ -50,7 +50,7 @@ public class MetaDataDialog extends DialogFragment {
String genre = genre_input.getText().toString(); String genre = genre_input.getText().toString();
listener.onMetadataEntered(title, composer, year, genre); listener.onMetadataEntered(fileUri, title, composer, year, genre);
} ) } )
.setNegativeButton("Abbrechen", (dialog, which) -> {} ) .setNegativeButton("Abbrechen", (dialog, which) -> {} )
.create(); .create();

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">
<ImageView
android:id="@+id/fullscreen_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"/>
</RelativeLayout>