diff --git a/build.gradle b/build.gradle index 54e94ab08..3b62601af 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { propMinSdkVersion = 21 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 - propVersionName = '5.7.16' + propVersionName = '5.7.17' kotlin_version = '1.3.21' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt index e48e9aff7..27bbf42f1 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt @@ -237,7 +237,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() { return } - if (!getDoesFilePathExist(destination)) { + if (!File(destination).exists()) { toast(R.string.invalid_destination) return } @@ -304,7 +304,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() { val newName = String.format("%s(%d).%s", file.nameWithoutExtension, fileIndex, file.extension) newFile = File(file.parent, newName) fileIndex++ - } while (getDoesFilePathExist(newFile!!.absolutePath)) + } while (File(newFile!!.absolutePath).exists()) return newFile } @@ -325,7 +325,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() { val file = files[index] val newFileDirItem = FileDirItem("$destinationPath/${file.name}", file.name, file.isDirectory) - if (getDoesFilePathExist(newFileDirItem.path)) { + if (File(newFileDirItem.path).exists()) { FileConflictDialog(this, newFileDirItem) { resolution, applyForAll -> if (applyForAll) { conflictResolutions.clear() diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt index d7325ef25..3ede8165e 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/asynctasks/CopyMoveTask.kt @@ -81,7 +81,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal try { val newPath = "$mDestinationPath/${file.name}" var newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), file.isDirectory) - if (activity.getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { val resolution = getConflictResolution(conflictResolutions, newPath) if (resolution == CONFLICT_SKIP) { mFileCountToCopy-- @@ -170,7 +170,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal val children = activity.getDocumentFile(source.path)?.listFiles() ?: return for (child in children) { val newPath = "$destinationPath/${child.name}" - if (activity.getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { continue } @@ -184,7 +184,7 @@ class CopyMoveTask(val activity: BaseSimpleActivity, val copyOnly: Boolean = fal val children = File(source.path).list() for (child in children) { val newPath = "$destinationPath/$child" - if (activity.getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { continue } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ExportSettingsDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ExportSettingsDialog.kt index 4d3a0f8d0..f9567a58c 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ExportSettingsDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/ExportSettingsDialog.kt @@ -5,6 +5,7 @@ import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.dialog_export_settings.view.* +import java.io.File class ExportSettingsDialog(val activity: BaseSimpleActivity, val defaultFilename: String, callback: (path: String) -> Unit) { init { @@ -38,7 +39,7 @@ class ExportSettingsDialog(val activity: BaseSimpleActivity, val defaultFilename return@setOnClickListener } - if (activity.getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newPath.getFilenameFromPath()) ConfirmationDialog(activity, title) { callback(newPath) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt index eac4ac98f..7df391211 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt @@ -43,11 +43,11 @@ class FilePickerDialog(val activity: BaseSimpleActivity, private var mDialogView = activity.layoutInflater.inflate(R.layout.dialog_filepicker, null) init { - if (!activity.getDoesFilePathExist(currPath)) { + if (!File(currPath).exists()) { currPath = activity.internalStoragePath } - if (!activity.getIsPathDirectory(currPath)) { + if (!File(currPath).isDirectory) { currPath = currPath.getParentPath() } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PropertiesDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PropertiesDialog.kt index 55e673cb8..0bcaa18bf 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PropertiesDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/PropertiesDialog.kt @@ -16,6 +16,7 @@ import com.simplemobiletools.commons.helpers.sumByLong import com.simplemobiletools.commons.models.FileDirItem import kotlinx.android.synthetic.main.dialog_properties.view.* import kotlinx.android.synthetic.main.property_item.view.* +import java.io.File import java.io.FileNotFoundException import java.util.* @@ -32,7 +33,7 @@ class PropertiesDialog() { * @param countHiddenItems toggle determining if we will count hidden files themselves and their sizes (reasonable only at directory properties) */ constructor(activity: Activity, path: String, countHiddenItems: Boolean = false) : this() { - if (!activity.getDoesFilePathExist(path)) { + if (!File(path).exists()) { activity.toast(String.format(activity.getString(R.string.source_file_doesnt_exist), path)) return } @@ -42,7 +43,7 @@ class PropertiesDialog() { val view = mInflater.inflate(R.layout.dialog_properties, null) mPropertyView = view.properties_holder - val fileDirItem = FileDirItem(path, path.getFilenameFromPath(), activity.getIsPathDirectory(path)) + val fileDirItem = FileDirItem(path, path.getFilenameFromPath(), File(path).isDirectory) addProperty(R.string.name, fileDirItem.name) addProperty(R.string.path, fileDirItem.getParentPath()) addProperty(R.string.size, "…", R.id.properties_size) @@ -137,7 +138,7 @@ class PropertiesDialog() { val fileDirItems = ArrayList(paths.size) paths.forEach { - val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), activity.getIsPathDirectory(it)) + val fileDirItem = FileDirItem(it, it.getFilenameFromPath(), File(it).isDirectory) fileDirItems.add(fileDirItem) } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemDialog.kt index 35a69760c..462d5e046 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemDialog.kt @@ -5,6 +5,7 @@ import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.dialog_rename_item.view.* +import java.io.File import java.util.* class RenameItemDialog(val activity: BaseSimpleActivity, val path: String, val callback: (newPath: String) -> Unit) { @@ -14,7 +15,7 @@ class RenameItemDialog(val activity: BaseSimpleActivity, val path: String, val c var name = fullName val view = activity.layoutInflater.inflate(R.layout.dialog_rename_item, null).apply { - if (dotAt > 0 && !activity.getIsPathDirectory(path)) { + if (dotAt > 0 && !File(path).isDirectory) { name = fullName.substring(0, dotAt) val extension = fullName.substring(dotAt + 1) rename_item_extension.setText(extension) @@ -53,13 +54,13 @@ class RenameItemDialog(val activity: BaseSimpleActivity, val path: String, val c newName += ".$newExtension" } - if (!activity.getDoesFilePathExist(path)) { + if (!File(path).exists()) { activity.toast(String.format(activity.getString(R.string.source_file_doesnt_exist), path)) return@setOnClickListener } val newPath = "${path.getParentPath()}/$newName" - if (activity.getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { activity.toast(R.string.name_taken) return@setOnClickListener } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemsDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemsDialog.kt index 4eac00431..d0e7a4f10 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemsDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemsDialog.kt @@ -6,6 +6,7 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.dialog_rename_items.* import kotlinx.android.synthetic.main.dialog_rename_items.view.* +import java.io.File import java.util.* class RenameItemsDialog(val activity: BaseSimpleActivity, val paths: ArrayList, val callback: () -> Unit) { @@ -34,7 +35,7 @@ class RenameItemsDialog(val activity: BaseSimpleActivity, val paths: ArrayList Unit) { } fun BaseSimpleActivity.createDirectorySync(directory: String): Boolean { - if (getDoesFilePathExist(directory)) { + if (File(directory).exists()) { return true } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt index 3164fc410..b82b6f1de 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt @@ -278,7 +278,7 @@ fun Context.getFileUri(path: String) = when { // these functions update the mediastore instantly, MediaScannerConnection.scanFileRecursively takes some time to really get applied fun Context.deleteFromMediaStore(path: String): Boolean { - if (getDoesFilePathExist(path) || getIsPathDirectory(path)) { + if (File(path).exists() || File(path).isDirectory) { return false } @@ -389,7 +389,7 @@ fun Context.rescanDeletedPath(path: String, callback: (() -> Unit)? = null) { if (deleteFromMediaStore(path)) { callback?.invoke() } else { - if (getIsPathDirectory(path)) { + if (File(path).isDirectory) { callback?.invoke() return } @@ -431,17 +431,6 @@ fun Context.trySAFFileDelete(fileDirItem: FileDirItem, allowDeleteFolder: Boolea } } -fun Context.getDoesFilePathExist(path: String) = if (isPathOnOTG(path)) getOTGFastDocumentFile(path)?.exists() - ?: false else File(path).exists() - -fun Context.getIsPathDirectory(path: String): Boolean { - return if (isPathOnOTG(path)) { - getOTGFastDocumentFile(path)?.isDirectory ?: false - } else { - File(path).isDirectory - } -} - // avoid these being set as SD card paths private val physicalPaths = arrayListOf( "/storage/sdcard1", // Motorola Xoom diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/File.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/File.kt index 4561a9119..52b1302ea 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/File.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/File.kt @@ -76,4 +76,4 @@ private fun getDirectoryFileCount(dir: File, countHiddenItems: Boolean): Int { fun File.getDirectChildrenCount(countHiddenItems: Boolean) = listFiles()?.filter { if (countHiddenItems) true else !it.isHidden }?.size ?: 0 -fun File.toFileDirItem(context: Context) = FileDirItem(absolutePath, name, context.getIsPathDirectory(absolutePath), 0, length()) +fun File.toFileDirItem(context: Context) = FileDirItem(absolutePath, name, File(absolutePath).isDirectory, 0, length())