nextNoteVault #23
@ -4,6 +4,14 @@
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2025-04-29T15:21:34.999046322Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=R52N50NLGRT" />
|
||||
</handle>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
<DialogSelection />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
</component>
|
||||
|
@ -2,6 +2,7 @@ package come.stormborntales.notevault
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.compose.setContent
|
||||
@ -13,6 +14,8 @@ 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.theme.NoteVaultTheme
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
@ -33,7 +36,7 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
// Launcher innerhalb von Compose
|
||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||
contract = ActivityResultContracts.PickMultipleVisualMedia(),
|
||||
contract = ActivityResultContracts.OpenMultipleDocuments(),
|
||||
onResult = { uris ->
|
||||
if (uris.isNotEmpty()) {
|
||||
selectedUris = uris
|
||||
@ -47,20 +50,26 @@ class MainActivity : ComponentActivity() {
|
||||
notes = notes,
|
||||
onAddNoteClicked = {
|
||||
imagePickerLauncher.launch(
|
||||
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageAndVideo)
|
||||
arrayOf("image/*")
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
// Dialog bei Bedarf
|
||||
if (showDialog) {
|
||||
val context = LocalContext.current;
|
||||
val scope = rememberCoroutineScope();
|
||||
AddNoteDialog(
|
||||
onDismiss = { showDialog = false },
|
||||
onSave = { title, composer, year, genre, description ->
|
||||
scope.launch(Dispatchers.IO) {
|
||||
val copiedUris = selectedUris.mapNotNull { uri ->
|
||||
try {
|
||||
val inputStream: InputStream? = context.contentResolver.openInputStream(uri)
|
||||
val outputFile = File(context.filesDir, "note_${System.currentTimeMillis()}_${uri.lastPathSegment}")
|
||||
val extension = MimeTypeMap.getSingleton()
|
||||
.getExtensionFromMimeType(context.contentResolver.getType(uri)) ?: "jpg" // Fallback
|
||||
|
||||
val outputFile = File(context.filesDir, "note_${System.currentTimeMillis()}.$extension")
|
||||
inputStream?.use { input ->
|
||||
outputFile.outputStream().use { output ->
|
||||
input.copyTo(output)
|
||||
@ -88,6 +97,9 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
showDialog = false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user