FIX: Update visualized notes when new notes are added

This commit is contained in:
Sebastian Böckelmann 2025-04-19 16:31:16 +02:00
parent 40fd227092
commit 43c22ea6d6
12 changed files with 107 additions and 31 deletions

8
.idea/.gitignore vendored Normal file
View File

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

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
NoteVault

View File

@ -0,0 +1,10 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

6
.idea/compiler.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="21" />
</component>
</project>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetSelector">
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
</SelectionState>
</selectionStates>
</component>
</project>

16
.idea/gradle.xml Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

6
.idea/kotlinc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="2.0.0" />
</component>
</project>

5
.idea/misc.xml Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="21" project-jdk-type="JavaSDK" />
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -53,11 +53,6 @@ class MainActivity : ComponentActivity() {
} }
setContent { setContent {
// Initialisiere die Notenliste als State
val notes = remember { mutableStateListOf<Uri>() }
// Launcher für die Bildauswahl einrichten
NoteVaultTheme { NoteVaultTheme {
MainScreen( MainScreen(
onAddNoteClicked = { onAddNoteClicked = {
@ -76,19 +71,3 @@ private fun addNoteToList(notes: MutableList<Uri>, uri: Uri) {
// Hier wird das Bild zur Liste hinzugefügt // Hier wird das Bild zur Liste hinzugefügt
notes.add(uri) 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")
}
}

View File

@ -6,9 +6,7 @@ import android.graphics.ImageDecoder
import android.media.Image import android.media.Image
import android.net.Uri import android.net.Uri
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons 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) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun MainScreen( fun MainScreen(
onAddNoteClicked: () -> Unit, // Übergib hier deine Logik für den Import onAddNoteClicked: () -> Unit, // Übergib hier deine Logik für den Import
notes: MutableList<Uri>, // Liste der Notenbilder (hier als URI), notes: MutableList<Uri>, // Liste der Notenbilder (hier als URI),
) { ) {
val dummyNotes = remember { mutableStateListOf<Uri>().apply { addAll(notes) } } val dummyNotes = notes
// Hole den aktuellen Context // Hole den aktuellen Context
val context = LocalContext.current val context = LocalContext.current
Scaffold( Scaffold(
@ -64,16 +73,31 @@ fun MainScreen(
.padding(16.dp) .padding(16.dp)
) { ) {
items(dummyNotes) { noteUri -> items(dummyNotes) { noteUri ->
// Lade das Bild mit der Hilfsfunktion
val imageBitmap = loadImageBitmap(context, noteUri) val imageBitmap = loadImageBitmap(context, noteUri)
val fileName = getFileNameFromUri(context, noteUri)
if (imageBitmap != null) { if (imageBitmap != null) {
Image( Card(
bitmap = imageBitmap,
contentDescription = "Notenblatt",
modifier = Modifier modifier = Modifier
.fillMaxWidth() .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)
)
}
}
} }
} }
} }