UPD: Select files from nextcloud o.ä.
This commit is contained in:
parent
2f089bd3c4
commit
646e2a5f1a
@ -4,6 +4,14 @@
|
|||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<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>
|
</SelectionState>
|
||||||
</selectionStates>
|
</selectionStates>
|
||||||
</component>
|
</component>
|
||||||
|
@ -2,6 +2,7 @@ package come.stormborntales.notevault
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.webkit.MimeTypeMap
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.compose.setContent
|
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.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 kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
@ -33,7 +36,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
// Launcher innerhalb von Compose
|
// Launcher innerhalb von Compose
|
||||||
val imagePickerLauncher = rememberLauncherForActivityResult(
|
val imagePickerLauncher = rememberLauncherForActivityResult(
|
||||||
contract = ActivityResultContracts.PickMultipleVisualMedia(),
|
contract = ActivityResultContracts.OpenMultipleDocuments(),
|
||||||
onResult = { uris ->
|
onResult = { uris ->
|
||||||
if (uris.isNotEmpty()) {
|
if (uris.isNotEmpty()) {
|
||||||
selectedUris = uris
|
selectedUris = uris
|
||||||
@ -47,20 +50,26 @@ class MainActivity : ComponentActivity() {
|
|||||||
notes = notes,
|
notes = notes,
|
||||||
onAddNoteClicked = {
|
onAddNoteClicked = {
|
||||||
imagePickerLauncher.launch(
|
imagePickerLauncher.launch(
|
||||||
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageAndVideo)
|
arrayOf("image/*")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Dialog bei Bedarf
|
// Dialog bei Bedarf
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
|
val context = LocalContext.current;
|
||||||
|
val scope = rememberCoroutineScope();
|
||||||
AddNoteDialog(
|
AddNoteDialog(
|
||||||
onDismiss = { showDialog = false },
|
onDismiss = { showDialog = false },
|
||||||
onSave = { title, composer, year, genre, description ->
|
onSave = { title, composer, year, genre, description ->
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
val copiedUris = selectedUris.mapNotNull { uri ->
|
val copiedUris = selectedUris.mapNotNull { uri ->
|
||||||
try {
|
try {
|
||||||
val inputStream: InputStream? = context.contentResolver.openInputStream(uri)
|
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 ->
|
inputStream?.use { input ->
|
||||||
outputFile.outputStream().use { output ->
|
outputFile.outputStream().use { output ->
|
||||||
input.copyTo(output)
|
input.copyTo(output)
|
||||||
@ -88,6 +97,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
showDialog = false
|
showDialog = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user