cleaning up

This commit is contained in:
darthpaul
2021-11-14 00:06:56 +00:00
parent ed2bf87dc9
commit 627bbb519a
7 changed files with 42 additions and 45 deletions

View File

@ -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<String>, 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<FileDirItem>()
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)
}

View File

@ -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) {

View File

@ -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)))

View File

@ -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 {

View File

@ -149,7 +149,6 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
}
}
} catch (e: Exception) {
e.printStackTrace()
activity?.showErrorToast(e)
}

View File

@ -13,12 +13,12 @@
app:showAsAction="always"/>
<item
android:id="@+id/cab_properties"
android:icon="@drawable/ic_info"
android:icon="@drawable/ic_info_vector"
android:title="@string/properties"
app:showAsAction="always"/>
<item
android:id="@+id/cab_rename"
android:icon="@drawable/ic_rename_new"
android:icon="@drawable/ic_rename_new_vector"
android:title="@string/rename"
app:showAsAction="always"/>
<item
@ -28,7 +28,7 @@
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_hide"
android:icon="@drawable/ic_hide"
android:icon="@drawable/ic_hide_vector"
android:title="@string/hide"
app:showAsAction="ifRoom"/>
<item

View File

@ -44,9 +44,9 @@
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
<!-- App title has to have less than 50 characters. If you cannot squeeze it, just remove a part of it -->
<string name="app_title">Simple File Manager Pro - Manage files easily & fast</string>
<string name="app_title">Simple File Manager Pro - Manage files easily &amp; fast</string>
<!-- Short description has to have less than 80 chars -->
<string name="app_short_description">Quick file management with no ads. Browse files easily, securely & fast</string>
<string name="app_short_description">Quick file management with no ads. Browse files easily, securely &amp; fast</string>
<string name="app_long_description">
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.