From 43c22ea6d699a73cc9f47129253a805a8ae96083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6ckelmann?= Date: Sat, 19 Apr 2025 16:31:16 +0200 Subject: [PATCH] FIX: Update visualized notes when new notes are added --- .idea/.gitignore | 8 ++++ .idea/.name | 1 + .idea/codeStyles/Project.xml | 10 +++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++ .idea/compiler.xml | 6 +++ .idea/deploymentTargetSelector.xml | 10 +++++ .idea/gradle.xml | 16 +++++++ .idea/kotlinc.xml | 6 +++ .idea/misc.xml | 5 +++ .idea/vcs.xml | 6 +++ .../stormborntales/notevault/MainActivity.kt | 21 --------- .../notevault/ui/screens/MainScreen.kt | 44 ++++++++++++++----- 12 files changed, 107 insertions(+), 31 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/compiler.xml create mode 100644 .idea/deploymentTargetSelector.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/kotlinc.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..3f3ac07 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +NoteVault \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..1bec35e --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..efd7cbf --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..6d0ee1c --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ed6ca53 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/come/stormborntales/notevault/MainActivity.kt b/app/src/main/java/come/stormborntales/notevault/MainActivity.kt index 2beb0af..3849445 100644 --- a/app/src/main/java/come/stormborntales/notevault/MainActivity.kt +++ b/app/src/main/java/come/stormborntales/notevault/MainActivity.kt @@ -53,11 +53,6 @@ class MainActivity : ComponentActivity() { } setContent { - // Initialisiere die Notenliste als State - val notes = remember { mutableStateListOf() } - // Launcher für die Bildauswahl einrichten - - NoteVaultTheme { MainScreen( onAddNoteClicked = { @@ -75,20 +70,4 @@ class MainActivity : ComponentActivity() { private fun addNoteToList(notes: MutableList, uri: Uri) { // Hier wird das Bild zur Liste hinzugefügt notes.add(uri) -} - -@Composable -fun Greeting(name: String, modifier: Modifier = Modifier) { - Text( - text = "Hello $name!", - modifier = modifier - ) -} - -@Preview(showBackground = true) -@Composable -fun GreetingPreview() { - NoteVaultTheme { - Greeting("Android") - } } \ No newline at end of file diff --git a/app/src/main/java/come/stormborntales/notevault/ui/screens/MainScreen.kt b/app/src/main/java/come/stormborntales/notevault/ui/screens/MainScreen.kt index 8ec033e..1c77df0 100644 --- a/app/src/main/java/come/stormborntales/notevault/ui/screens/MainScreen.kt +++ b/app/src/main/java/come/stormborntales/notevault/ui/screens/MainScreen.kt @@ -6,9 +6,7 @@ import android.graphics.ImageDecoder import android.media.Image import android.net.Uri import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.icons.Icons @@ -33,13 +31,24 @@ fun loadImageBitmap(context: Context, uri: Uri): ImageBitmap? { } } +fun getFileNameFromUri(context: Context, uri: Uri): String? { + val cursor = context.contentResolver.query(uri, null, null, null, null) + cursor?.use { + val nameIndex = it.getColumnIndex(android.provider.OpenableColumns.DISPLAY_NAME) + if (it.moveToFirst() && nameIndex >= 0) { + return it.getString(nameIndex) + } + } + return null +} + @OptIn(ExperimentalMaterial3Api::class) @Composable fun MainScreen( onAddNoteClicked: () -> Unit, // Übergib hier deine Logik für den Import notes: MutableList, // Liste der Notenbilder (hier als URI), ) { - val dummyNotes = remember { mutableStateListOf().apply { addAll(notes) } } + val dummyNotes = notes // Hole den aktuellen Context val context = LocalContext.current Scaffold( @@ -64,16 +73,31 @@ fun MainScreen( .padding(16.dp) ) { items(dummyNotes) { noteUri -> - // Lade das Bild mit der Hilfsfunktion val imageBitmap = loadImageBitmap(context, noteUri) + val fileName = getFileNameFromUri(context, noteUri) + if (imageBitmap != null) { - Image( - bitmap = imageBitmap, - contentDescription = "Notenblatt", + Card( modifier = Modifier .fillMaxWidth() - .padding(8.dp) - ) + .padding(8.dp), + elevation = CardDefaults.cardElevation(4.dp) + ) { + Row(modifier = Modifier.padding(8.dp)) { + Image( + bitmap = imageBitmap, + contentDescription = "Notenblatt Vorschau", + modifier = Modifier + .size(80.dp) // oder width = 80.dp, height = 100.dp + .padding(end = 8.dp) + ) + Text( + text = fileName ?: "Unbekannter Dateiname", + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.weight(2f) + ) + } + } } } }