Modern Apps git

← Modern-Apps.git

files + others: fix drag and drop

Commit
1583bab8d363a79a2b64160dca72087e859daff5
Author
Vayun Mathur <[email protected]>
When
2026-05-06 21:46 UTC (7 months ago)
Parents
8f6317b

Diff

calendar/src/main/AndroidManifest.xml
diff --git a/calendar/src/main/AndroidManifest.xml b/calendar/src/main/AndroidManifest.xmlindex 5abf740ea5..58666d1da4 100644--- a/calendar/src/main/AndroidManifest.xml+++ b/calendar/src/main/AndroidManifest.xml@@ -20,7 +20,10 @@             android:name="MainActivity"             android:exported="true"             android:theme="@style/Theme.General">-+            <intent-filter>+                <action android:name="android.intent.action.MAIN" />+                <category android:name="android.intent.category.LAUNCHER" />+            </intent-filter>             <intent-filter>                 <action android:name="android.intent.action.INSERT" />                 <data android:mimeType="vnd.android.cursor.dir/event" />
contacts/src/main/AndroidManifest.xml
diff --git a/contacts/src/main/AndroidManifest.xml b/contacts/src/main/AndroidManifest.xmlindex 1790bd4f7a..f45e3b9a2c 100644--- a/contacts/src/main/AndroidManifest.xml+++ b/contacts/src/main/AndroidManifest.xml@@ -35,9 +35,10 @@             android:name=".MainActivity"             android:exported="true"             android:theme="@style/Theme.General">---+            <intent-filter>+                <action android:name="android.intent.action.MAIN" />+                <category android:name="android.intent.category.LAUNCHER" />+            </intent-filter>             <intent-filter>                 <action android:name="android.intent.action.PICK" />                 <data android:mimeType="vnd.android.cursor.dir/contact" />
files/src/main/AndroidManifest.xml
diff --git a/files/src/main/AndroidManifest.xml b/files/src/main/AndroidManifest.xmlindex 2279d26e81..55a787ed6a 100644--- a/files/src/main/AndroidManifest.xml+++ b/files/src/main/AndroidManifest.xml@@ -38,9 +38,14 @@             android:theme="@style/Theme.General">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />-                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>+            <intent-filter>+                <action android:name="android.intent.action.SEND" />+                <action android:name="android.intent.action.SEND_MULTIPLE" />+                <category android:name="android.intent.category.DEFAULT" />+                <data android:mimeType="*/*" />+            </intent-filter>         </activity>          <!-- Text editor activity to open/edit/save text files using SAF -->
files/src/main/java/com/vayunmathur/files/MainActivity.kt
diff --git a/files/src/main/java/com/vayunmathur/files/MainActivity.kt b/files/src/main/java/com/vayunmathur/files/MainActivity.ktindex 88c8291017..d0a3bc110a 100644--- a/files/src/main/java/com/vayunmathur/files/MainActivity.kt+++ b/files/src/main/java/com/vayunmathur/files/MainActivity.kt@@ -3,6 +3,7 @@ package com.vayunmathur.files import android.Manifest import android.content.ClipData import android.content.ClipDescription+import android.content.ContentResolver import android.content.Context import android.content.Intent import android.content.pm.PackageManager@@ -12,6 +13,7 @@ import android.os.Bundle import android.os.Environment import android.os.FileObserver import android.provider.Settings+import android.provider.OpenableColumns import android.view.View import android.webkit.MimeTypeMap import androidx.activity.ComponentActivity@@ -30,13 +32,11 @@ import androidx.compose.foundation.gestures.detectDragGesturesAfterLongPress import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.rememberScrollState@@ -96,51 +96,86 @@ import com.vayunmathur.library.ui.IconChevronRight import com.vayunmathur.library.ui.IconClose import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.IconEdit+import com.vayunmathur.library.ui.IconSave import com.vayunmathur.library.ui.IconUnarchive-import kotlinx.coroutines.Dispatchers+import kotlin.math.roundToLong import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.launch import okio.FileSystem-import okio.openZip import okio.Path import okio.Path.Companion.toOkioPath import okio.Path.Companion.toPath-import kotlin.math.roundToLong+import okio.openZip+import okio.source  class MainActivity : ComponentActivity() {+    private var incomingUris by mutableStateOf<List<Uri>?>(null)+     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)+        handleIntent(intent)         enableEdgeToEdge()-        setContent {-            DynamicTheme {-                HomeDirectoryPage()+        setContent { DynamicTheme { HomeDirectoryPage(incomingUris) { incomingUris = null } } }+    }++    override fun onNewIntent(intent: Intent) {+        super.onNewIntent(intent)+        handleIntent(intent)+    }++    private fun handleIntent(intent: Intent?) {+        if (intent == null) return+        val action = intent.action+        val type = intent.type++        if (Intent.ACTION_SEND == action && type != null) {+            val uri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)+            if (uri != null) {+                incomingUris = listOf(uri)+            }+        } else if (Intent.ACTION_SEND_MULTIPLE == action && type != null) {+            val uris = intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)+            if (uris != null) {+                incomingUris = uris             }         }     } }  @Composable-fun HomeDirectoryPage() {+fun HomeDirectoryPage(incomingUris: List<Uri>? = null, onClearIncoming: () -> Unit = {}) {     val context = LocalContext.current     val prefs = remember { context.getSharedPreferences("files_prefs", Context.MODE_PRIVATE) }-    +     var isFilesGranted by remember { mutableStateOf(Environment.isExternalStorageManager()) }-    var hasPromptedNotifications by remember { mutableStateOf(prefs.getBoolean("has_prompted_notifications", false)) }+    var hasPromptedNotifications by remember {+        mutableStateOf(prefs.getBoolean("has_prompted_notifications", false))+    }     var showNotificationDialog by remember { mutableStateOf(false) } -    val filesLauncher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {-        isFilesGranted = Environment.isExternalStorageManager()-    }+    val filesLauncher =+            rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {+                isFilesGranted = Environment.isExternalStorageManager()+            } -    val notificationsLauncher = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->-        prefs.edit().putBoolean("has_prompted_notifications", true).apply()-        hasPromptedNotifications = true-        showNotificationDialog = false-    }+    val notificationsLauncher =+            rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) {+                    isGranted ->+                prefs.edit().putBoolean("has_prompted_notifications", true).apply()+                hasPromptedNotifications = true+                showNotificationDialog = false+            }      LaunchedEffect(isFilesGranted, hasPromptedNotifications) {-        if (isFilesGranted && !hasPromptedNotifications && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {-            val isGranted = ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED+        if (isFilesGranted &&+                        !hasPromptedNotifications &&+                        Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU+        ) {+            val isGranted =+                    ContextCompat.checkSelfPermission(+                            context,+                            Manifest.permission.POST_NOTIFICATIONS+                    ) == PackageManager.PERMISSION_GRANTED             if (!isGranted) {                 showNotificationDialog = true             } else {@@ -152,60 +187,72 @@ fun HomeDirectoryPage() {      if (showNotificationDialog) {         AlertDialog(-            onDismissRequest = { -                prefs.edit().putBoolean("has_prompted_notifications", true).apply()-                hasPromptedNotifications = true-                showNotificationDialog = false -            },-            title = { Text(stringResource(R.string.enable_notifications)) },-            text = { Text(stringResource(R.string.notification_permission_rationale)) },-            confirmButton = {-                TextButton(onClick = {-                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {-                        notificationsLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)-                    }-                }) {-                    Text(stringResource(R.string.enable))-                }-            },-            dismissButton = {-                TextButton(onClick = {+                onDismissRequest = {                     prefs.edit().putBoolean("has_prompted_notifications", true).apply()                     hasPromptedNotifications = true                     showNotificationDialog = false-                }) {-                    Text(stringResource(R.string.skip))+                },+                title = { Text(stringResource(R.string.enable_notifications)) },+                text = { Text(stringResource(R.string.notification_permission_rationale)) },+                confirmButton = {+                    TextButton(+                            onClick = {+                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {+                                    notificationsLauncher.launch(+                                            Manifest.permission.POST_NOTIFICATIONS+                                    )+                                }+                            }+                    ) { Text(stringResource(R.string.enable)) }+                },+                dismissButton = {+                    TextButton(+                            onClick = {+                                prefs.edit().putBoolean("has_prompted_notifications", true).apply()+                                hasPromptedNotifications = true+                                showNotificationDialog = false+                            }+                    ) { Text(stringResource(R.string.skip)) }                 }-            }         )     }      if (!isFilesGranted) {         Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {-            Button(onClick = {-                val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION).apply {-                    data = Uri.fromParts("package", context.packageName, null)-                }-                filesLauncher.launch(intent)-            }) {-                Text(stringResource(R.string.grant_all_files_access))-            }+            Button(+                    onClick = {+                        val intent =+                                Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)+                                        .apply {+                                            data =+                                                    Uri.fromParts(+                                                            "package",+                                                            context.packageName,+                                                            null+                                                    )+                                        }+                        filesLauncher.launch(intent)+                    }+            ) { Text(stringResource(R.string.grant_all_files_access)) }         }     } else {-        DirectoryPage(Environment.getExternalStorageDirectory().toOkioPath())+        DirectoryPage(Environment.getExternalStorageDirectory().toOkioPath(), incomingUris, onClearIncoming)     } }  val fs = FileSystem.SYSTEM-fun Path.listFiles(fileSystem: FileSystem = fs): List<Path> = try {-    fileSystem.list(this).toList()-} catch (e: Exception) {-    emptyList()-}-fun Path.isDirectory(fileSystem: FileSystem = fs): Boolean-    = fileSystem.metadataOrNull(this)?.isDirectory ?: false-fun Path.size(fileSystem: FileSystem = fs): Long?-    = fileSystem.metadataOrNull(this)?.size++fun Path.listFiles(fileSystem: FileSystem = fs): List<Path> =+        try {+            fileSystem.list(this).toList()+        } catch (e: Exception) {+            emptyList()+        }++fun Path.isDirectory(fileSystem: FileSystem = fs): Boolean =+        fileSystem.metadataOrNull(this)?.isDirectory ?: false++fun Path.size(fileSystem: FileSystem = fs): Long? = fileSystem.metadataOrNull(this)?.size  fun Path.deleteRecursively(fileSystem: FileSystem = fs) {     if (isDirectory(fileSystem)) {@@ -216,105 +263,152 @@ fun Path.deleteRecursively(fileSystem: FileSystem = fs) {  @OptIn(ExperimentalMaterial3Api::class) @Composable-fun DirectoryPage(rootFile: Path) {+fun DirectoryPage(+        rootFile: Path,+        incomingUris: List<Uri>? = null,+        onClearIncoming: () -> Unit = {}+) {     val context = LocalContext.current     val snackbarHostState = remember { SnackbarHostState() }     val scope = rememberCoroutineScope()-    +     var currentFileSystem by remember { mutableStateOf<FileSystem>(fs) }     var currentDirectory by remember { mutableStateOf(rootFile) }     var zipPath by remember { mutableStateOf<Path?>(null) }-    +     val isReadOnly = zipPath != null-    -    var selectedPaths by remember(currentDirectory, currentFileSystem) { mutableStateOf(setOf<Path>()) }++    var selectedPaths by+            remember(currentDirectory, currentFileSystem) { mutableStateOf(setOf<Path>()) }     var pathBeingRenamed by remember { mutableStateOf<Path?>(null) }     var showArchiveDialog by remember { mutableStateOf(false) }     var archiveName by remember { mutableStateOf("archive.zip") }      if (showArchiveDialog) {         AlertDialog(-            onDismissRequest = { showArchiveDialog = false },-            title = { Text(stringResource(R.string.archive_selection)) },-            text = {-                TextField(-                    value = archiveName,-                    onValueChange = { archiveName = it },-                    label = { Text(stringResource(R.string.zip_file_name_label)) },-                    singleLine = true-                )-            },-            confirmButton = {-                TextButton(onClick = {-                    val destPath = currentDirectory.resolve(if (archiveName.endsWith(".zip")) archiveName else "$archiveName.zip")-                    val zipWork = OneTimeWorkRequestBuilder<ZipWorker>()-                        .setInputData(workDataOf(-                            "source_paths" to selectedPaths.map { it.toString() }.toTypedArray(),-                            "dest_path" to destPath.toString()-                        ))-                        .build()-                    WorkManager.getInstance(context).enqueue(zipWork)-                    selectedPaths = emptySet()-                    pathBeingRenamed = null-                    showArchiveDialog = false-                    scope.launch {-                        snackbarHostState.showSnackbar(context.getString(R.string.archiving_started))+                onDismissRequest = { showArchiveDialog = false },+                title = { Text(stringResource(R.string.archive_selection)) },+                text = {+                    TextField(+                            value = archiveName,+                            onValueChange = { archiveName = it },+                            label = { Text(stringResource(R.string.zip_file_name_label)) },+                            singleLine = true+                    )+                },+                confirmButton = {+                    TextButton(+                            onClick = {+                                val destPath =+                                        currentDirectory.resolve(+                                                if (archiveName.endsWith(".zip")) archiveName+                                                else "$archiveName.zip"+                                        )+                                val zipWork =+                                        OneTimeWorkRequestBuilder<ZipWorker>()+                                                .setInputData(+                                                        workDataOf(+                                                                "source_paths" to+                                                                        selectedPaths+                                                                                .map {+                                                                                    it.toString()+                                                                                }+                                                                                .toTypedArray(),+                                                                "dest_path" to destPath.toString()+                                                        )+                                                )+                                                .build()+                                WorkManager.getInstance(context).enqueue(zipWork)+                                selectedPaths = emptySet()+                                pathBeingRenamed = null+                                showArchiveDialog = false+                                scope.launch {+                                    snackbarHostState.showSnackbar(+                                            context.getString(R.string.archiving_started)+                                    )+                                }+                            }+                    ) { Text(stringResource(R.string.archive)) }+                },+                dismissButton = {+                    TextButton(onClick = { showArchiveDialog = false }) {+                        Text(stringResource(R.string.cancel))                     }-                }) {-                    Text(stringResource(R.string.archive))                 }-            },-            dismissButton = {-                TextButton(onClick = { showArchiveDialog = false }) {-                    Text(stringResource(R.string.cancel))-                }-            }         )     } -    val zipToUnzip = remember(selectedPaths) {-        if (selectedPaths.size == 1 && !selectedPaths.first().isDirectory(currentFileSystem) && selectedPaths.first().name.endsWith(".zip", ignoreCase = true)) {-            selectedPaths.first()-        } else null-    }+    val zipToUnzip =+            remember(selectedPaths) {+                if (selectedPaths.size == 1 &&+                                !selectedPaths.first().isDirectory(currentFileSystem) &&+                                selectedPaths.first().name.endsWith(".zip", ignoreCase = true)+                ) {+                    selectedPaths.first()+                } else null+            } -    val treeLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->-        if (uri != null && zipToUnzip != null) {-            val path = uri.path?.split(":")?.lastOrNull()?.let {-                Environment.getExternalStorageDirectory().resolve(it).toOkioPath()-            } ?: currentDirectory+    val treeLauncher =+            rememberLauncherForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->+                if (uri != null && zipToUnzip != null) {+                    val path =+                            uri.path?.split(":")?.lastOrNull()?.let {+                                Environment.getExternalStorageDirectory().resolve(it).toOkioPath()+                            }+                                    ?: currentDirectory -            val unzipWork = OneTimeWorkRequestBuilder<UnzipWorker>()-                .setInputData(workDataOf(-                    "zip_path" to zipToUnzip.toString(),-                    "dest_path" to path.toString()-                ))-                .build()-            WorkManager.getInstance(context).enqueue(unzipWork)+                    val unzipWork =+                            OneTimeWorkRequestBuilder<UnzipWorker>()+                                    .setInputData(+                                            workDataOf(+                                                    "zip_path" to zipToUnzip.toString(),+                                                    "dest_path" to path.toString()+                                            )+                                    )+                                    .build()+                    WorkManager.getInstance(context).enqueue(unzipWork) -            selectedPaths = emptySet()-            scope.launch {-                snackbarHostState.showSnackbar(context.getString(R.string.unzipping_started_to, path.name))+                    selectedPaths = emptySet()+                    scope.launch {+                        snackbarHostState.showSnackbar(+                                context.getString(R.string.unzipping_started_to, path.name)+                        )+                    }+                }             }-        }-    }      // Data state-    var filesList by remember(currentDirectory, currentFileSystem) {-        mutableStateOf(currentDirectory.listFiles(currentFileSystem).partition { it.isDirectory(currentFileSystem) })-    }+    var filesList by+            remember(currentDirectory, currentFileSystem) {+                mutableStateOf(+                        currentDirectory.listFiles(currentFileSystem).partition {+                            it.isDirectory(currentFileSystem)+                        }+                )+            }      fun forceRefresh() {-        filesList = currentDirectory.listFiles(currentFileSystem).partition { it.isDirectory(currentFileSystem) }+        filesList =+                currentDirectory.listFiles(currentFileSystem).partition {+                    it.isDirectory(currentFileSystem)+                }     }      LaunchedEffect(currentDirectory, currentFileSystem) {         if (currentFileSystem == fs) {-            val observer = object : FileObserver(currentDirectory.toFile(), FileObserver.CREATE or FileObserver.DELETE or FileObserver.MOVED_FROM or FileObserver.MOVED_TO) {-                override fun onEvent(event: Int, path: String?) {-                    forceRefresh()-                }-            }+            val observer =+                    object :+                            FileObserver(+                                    currentDirectory.toFile(),+                                    FileObserver.CREATE or+                                            FileObserver.DELETE or+                                            FileObserver.MOVED_FROM or+                                            FileObserver.MOVED_TO+                            ) {+                        override fun onEvent(event: Int, path: String?) {+                            forceRefresh()+                        }+                    }             observer.startWatching()             try {                 awaitCancellation()@@ -329,37 +423,44 @@ fun DirectoryPage(rootFile: Path) {     val focusManager = LocalFocusManager.current      val root = remember { Environment.getExternalStorageDirectory().toOkioPath() }-    -    val breadcrumbs = remember(currentDirectory, zipPath, currentFileSystem) {-        if (zipPath == null) {-            val list = mutableListOf<Path>()-            var temp: Path? = currentDirectory-            while (temp != null) {-                list.add(0, temp)-                if (temp == root) break-                temp = temp.parent-            }-            list.map { Triple(it, fs, if (it == root) Build.MODEL else it.name) }-        } else {-            val systemList = mutableListOf<Path>()-            var tempSystem: Path? = zipPath?.parent-            while (tempSystem != null) {-                systemList.add(0, tempSystem)-                if (tempSystem == root) break-                tempSystem = tempSystem.parent-            }-            -            val zipList = mutableListOf<Path>()-            var tempZip: Path? = currentDirectory-            while (tempZip != null) {-                zipList.add(0, tempZip)-                tempZip = tempZip.parent++    val breadcrumbs =+            remember(currentDirectory, zipPath, currentFileSystem) {+                if (zipPath == null) {+                    val list = mutableListOf<Path>()+                    var temp: Path? = currentDirectory+                    while (temp != null) {+                        list.add(0, temp)+                        if (temp == root) break+                        temp = temp.parent+                    }+                    list.map { Triple(it, fs, if (it == root) Build.MODEL else it.name) }+                } else {+                    val systemList = mutableListOf<Path>()+                    var tempSystem: Path? = zipPath?.parent+                    while (tempSystem != null) {+                        systemList.add(0, tempSystem)+                        if (tempSystem == root) break+                        tempSystem = tempSystem.parent+                    }++                    val zipList = mutableListOf<Path>()+                    var tempZip: Path? = currentDirectory+                    while (tempZip != null) {+                        zipList.add(0, tempZip)+                        tempZip = tempZip.parent+                    }++                    systemList.map { Triple(it, fs, if (it == root) Build.MODEL else it.name) } ++                            zipList.map {+                                Triple(+                                        it,+                                        currentFileSystem,+                                        if (it.name.isEmpty()) zipPath!!.name else it.name+                                )+                            }+                }             }-            -            systemList.map { Triple(it, fs, if (it == root) Build.MODEL else it.name) } +-            zipList.map { Triple(it, currentFileSystem, if (it.name.isEmpty()) zipPath!!.name else it.name) }-        }-    }      BackHandler(currentDirectory != root || selectedPaths.isNotEmpty() || zipPath != null) {         if (selectedPaths.isNotEmpty()) {@@ -379,244 +480,384 @@ fun DirectoryPage(rootFile: Path) {     }      Scaffold(-        modifier = Modifier-            .imePadding()-            .clickable(interactionSource = remember { MutableInteractionSource() }, indication = null) {-                focusManager.clearFocus()-                pathBeingRenamed = null-                selectedPaths = emptySet()-            },-        snackbarHost = { SnackbarHost(snackbarHostState) },-        topBar = {-            TopAppBar(-                title = {-                    Row(-                        verticalAlignment = Alignment.CenterVertically,-                        modifier = Modifier.horizontalScroll(rememberScrollState())-                    ) {-                        breadcrumbs.forEachIndexed { index, (path, fileSystem, displayName) ->-                            var isBreadcrumbDraggingOver by remember { mutableStateOf(false) }--                            Box(-                                modifier = Modifier-                                    .background(-                                        if (isBreadcrumbDraggingOver) MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f)-                                        else Color.Transparent,-                                        shape = MaterialTheme.shapes.small-                                    )-                                    .dragAndDropTarget(-                                        shouldStartDragAndDrop = { event ->-                                            !isReadOnly && event.mimeTypes().contains(ClipDescription.MIMETYPE_TEXT_PLAIN)-                                        },-                                        target = remember(path, fileSystem) {-                                            object : DragAndDropTarget {-                                                override fun onDrop(event: DragAndDropEvent): Boolean {-                                                    isBreadcrumbDraggingOver = false-                                                    val dragEvent = event.toAndroidDragEvent()-                                                    val clipData = dragEvent.clipData-                                                    if (clipData != null && clipData.itemCount > 0) {-                                                        val sources = (0 until clipData.itemCount).map {-                                                            clipData.getItemAt(it).text.toString().toPath()-                                                        }-                                                        var movedAny = false-                                                        sources.forEach { sourcePath ->-                                                            if (sourcePath.parent != path && sourcePath != path) {-                                                                try {-                                                                    fs.atomicMove(sourcePath, path.resolve(sourcePath.name))-                                                                    movedAny = true-                                                                } catch (e: Exception) {-                                                                    scope.launch {-                                                                        snackbarHostState.showSnackbar(context.getString(R.string.move_failed, e.localizedMessage))-                                                                    }-                                                                }+            modifier =+                    Modifier.imePadding().clickable(+                                    interactionSource = remember { MutableInteractionSource() },+                                    indication = null+                            ) {+                        focusManager.clearFocus()+                        pathBeingRenamed = null+                        selectedPaths = emptySet()+                    },+            snackbarHost = { SnackbarHost(snackbarHostState) },+            topBar = {+                TopAppBar(+                        title = {+                            Row(+                                    verticalAlignment = Alignment.CenterVertically,+                                    modifier = Modifier.horizontalScroll(rememberScrollState())+                            ) {+                                breadcrumbs.forEachIndexed { index, (path, fileSystem, displayName)+                                    ->+                                    var isBreadcrumbDraggingOver by remember {+                                        mutableStateOf(false)+                                    }++                                    Box(+                                            modifier =+                                                    Modifier.background(+                                                                    if (isBreadcrumbDraggingOver)+                                                                            MaterialTheme+                                                                                    .colorScheme+                                                                                    .primaryContainer+                                                                                    .copy(+                                                                                            alpha =+                                                                                                    0.5f+                                                                                    )+                                                                    else Color.Transparent,+                                                                    shape =+                                                                            MaterialTheme.shapes+                                                                                    .small+                                                            )+                                                            .dragAndDropTarget(+                                                                    shouldStartDragAndDrop = { event+                                                                        ->+                                                                        !isReadOnly &&+                                                                                event.mimeTypes()+                                                                                        .contains(+                                                                                                ClipDescription+                                                                                                        .MIMETYPE_TEXT_PLAIN+                                                                                        )+                                                                    },+                                                                    target =+                                                                            remember(+                                                                                    path,+                                                                                    fileSystem+                                                                            ) {+                                                                                object :+                                                                                        DragAndDropTarget {+                                                                                    override fun onDrop(+                                                                                            event:+                                                                                                    DragAndDropEvent+                                                                                    ): Boolean {+                                                                                        isBreadcrumbDraggingOver =+                                                                                                false+                                                                                        val dragEvent =+                                                                                                event.toAndroidDragEvent()+                                                                                        val clipData =+                                                                                                dragEvent+                                                                                                        .clipData+                                                                                        if (clipData !=+                                                                                                        null &&+                                                                                                        clipData.itemCount >+                                                                                                                0+                                                                                        ) {+                                                                                            val sources =+                                                                                                    (0 until+                                                                                                                    clipData.itemCount)+                                                                                                            .map {+                                                                                                                clipData.getItemAt(+                                                                                                                                it+                                                                                                                        )+                                                                                                                        .text+                                                                                                                        .toString()+                                                                                                                        .toPath()+                                                                                                            }+                                                                                            var movedAny =+                                                                                                    false+                                                                                            sources+                                                                                                    .forEach {+                                                                                                            sourcePath+                                                                                                        ->+                                                                                                        if (sourcePath+                                                                                                                        .parent !=+                                                                                                                        path &&+                                                                                                                        sourcePath !=+                                                                                                                                path+                                                                                                        ) {+                                                                                                            try {+                                                                                                                fs.atomicMove(+                                                                                                                        sourcePath,+                                                                                                                        path.resolve(+                                                                                                                                sourcePath+                                                                                                                                        .name+                                                                                                                        )+                                                                                                                )+                                                                                                                movedAny =+                                                                                                                        true+                                                                                                            } catch (+                                                                                                                    e:+                                                                                                                            Exception) {+                                                                                                                scope+                                                                                                                        .launch {+                                                                                                                            snackbarHostState+                                                                                                                                    .showSnackbar(+                                                                                                                                            context.getString(+                                                                                                                                                    R.string+                                                                                                                                                            .move_failed,+                                                                                                                                                    e.localizedMessage+                                                                                                                                            )+                                                                                                                                    )+                                                                                                                        }+                                                                                                            }+                                                                                                        }+                                                                                                    }+                                                                                            if (movedAny+                                                                                            ) {+                                                                                                forceRefresh()+                                                                                                selectedPaths =+                                                                                                        emptySet()+                                                                                                pathBeingRenamed =+                                                                                                        null+                                                                                                return true+                                                                                            }+                                                                                        }+                                                                                        return false+                                                                                    }+                                                                                    override fun onEntered(+                                                                                            event:+                                                                                                    DragAndDropEvent+                                                                                    ) {+                                                                                        isBreadcrumbDraggingOver =+                                                                                                true+                                                                                    }+                                                                                    override fun onExited(+                                                                                            event:+                                                                                                    DragAndDropEvent+                                                                                    ) {+                                                                                        isBreadcrumbDraggingOver =+                                                                                                false+                                                                                    }+                                                                                    override fun onEnded(+                                                                                            event:+                                                                                                    DragAndDropEvent+                                                                                    ) {+                                                                                        isBreadcrumbDraggingOver =+                                                                                                false+                                                                                    }+                                                                                }+                                                                            }+                                                            )+                                                            .clickable {+                                                                currentFileSystem = fileSystem+                                                                currentDirectory = path+                                                                if (fileSystem == fs) zipPath = null                                                             }-                                                        }-                                                        if (movedAny) {-                                                            forceRefresh()-                                                            selectedPaths = emptySet()-                                                            pathBeingRenamed = null-                                                            return true-                                                        }-                                                    }-                                                    return false-                                                }-                                                override fun onEntered(event: DragAndDropEvent) {-                                                    isBreadcrumbDraggingOver = true-                                                }-                                                override fun onExited(event: DragAndDropEvent) {-                                                    isBreadcrumbDraggingOver = false-                                                }-                                                override fun onEnded(event: DragAndDropEvent) {-                                                    isBreadcrumbDraggingOver = false-                                                }-                                            }-                                        }-                                    )-                                    .clickable {-                                        currentFileSystem = fileSystem-                                        currentDirectory = path-                                        if (fileSystem == fs) zipPath = null+                                                            .padding(4.dp)+                                    ) {+                                        Text(+                                                text = displayName,+                                                style = MaterialTheme.typography.titleLarge+                                        )                                     }-                                    .padding(4.dp)-                            ) {-                                Text(-                                    text = displayName,-                                    style = MaterialTheme.typography.titleLarge-                                )-                            }-                            if (index < breadcrumbs.size - 1) {-                                IconChevronRight(-                                    tint = MaterialTheme.colorScheme.outline-                                )-                            }-                        }-                    }-                },-                actions = {-                    if (selectedPaths.isNotEmpty()) {-                        IconButton(onClick = {-                            selectedPaths = emptySet()-                            pathBeingRenamed = null-                        }) {-                            IconClose()-                        }-                    }-                    if (!isReadOnly) {-                        if (selectedPaths.isNotEmpty()) {-                            IconButton(onClick = {-                                archiveName = if (selectedPaths.size == 1) "${selectedPaths.first().name}.zip" else "archive.zip"-                                showArchiveDialog = true-                            }) {-                                IconArchive()+                                    if (index < breadcrumbs.size - 1) {+                                        IconChevronRight(tint = MaterialTheme.colorScheme.outline)+                                    }+                                }                             }-                        }-                        if (zipToUnzip != null) {-                            IconButton(onClick = { treeLauncher.launch(null) }) {-                                IconUnarchive()+                        },+                        actions = {+                            if (selectedPaths.isNotEmpty()) {+                                IconButton(+                                        onClick = {+                                            selectedPaths = emptySet()+                                            pathBeingRenamed = null+                                        }+                                ) { IconClose() }                             }-                        }-                        // Show Rename Button if exactly 1 is selected-                        if (selectedPaths.size == 1) {-                            IconButton(onClick = { pathBeingRenamed = selectedPaths.first() }) {-                                IconEdit()+                            if (incomingUris != null && !isReadOnly) {+                                IconButton(+                                        onClick = {+                                            scope.launch {+                                                incomingUris.forEach { uri ->+                                                    saveUriToPath(context, uri, currentDirectory)+                                                }+                                                onClearIncoming()+                                                forceRefresh()+                                                snackbarHostState.showSnackbar(+                                                        context.getString(R.string.files_saved)+                                                )+                                            }+                                        }+                                ) { IconSave() }                             }-                        }-                        // Delete Button-                        if (selectedPaths.isNotEmpty()) {-                            IconButton(onClick = {-                                selectedPaths.forEach { it.deleteRecursively(currentFileSystem) }-                                selectedPaths = emptySet()-                                pathBeingRenamed = null-                                forceRefresh()-                            }) {-                                IconDelete()+                            if (!isReadOnly) {+                                if (selectedPaths.isNotEmpty()) {+                                    IconButton(+                                            onClick = {+                                                archiveName =+                                                        if (selectedPaths.size == 1)+                                                                "${selectedPaths.first().name}.zip"+                                                        else "archive.zip"+                                                showArchiveDialog = true+                                            }+                                    ) { IconArchive() }+                                }+                                if (zipToUnzip != null) {+                                    IconButton(onClick = { treeLauncher.launch(null) }) {+                                        IconUnarchive()+                                    }+                                }+                                // Show Rename Button if exactly 1 is selected+                                if (selectedPaths.size == 1) {+                                    IconButton(+                                            onClick = { pathBeingRenamed = selectedPaths.first() }+                                    ) { IconEdit() }+                                }+                                // Delete Button+                                if (selectedPaths.isNotEmpty()) {+                                    IconButton(+                                            onClick = {+                                                selectedPaths.forEach {+                                                    it.deleteRecursively(currentFileSystem)+                                                }+                                                selectedPaths = emptySet()+                                                pathBeingRenamed = null+                                                forceRefresh()+                                            }+                                    ) { IconDelete() }+                                }                             }                         }-                    }-                }-            )-        }+                )+            }     ) { padding ->         LazyColumn(Modifier.padding(padding)) {-            val allItems = directories.sortedBy { it.name.lowercase() } + files.sortedBy { it.name.lowercase() }+            val allItems =+                    directories.sortedBy { it.name.lowercase() } ++                            files.sortedBy { it.name.lowercase() }              items(allItems, key = { it.toString() }) { child ->                 val isSelected = selectedPaths.contains(child)                 val isEditing = pathBeingRenamed == child                  DirectoryItem(-                    file = child,-                    isEditing = isEditing,-                    isSelected = isSelected,-                    fileSystem = currentFileSystem,-                    isReadOnly = isReadOnly,-                    onRename = { newName ->-                        currentFileSystem.atomicMove(child, child.parent!!.resolve(newName))-                        forceRefresh()-                        pathBeingRenamed = null-                        selectedPaths = emptySet()-                    },-                    onToggleSelection = {-                        if (isReadOnly) return@DirectoryItem-                        if(pathBeingRenamed != null) pathBeingRenamed = null-                        if (!isSelected) {-                            selectedPaths = selectedPaths + child-                        }-                    },-                    onClick = {-                        if (selectedPaths.isNotEmpty()) {-                            if (isSelected && pathBeingRenamed == child) {-                                pathBeingRenamed = null+                        file = child,+                        isEditing = isEditing,+                        isSelected = isSelected,+                        fileSystem = currentFileSystem,+                        isReadOnly = isReadOnly,+                        onRename = { newName ->+                            currentFileSystem.atomicMove(child, child.parent!!.resolve(newName))+                            forceRefresh()+                            pathBeingRenamed = null+                            selectedPaths = emptySet()+                        },+                        onToggleSelection = {+                            if (isReadOnly) return@DirectoryItem+                            if (pathBeingRenamed != null) pathBeingRenamed = null+                            if (!isSelected) {+                                selectedPaths = selectedPaths + child                             }-                            selectedPaths = if (isSelected) selectedPaths - child-                            else selectedPaths + child-                        } else if (child.isDirectory(currentFileSystem)) {-                            currentDirectory = child-                        } else if (child.name.endsWith(".zip", ignoreCase = true)) {-                            try {-                                val zipFs = currentFileSystem.openZip(child)-                                currentFileSystem = zipFs-                                zipPath = if (zipPath == null) child else zipPath-                                currentDirectory = "/".toPath()-                            } catch (e: Exception) {-                                scope.launch {-                                    snackbarHostState.showSnackbar(context.getString(R.string.could_not_open_zip, e.localizedMessage))+                        },+                        onClick = {+                            if (selectedPaths.isNotEmpty()) {+                                if (isSelected && pathBeingRenamed == child) {+                                    pathBeingRenamed = null                                 }-                            }-                        } else if (currentFileSystem == fs) {-                            val file = child.toFile()-                            val extension = file.extension-                            val mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) ?: "*/*"--                            val intent = Intent(Intent.ACTION_VIEW).apply {-                                val uri = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)-                                setDataAndType(uri, mimeType)-                                flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION-                            }-                            try {-                                context.startActivity(intent)-                            } catch (e: Exception) {+                                selectedPaths =+                                        if (isSelected) selectedPaths - child+                                        else selectedPaths + child+                            } else if (child.isDirectory(currentFileSystem)) {+                                currentDirectory = child+                            } else if (child.name.endsWith(".zip", ignoreCase = true)) {+                                try {+                                    val zipFs = currentFileSystem.openZip(child)+                                    currentFileSystem = zipFs+                                    zipPath = if (zipPath == null) child else zipPath+                                    currentDirectory = "/".toPath()+                                } catch (e: Exception) {+                                    scope.launch {+                                        snackbarHostState.showSnackbar(+                                                context.getString(+                                                        R.string.could_not_open_zip,+                                                        e.localizedMessage+                                                )+                                        )+                                    }+                                }+                            } else if (currentFileSystem == fs) {+                                val file = child.toFile()+                                val extension = file.extension+                                val mimeType =+                                        MimeTypeMap.getSingleton()+                                                .getMimeTypeFromExtension(extension)+                                                ?: "*/*"++                                val intent =+                                        Intent(Intent.ACTION_VIEW).apply {+                                            val uri =+                                                    FileProvider.getUriForFile(+                                                            context,+                                                            "${context.packageName}.fileprovider",+                                                            file+                                                    )+                                            setDataAndType(uri, mimeType)+                                            flags =+                                                    Intent.FLAG_ACTIVITY_NEW_TASK or+                                                            Intent.FLAG_GRANT_READ_URI_PERMISSION or+                                                            Intent.FLAG_GRANT_WRITE_URI_PERMISSION+                                        }+                                try {+                                    context.startActivity(intent)+                                } catch (e: Exception) {+                                    scope.launch {+                                        snackbarHostState.showSnackbar(+                                                context.getString(+                                                        R.string.no_app_found_to_open_file+                                                )+                                        )+                                    }+                                }+                            } else {                                 scope.launch {-                                    snackbarHostState.showSnackbar(context.getString(R.string.no_app_found_to_open_file))+                                    snackbarHostState.showSnackbar(+                                            context.getString(R.string.zip_browse_only)+                                    )                                 }                             }-                        } else {-                            scope.launch {-                                snackbarHostState.showSnackbar(context.getString(R.string.zip_browse_only))-                            }-                        }-                    },-                    onMove = { sources ->-                        if (!isReadOnly && child.isDirectory(currentFileSystem)) {-                            var movedAny = false-                            sources.forEach { source ->-                                if (source != child && !child.toString().startsWith(source.toString())) {-                                    try {-                                        currentFileSystem.atomicMove(source, child.resolve(source.name))-                                        movedAny = true-                                    } catch (e: Exception) {-                                        scope.launch {-                                            snackbarHostState.showSnackbar(context.getString(R.string.move_failed, e.localizedMessage))+                        },+                        onMove = { sources ->+                            if (!isReadOnly && child.isDirectory(currentFileSystem)) {+                                var movedAny = false+                                sources.forEach { source ->+                                    if (source != child &&+                                                    !child.toString().startsWith(source.toString())+                                    ) {+                                        try {+                                            currentFileSystem.atomicMove(+                                                    source,+                                                    child.resolve(source.name)+                                            )+                                            movedAny = true+                                        } catch (e: Exception) {+                                            scope.launch {+                                                snackbarHostState.showSnackbar(+                                                        context.getString(+                                                                R.string.move_failed,+                                                                e.localizedMessage+                                                        )+                                                )+                                            }                                         }                                     }                                 }+                                if (movedAny) {+                                    forceRefresh()+                                    selectedPaths = emptySet()+                                    pathBeingRenamed = null+                                }                             }-                            if (movedAny) {-                                forceRefresh()-                                selectedPaths = emptySet()-                                pathBeingRenamed = null-                            }+                        },+                        onStartDrag = {+                            if (isReadOnly) emptyList()+                            else if (selectedPaths.contains(child)) selectedPaths.toList()+                            else listOf(child)                         }-                    },-                    onStartDrag = {-                        if (isReadOnly) emptyList()-                        else if (selectedPaths.contains(child)) selectedPaths.toList()-                        else listOf(child)-                    }                 )                 HorizontalDivider(-                    thickness = 0.5.dp,-                    color = MaterialTheme.colorScheme.outlineVariant+                        thickness = 0.5.dp,+                        color = MaterialTheme.colorScheme.outlineVariant                 )             }         }@@ -626,16 +867,16 @@ fun DirectoryPage(rootFile: Path) { @OptIn(ExperimentalFoundationApi::class) @Composable fun DirectoryItem(-    file: Path,-    isEditing: Boolean,-    isSelected: Boolean,-    fileSystem: FileSystem,-    isReadOnly: Boolean,-    onRename: (String) -> Unit,-    onToggleSelection: () -> Unit,-    onClick: () -> Unit,-    onMove: (List<Path>) -> Unit,-    onStartDrag: () -> List<Path>+        file: Path,+        isEditing: Boolean,+        isSelected: Boolean,+        fileSystem: FileSystem,+        isReadOnly: Boolean,+        onRename: (String) -> Unit,+        onToggleSelection: () -> Unit,+        onClick: () -> Unit,+        onMove: (List<Path>) -> Unit,+        onStartDrag: () -> List<Path> ) {     var editedName by remember(isEditing) { mutableStateOf(file.name) }     val focusRequester = remember { FocusRequester() }@@ -644,120 +885,198 @@ fun DirectoryItem(     val currentOnMove by rememberUpdatedState(onMove)     val currentOnStartDrag by rememberUpdatedState(onStartDrag) +    val context = LocalContext.current     Box(-        modifier = Modifier-            .fillMaxWidth()-            .background(-                if (isDraggingOver) MaterialTheme.colorScheme.primaryContainer-                else if (isSelected) MaterialTheme.colorScheme.surfaceVariant-                else Color.Transparent-            )-            .dragAndDropSource(-                block = {-                    detectDragGesturesAfterLongPress(-                        onDragStart = {-                            if (isReadOnly) return@detectDragGesturesAfterLongPress-                            val paths = currentOnStartDrag()-                            if (paths.isEmpty()) return@detectDragGesturesAfterLongPress-                            val clipData = ClipData.newPlainText("path", paths.first().toString())-                            for (i in 1 until paths.size) {-                                clipData.addItem(ClipData.Item(paths[i].toString()))-                            }--                            startTransfer(-                                DragAndDropTransferData(-                                    clipData = clipData,-                                    flags = View.DRAG_FLAG_GLOBAL-                                )+            modifier =+                    Modifier.fillMaxWidth()+                            .background(+                                    if (isDraggingOver) MaterialTheme.colorScheme.primaryContainer+                                    else if (isSelected) MaterialTheme.colorScheme.surfaceVariant+                                    else Color.Transparent                             )-                        },-                        onDrag = { _, _ -> },-                        onDragEnd = { },-                        onDragCancel = { }-                    )-                }-            )-            .then(-                if (file.isDirectory(fileSystem) && !isReadOnly) {-                    Modifier.dragAndDropTarget(-                        shouldStartDragAndDrop = { event ->-                            event.mimeTypes().contains(ClipDescription.MIMETYPE_TEXT_PLAIN)-                        },-                        target = remember(file) {-                            object : DragAndDropTarget {-                                override fun onDrop(event: DragAndDropEvent): Boolean {-                                    isDraggingOver = false-                                    val dragEvent = event.toAndroidDragEvent()-                                    val clipData = dragEvent.clipData-                                    if (clipData != null && clipData.itemCount > 0) {-                                        val sources = (0 until clipData.itemCount).map {-                                            clipData.getItemAt(it).text.toString().toPath()-                                        }-                                        currentOnMove(sources)-                                        return true+                            .dragAndDropSource(+                                    block = {+                                        detectDragGesturesAfterLongPress(+                                                onDragStart = {+                                                    val paths = currentOnStartDrag()+                                                    if (paths.isEmpty())+                                                            return@detectDragGesturesAfterLongPress++                                                    val uris =+                                                            paths.map { path ->+                                                                FileProvider.getUriForFile(+                                                                        context,+                                                                        "${context.packageName}.fileprovider",+                                                                        path.toFile()+                                                                )+                                                            }+                                                    val mimeTypes =+                                                            paths.map { path ->+                                                                        val extension =+                                                                                path.name+                                                                                        .substringAfterLast(+                                                                                                '.',+                                                                                                ""+                                                                                        )+                                                                        if (extension == "md")+                                                                                "text/markdown"+                                                                        else+                                                                                MimeTypeMap.getSingleton()+                                                                                        .getMimeTypeFromExtension(+                                                                                                extension+                                                                                        ) ?: "*/*"+                                                                    }+                                                                    .toMutableList()+                                                                    .apply {+                                                                        add(+                                                                                ClipDescription+                                                                                        .MIMETYPE_TEXT_PLAIN+                                                                        )+                                                                    }+                                                                    .distinct()+                                                                    .toTypedArray()++                                                    val clipData =+                                                            ClipData(+                                                                    paths.first().name,+                                                                    mimeTypes,+                                                                    ClipData.Item(+                                                                            paths.first()+                                                                                    .toString(),+                                                                            null,+                                                                            null,+                                                                            uris.first()+                                                                    )+                                                            )+                                                    for (i in 1 until uris.size) {+                                                        clipData.addItem(+                                                                ClipData.Item(+                                                                        paths[i].toString(),+                                                                        null,+                                                                        null,+                                                                        uris[i]+                                                                )+                                                        )+                                                    }++                                                    startTransfer(+                                                            DragAndDropTransferData(+                                                                    clipData = clipData,+                                                                    flags =+                                                                            View.DRAG_FLAG_GLOBAL or+                                                                                    View+                                                                                            .DRAG_FLAG_GLOBAL_URI_READ+                                                            )+                                                    )+                                                },+                                                onDrag = { _, _ -> },+                                                onDragEnd = {},+                                                onDragCancel = {}+                                        )                                     }-                                    return false-                                }+                            )+                            .then(+                                    if (file.isDirectory(fileSystem) && !isReadOnly) {+                                        Modifier.dragAndDropTarget(+                                                shouldStartDragAndDrop = { event ->+                                                    event.mimeTypes()+                                                            .contains(+                                                                    ClipDescription+                                                                            .MIMETYPE_TEXT_PLAIN+                                                            )+                                                },+                                                target =+                                                        remember(file) {+                                                            object : DragAndDropTarget {+                                                                override fun onDrop(+                                                                        event: DragAndDropEvent+                                                                ): Boolean {+                                                                    isDraggingOver = false+                                                                    val dragEvent =+                                                                            event.toAndroidDragEvent()+                                                                    val clipData =+                                                                            dragEvent.clipData+                                                                    if (clipData != null &&+                                                                                    clipData.itemCount >+                                                                                            0+                                                                    ) {+                                                                        val sources =+                                                                                (0 until+                                                                                                clipData.itemCount)+                                                                                        .map {+                                                                                            clipData.getItemAt(+                                                                                                            it+                                                                                                    )+                                                                                                    .text+                                                                                                    .toString()+                                                                                                    .toPath()+                                                                                        }+                                                                        currentOnMove(sources)+                                                                        return true+                                                                    }+                                                                    return false+                                                                } -                                override fun onEntered(event: DragAndDropEvent) {-                                    isDraggingOver = true-                                }+                                                                override fun onEntered(+                                                                        event: DragAndDropEvent+                                                                ) {+                                                                    isDraggingOver = true+                                                                } -                                override fun onExited(event: DragAndDropEvent) {-                                    isDraggingOver = false-                                }+                                                                override fun onExited(+                                                                        event: DragAndDropEvent+                                                                ) {+                                                                    isDraggingOver = false+                                                                } -                                override fun onEnded(event: DragAndDropEvent) {-                                    isDraggingOver = false-                                }-                            }-                        }-                    )-                } else Modifier-            )-            .combinedClickable(-                onClick = onClick,-                onLongClick = onToggleSelection-            )+                                                                override fun onEnded(+                                                                        event: DragAndDropEvent+                                                                ) {+                                                                    isDraggingOver = false+                                                                }+                                                            }+                                                        }+                                        )+                                    } else Modifier+                            )+                            .combinedClickable(onClick = onClick, onLongClick = onToggleSelection)     ) {         ListItem(-            headlineContent = {-                if (isEditing) {-                    TextField(-                        value = editedName,-                        onValueChange = { editedName = it },-                        modifier = Modifier-                            .focusRequester(focusRequester)-                            .fillMaxWidth(),-                        singleLine = true,-                        keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),-                        keyboardActions = KeyboardActions(onDone = { onRename(editedName) })-                    )-                    LaunchedEffect(Unit) {-                        focusRequester.requestFocus()-                        keyboard?.show()+                headlineContent = {+                    if (isEditing) {+                        TextField(+                                value = editedName,+                                onValueChange = { editedName = it },+                                modifier = Modifier.focusRequester(focusRequester).fillMaxWidth(),+                                singleLine = true,+                                keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),+                                keyboardActions = KeyboardActions(onDone = { onRename(editedName) })+                        )+                        LaunchedEffect(Unit) {+                            focusRequester.requestFocus()+                            keyboard?.show()+                        }+                    } else {+                        Text(file.name.ifEmpty { "/" })                     }-                } else {-                    Text(file.name.ifEmpty { "/" })-                }-            },-            leadingContent = {-                Icon(-                    if (file.isDirectory(fileSystem)) painterResource(R.drawable.folder_24px) else painterResource(R.drawable.docs_24px),-                    contentDescription = null,-                    tint = if (isSelected) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.outline-                )-            },-            supportingContent = {-                if (!file.isDirectory(fileSystem)) {-                    file.size(fileSystem)?.let { size ->-                        Text(byteSizeString(size))+                },+                leadingContent = {+                    Icon(+                            if (file.isDirectory(fileSystem))+                                    painterResource(R.drawable.folder_24px)+                            else painterResource(R.drawable.docs_24px),+                            contentDescription = null,+                            tint =+                                    if (isSelected) MaterialTheme.colorScheme.primary+                                    else MaterialTheme.colorScheme.outline+                    )+                },+                supportingContent = {+                    if (!file.isDirectory(fileSystem)) {+                        file.size(fileSystem)?.let { size -> Text(byteSizeString(size)) }                     }-                }-            },-            colors = ListItemDefaults.colors(-                containerColor = Color.Transparent-            )+                },+                colors = ListItemDefaults.colors(containerColor = Color.Transparent)         )     } }@@ -766,10 +1085,34 @@ fun byteSizeString(bytes: Long): String {     val units = arrayOf("B", "KB", "MB", "GB", "TB")     var unitIdx = 0     var bytesS = bytes.toDouble()-    while(bytesS >= 1024) {+    while (bytesS >= 1024) {         bytesS /= 1024         unitIdx++     }-    bytesS = (bytesS*100).roundToLong()/100.0+    bytesS = (bytesS * 100).roundToLong() / 100.0     return "$bytesS ${units[unitIdx]}" }++private fun saveUriToPath(context: Context, uri: Uri, targetDir: Path) {+    val name =+            getFileName(context.contentResolver, uri)+                    ?: "shared_file_${System.currentTimeMillis()}"+    val targetPath = targetDir.resolve(name)+    context.contentResolver.openInputStream(uri)?.use { input ->+        fs.write(targetPath) { writeAll(input.source()) }+    }+}++private fun getFileName(contentResolver: ContentResolver, uri: Uri): String? {+    if (uri.scheme == "content") {+        contentResolver.query(uri, null, null, null, null)?.use { cursor ->+            if (cursor.moveToFirst()) {+                val nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)+                if (nameIndex != -1) {+                    return cursor.getString(nameIndex)+                }+            }+        }+    }+    return uri.path?.substringAfterLast('/')+}
files/src/main/res/values/strings.xml
diff --git a/files/src/main/res/values/strings.xml b/files/src/main/res/values/strings.xmlindex 95dd47e48e..738953c7a5 100644--- a/files/src/main/res/values/strings.xml+++ b/files/src/main/res/values/strings.xml@@ -20,4 +20,5 @@     <string name="unzipping">Unzipping...</string>     <string name="zip_channel_name">Zip Operations</string>     <string name="archiving">Archiving...</string>+    <string name="files_saved">Files saved successfully</string> </resources>\ No newline at end of file
library/src/main/java/com/vayunmathur/library/util/FileDropModifier.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/FileDropModifier.kt b/library/src/main/java/com/vayunmathur/library/util/FileDropModifier.ktindex 632781600c..7a29b6b1eb 100644--- a/library/src/main/java/com/vayunmathur/library/util/FileDropModifier.kt+++ b/library/src/main/java/com/vayunmathur/library/util/FileDropModifier.kt@@ -1,35 +1,63 @@ package com.vayunmathur.library.util +import android.app.Activity+import android.content.Context+import android.content.ContextWrapper import android.net.Uri import androidx.compose.foundation.draganddrop.dragAndDropTarget+import androidx.compose.runtime.remember import androidx.compose.ui.Modifier+import androidx.compose.ui.composed import androidx.compose.ui.draganddrop.DragAndDropEvent import androidx.compose.ui.draganddrop.DragAndDropTarget+import androidx.compose.ui.draganddrop.mimeTypes import androidx.compose.ui.draganddrop.toAndroidDragEvent+import androidx.compose.ui.platform.LocalContext++/**+ * A helper to find the Activity from a Context.+ */+private fun Context.findActivity(): Activity? {+    var context = this+    while (context is ContextWrapper) {+        if (context is Activity) return context+        context = context.baseContext+    }+    return null+}  /**  * A modifier that handles external drag and drop of files.  */ fun Modifier.onFileDrop(     onFilesDropped: (List<Uri>) -> Unit-): Modifier = this.dragAndDropTarget(-    shouldHandleDragAndDrop = { event ->-        val dragEvent = event.toAndroidDragEvent()-        dragEvent.clipData != null-    },-    target = object : DragAndDropTarget {-        override fun onDrop(event: DragAndDropEvent): Boolean {-            val dragEvent = event.toAndroidDragEvent()-            val clipData = dragEvent.clipData ?: return false-            val uris = mutableListOf<Uri>()-            for (i in 0 until clipData.itemCount) {-                clipData.getItemAt(i).uri?.let { uris.add(it) }-            }-            if (uris.isNotEmpty()) {-                onFilesDropped(uris)-                return true+): Modifier = this.composed {+    val context = LocalContext.current+    remember(context, onFilesDropped) {+        this.dragAndDropTarget(+            shouldStartDragAndDrop = { event ->+                event.mimeTypes().isNotEmpty()+            },+            target = object : DragAndDropTarget {+                override fun onDrop(event: DragAndDropEvent): Boolean {+                    val dragEvent = event.toAndroidDragEvent()+                    val activity = context.findActivity()+                    +                    // Request permissions for cross-app drag and drop URIs+                    activity?.requestDragAndDropPermissions(dragEvent)++                    val clipData = dragEvent.clipData ?: return false+                    val uris = mutableListOf<Uri>()+                    for (i in 0 until clipData.itemCount) {+                        clipData.getItemAt(i).uri?.let { uris.add(it) }+                    }+                    if (uris.isNotEmpty()) {+                        onFilesDropped(uris)+                        return true+                    }+                    return false+                }             }-            return false-        }+        )     }-)+}
library/src/main/java/com/vayunmathur/library/util/IntentHelper.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/IntentHelper.kt b/library/src/main/java/com/vayunmathur/library/util/IntentHelper.ktindex bec8d86952..8f81c81b55 100644--- a/library/src/main/java/com/vayunmathur/library/util/IntentHelper.kt+++ b/library/src/main/java/com/vayunmathur/library/util/IntentHelper.kt@@ -1,7 +1,9 @@ package com.vayunmathur.library.util +import android.content.Context import android.content.Intent import android.net.Uri+import android.provider.OpenableColumns  object IntentHelper {     /**@@ -20,4 +22,34 @@ object IntentHelper {                 intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)?.let { uris.addAll(it) }             }         }+        return uris+    } +    /**+     * Resolves the display name for a given URI.+     */+    fun getFileName(context: Context, uri: Uri): String? {+        var result: String? = null+        if (uri.scheme == "content") {+            val cursor = context.contentResolver.query(uri, null, null, null, null)+            try {+                if (cursor != null && cursor.moveToFirst()) {+                    val index = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)+                    if (index != -1) {+                        result = cursor.getString(index)+                    }+                }+            } finally {+                cursor?.close()+            }+        }+        if (result == null) {+            result = uri.path+            val cut = result?.lastIndexOf('/') ?: -1+            if (cut != -1) {+                result = result?.substring(cut + 1)+            }+        }+        return result+    }+}
notes/src/main/AndroidManifest.xml
diff --git a/notes/src/main/AndroidManifest.xml b/notes/src/main/AndroidManifest.xmlindex 13b83ef253..00d49687ad 100644--- a/notes/src/main/AndroidManifest.xml+++ b/notes/src/main/AndroidManifest.xml@@ -18,7 +18,10 @@             android:name=".MainActivity"             android:exported="true"             android:theme="@style/Theme.General">-+            <intent-filter>+                <action android:name="android.intent.action.MAIN" />+                <category android:name="android.intent.category.LAUNCHER" />+            </intent-filter>         </activity>          <activity