ADD: Add Metadata to added Notes
This commit is contained in:
parent
b132779730
commit
03f1a55437
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="21" project-jdk-type="JavaSDK" />
|
<component name="FrameworkDetectionExcludesConfiguration">
|
||||||
|
<file type="web" url="file://$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK" />
|
||||||
</project>
|
</project>
|
12
.idea/runConfigurations.xml
Normal file
12
.idea/runConfigurations.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RunConfigurationProducerService">
|
||||||
|
<option name="ignoredProducers">
|
||||||
|
<set>
|
||||||
|
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
|
||||||
|
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
|
||||||
|
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,38 +1,66 @@
|
|||||||
package come.stormborntales.notevault
|
package come.stormborntales.notevault
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
|
||||||
import androidx.activity.result.PickVisualMediaRequest
|
import androidx.activity.result.PickVisualMediaRequest
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import come.stormborntales.notevault.data.model.NoteEntry
|
import come.stormborntales.notevault.data.model.NoteEntry
|
||||||
|
import come.stormborntales.notevault.ui.screens.AddNoteDialog
|
||||||
import come.stormborntales.notevault.ui.screens.MainScreen
|
import come.stormborntales.notevault.ui.screens.MainScreen
|
||||||
import come.stormborntales.notevault.ui.theme.NoteVaultTheme
|
import come.stormborntales.notevault.ui.theme.NoteVaultTheme
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
private lateinit var imagePickerLauncher: ActivityResultLauncher<PickVisualMediaRequest>
|
|
||||||
// Definiere notes als MutableStateList für die gesamte Aktivität
|
|
||||||
private val notes = mutableStateListOf<NoteEntry>()
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
enableEdgeToEdge()
|
|
||||||
|
|
||||||
// Launcher für die Bildauswahl einrichten
|
setContent {
|
||||||
imagePickerLauncher = registerForActivityResult(ActivityResultContracts.PickMultipleVisualMedia()) { uris ->
|
NoteVaultTheme {
|
||||||
if (!uris.isNullOrEmpty()) {
|
val context = LocalContext.current
|
||||||
val context: Context = applicationContext
|
|
||||||
val copiedUris = uris.mapNotNull { uri ->
|
// Globale Notenliste
|
||||||
|
val notes = remember { mutableStateListOf<NoteEntry>() }
|
||||||
|
|
||||||
|
// Bildauswahl + Dialog-States
|
||||||
|
var selectedUris by remember { mutableStateOf<List<Uri>>(emptyList()) }
|
||||||
|
var showDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
// Launcher innerhalb von Compose
|
||||||
|
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||||
|
contract = ActivityResultContracts.PickMultipleVisualMedia(),
|
||||||
|
onResult = { uris ->
|
||||||
|
if (uris.isNotEmpty()) {
|
||||||
|
selectedUris = uris
|
||||||
|
showDialog = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// UI anzeigen
|
||||||
|
MainScreen(
|
||||||
|
notes = notes,
|
||||||
|
onAddNoteClicked = {
|
||||||
|
imagePickerLauncher.launch(
|
||||||
|
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageAndVideo)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Dialog bei Bedarf
|
||||||
|
if (showDialog) {
|
||||||
|
AddNoteDialog(
|
||||||
|
onDismiss = { showDialog = false },
|
||||||
|
onSave = { title, composer, year, genre, description ->
|
||||||
|
val copiedUris = selectedUris.mapNotNull { uri ->
|
||||||
try {
|
try {
|
||||||
val inputStream: InputStream? = contentResolver.openInputStream(uri)
|
val inputStream: InputStream? = context.contentResolver.openInputStream(uri)
|
||||||
val outputFile =
|
val outputFile = File(context.filesDir, "note_${System.currentTimeMillis()}_${uri.lastPathSegment}")
|
||||||
File(context.filesDir, "note_${System.currentTimeMillis()}_${uri.lastPathSegment}")
|
|
||||||
inputStream?.use { input ->
|
inputStream?.use { input ->
|
||||||
outputFile.outputStream().use { output ->
|
outputFile.outputStream().use { output ->
|
||||||
input.copyTo(output)
|
input.copyTo(output)
|
||||||
@ -46,21 +74,23 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (copiedUris.isNotEmpty()) {
|
if (copiedUris.isNotEmpty()) {
|
||||||
notes.add(NoteEntry(images = copiedUris)) // Titel optional setzen
|
notes.add(
|
||||||
}
|
NoteEntry(
|
||||||
}
|
title = title,
|
||||||
|
images = copiedUris,
|
||||||
|
composer = composer,
|
||||||
|
year = year,
|
||||||
|
genre = genre,
|
||||||
|
description = description
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
setContent {
|
showDialog = false
|
||||||
NoteVaultTheme {
|
}
|
||||||
MainScreen(
|
|
||||||
onAddNoteClicked = {
|
|
||||||
// Öffne die Galerie zum Auswählen eines Bildes
|
|
||||||
imagePickerLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageAndVideo))
|
|
||||||
},
|
|
||||||
notes = notes,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,9 +2,9 @@ package come.stormborntales.notevault.data.model
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
|
||||||
class NoteEntry(images: List<Uri>) {
|
class NoteEntry(
|
||||||
val title: String = "Unbenannt" // oder optional
|
val title: String, val images: List<Uri>, val composer: String?, val year: Int?,
|
||||||
val images: List<Uri> = images;
|
val genre: String?, val description: String?
|
||||||
|
) {
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
package come.stormborntales.notevault.ui.screens
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun AddNoteDialog(
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onSave: (title: String, composer: String?, year: Int?, genre: String?, description: String?) -> Unit
|
||||||
|
) {
|
||||||
|
var title by remember { mutableStateOf("") }
|
||||||
|
var composer by remember { mutableStateOf("") }
|
||||||
|
var year by remember { mutableStateOf("") }
|
||||||
|
var genre by remember { mutableStateOf("") }
|
||||||
|
var description by remember { mutableStateOf("") }
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = { Text("Notenblatt hinzufügen") },
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = title,
|
||||||
|
onValueChange = { title = it },
|
||||||
|
label = { Text("Titel*") },
|
||||||
|
singleLine = true
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = composer,
|
||||||
|
onValueChange = { composer = it },
|
||||||
|
label = { Text("Komponist") },
|
||||||
|
singleLine = true
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = year,
|
||||||
|
onValueChange = { year = it },
|
||||||
|
label = { Text("Erscheinungsjahr") },
|
||||||
|
singleLine = true
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = genre,
|
||||||
|
onValueChange = { genre = it },
|
||||||
|
label = { Text("Genre") },
|
||||||
|
singleLine = true
|
||||||
|
)
|
||||||
|
OutlinedTextField(
|
||||||
|
value = description,
|
||||||
|
onValueChange = { description = it },
|
||||||
|
label = { Text("Beschreibung") },
|
||||||
|
modifier = Modifier.height(100.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
if (title.isNotBlank()) {
|
||||||
|
val parsedYear = year.toIntOrNull()
|
||||||
|
onSave(title, composer.ifBlank { null }, parsedYear, genre.ifBlank { null }, description.ifBlank { null })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text("Speichern")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Abbrechen")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user