diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt index 4308519c..c38f499e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt @@ -330,10 +330,10 @@ class ItemsAdapter( if (activity.getIsPathDirectory(path)) { val shouldShowHidden = activity.config.shouldShowHidden when { - activity.isRestrictedAndroidDir(path) -> { - activity.getStorageItemsWithTreeUri(path, shouldShowHidden, false) { files -> + activity.isRestrictedSAFOnlyRoot(path) -> { + activity.getAndroidSAFFileItems(path, shouldShowHidden, false) { files -> files.forEach { - addFileUris(activity.getPrimaryAndroidSAFUri(it.path).toString(), paths) + addFileUris(activity.getAndroidSAFUri(it.path).toString(), paths) } } } @@ -403,7 +403,7 @@ class ItemsAdapter( if (!isCopyOperation) { files.forEach { sourceFileDir -> val sourcePath = sourceFileDir.path - if (activity.isRestrictedAndroidDir(sourcePath) && activity.getDoesFilePathExist(sourcePath)) { + if (activity.isRestrictedSAFOnlyRoot(sourcePath) && activity.getDoesFilePathExist(sourcePath)) { activity.deleteFile(sourceFileDir, true) { listener?.refreshFragment() activity.runOnUiThread { @@ -521,8 +521,7 @@ class ItemsAdapter( private fun tryDecompressingPaths(sourcePaths: List, callback: (success: Boolean) -> Unit) { sourcePaths.forEach { path -> - val zipInputStream = ZipInputStream(BufferedInputStream(activity.getFileInputStreamSync(path))) - zipInputStream.use { + ZipInputStream(BufferedInputStream(activity.getFileInputStreamSync(path))).use { zipInputStream -> try { val fileDirItems = ArrayList() var entry = zipInputStream.nextEntry @@ -541,6 +540,7 @@ class ItemsAdapter( } } } catch (exception: Exception) { + exception.printStackTrace() activity.showErrorToast(exception) } } @@ -643,8 +643,8 @@ class ItemsAdapter( while (!queue.isEmpty()) { mainFilePath = queue.pop() if (activity.getIsPathDirectory(mainFilePath)) { - if (activity.isRestrictedAndroidDir(mainFilePath)) { - activity.getStorageItemsWithTreeUri(mainFilePath, true) { files -> + if (activity.isRestrictedSAFOnlyRoot(mainFilePath)) { + activity.getAndroidSAFFileItems(mainFilePath, true) { files -> for (file in files) { name = file.path.relativizeWith(base) if (activity.getIsPathDirectory(file.path)) { @@ -884,8 +884,8 @@ class ItemsAdapter( path } - if (activity.isRestrictedAndroidDir(path)) { - itemToLoad = activity.getPrimaryAndroidSAFUri(path) + if (activity.isRestrictedSAFOnlyRoot(path)) { + itemToLoad = activity.getAndroidSAFUri(path) } else if (hasOTGConnected && itemToLoad is String && activity.isPathOnOTG(itemToLoad) && baseConfig.OTGTreeUri.isNotEmpty() && baseConfig.OTGPartition.isNotEmpty()) { itemToLoad = getOTGPublicPath(itemToLoad) } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CreateNewItemDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CreateNewItemDialog.kt index fa731fbc..d54116c4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CreateNewItemDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CreateNewItemDialog.kt @@ -51,6 +51,27 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) { when { + isRPlus() || path.startsWith(activity.internalStoragePath, true) -> { + if (activity.isRestrictedSAFOnlyRoot(path)) { + activity.handlePrimaryAndroidSAFDialog(path) { + if (!it) { + callback(false) + return@handlePrimaryAndroidSAFDialog + } + if (activity.createAndroidSAFDirectory(path)) { + success(alertDialog) + } else { + val error = String.format(activity.getString(R.string.could_not_create_folder), path) + activity.showErrorToast(error) + callback(false) + } + } + } else { + if (File(path).mkdirs()) { + success(alertDialog) + } + } + } activity.needsStupidWritePermissions(path) -> activity.handleSAFDialog(path) { if (!it) { return@handleSAFDialog @@ -66,27 +87,6 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca documentFile.createDirectory(path.getFilenameFromPath()) success(alertDialog) } - isRPlus() || path.startsWith(activity.internalStoragePath, true) -> { - if (activity.isRestrictedAndroidDir(path)) { - activity.handlePrimaryAndroidSAFDialog(path) { - if (!it) { - callback(false) - return@handlePrimaryAndroidSAFDialog - } - if (activity.createSAFOnlyDirectory(path)) { - success(alertDialog) - } else { - val error = String.format(activity.getString(R.string.could_not_create_folder), path) - activity.showErrorToast(error) - callback(false) - } - } - } else { - if (File(path).mkdirs()) { - success(alertDialog) - } - } - } else -> { RootHelpers(activity).createFileFolder(path, false) { if (it) { @@ -102,13 +102,13 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca private fun createFile(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) { try { when { - activity.isRestrictedAndroidDir(path) -> { + activity.isRestrictedSAFOnlyRoot(path) -> { activity.handlePrimaryAndroidSAFDialog(path) { if (!it) { callback(false) return@handlePrimaryAndroidSAFDialog } - if (activity.createSAFOnlyFile(path)) { + if (activity.createAndroidSAFFile(path)) { success(alertDialog) } else { val error = String.format(activity.getString(R.string.could_not_create_file), path) @@ -141,7 +141,6 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca success(alertDialog) } } - else -> { RootHelpers(activity).createFileFolder(path, true) { if (it) { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt index 0e30de4a..07b1f5f5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/extensions/Context.kt @@ -3,9 +3,8 @@ package com.simplemobiletools.filemanager.pro.extensions import android.content.Context import com.simplemobiletools.commons.extensions.isPathOnOTG import com.simplemobiletools.commons.extensions.isPathOnSD -import com.simplemobiletools.commons.extensions.otgPath -import com.simplemobiletools.commons.extensions.sdCardPath import com.simplemobiletools.filemanager.pro.helpers.Config val Context.config: Config get() = Config.newInstance(applicationContext) + fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || isPathOnOTG(path) || (isPathOnSD(path))) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index 784841d3..56856166 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -187,15 +187,15 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF val isSortingBySize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0 val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST - if (context.isRestrictedAndroidDir(path)) { + if (context.isRestrictedSAFOnlyRoot(path)) { activity?.handlePrimaryAndroidSAFDialog(path) { if (!it) { activity?.toast(R.string.no_storage_permissions) return@handlePrimaryAndroidSAFDialog } - context.getStorageItemsWithTreeUri(path, context.config.shouldShowHidden, getProperChildCount) { - callback(path, getListItemsFromFileDirItems(it)) + context.getAndroidSAFFileItems(path, context.config.shouldShowHidden, getProperChildCount) { fileItems -> + callback(path, getListItemsFromFileDirItems(fileItems)) } } } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt index 39541e45..a2f0c66e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt @@ -149,7 +149,6 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage } } } catch (e: Exception) { - e.printStackTrace() activity?.showErrorToast(e) } diff --git a/app/src/main/res/menu/cab.xml b/app/src/main/res/menu/cab.xml index b179b77b..7dfbb6db 100644 --- a/app/src/main/res/menu/cab.xml +++ b/app/src/main/res/menu/cab.xml @@ -13,12 +13,12 @@ app:showAsAction="always"/> - Simple File Manager Pro - Manage files easily & fast + Simple File Manager Pro - Manage files easily & fast - Quick file management with no ads. Browse files easily, securely & fast + Quick file management with no ads. Browse files easily, securely & fast Un xestor de ficheiros rápido e lixeiro para uso diario. Ofrece unha funcionalidade de busca útil e podes personalizar o cartafol de inicio e seleccionar os cartafoles favoritos para un acceso rápido.