removing a few OTG related helper functions
This commit is contained in:
parent
f8b2e3f1f6
commit
e21ac505e5
11 changed files with 26 additions and 33 deletions
|
@ -7,7 +7,7 @@ buildscript {
|
|||
propMinSdkVersion = 21
|
||||
propTargetSdkVersion = propCompileSdkVersion
|
||||
propVersionCode = 1
|
||||
propVersionName = '5.7.16'
|
||||
propVersionName = '5.7.17'
|
||||
kotlin_version = '1.3.21'
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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<FileDirItem>(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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<String>, val callback: () -> Unit) {
|
||||
|
@ -34,7 +35,7 @@ class RenameItemsDialog(val activity: BaseSimpleActivity, val paths: ArrayList<S
|
|||
return@setOnClickListener
|
||||
}
|
||||
|
||||
val validPaths = paths.filter { activity.getDoesFilePathExist(it) }
|
||||
val validPaths = paths.filter { File(it).exists() }
|
||||
val sdFilePath = validPaths.firstOrNull { activity.isPathOnSD(it) } ?: validPaths.firstOrNull()
|
||||
if (sdFilePath == null) {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
|
@ -63,7 +64,7 @@ class RenameItemsDialog(val activity: BaseSimpleActivity, val paths: ArrayList<S
|
|||
|
||||
val newPath = "${path.getParentPath()}/$newName"
|
||||
|
||||
if (activity.getDoesFilePathExist(newPath)) {
|
||||
if (File(newPath).exists()) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -718,7 +718,7 @@ fun Activity.handleDeletePasswordProtection(callback: () -> Unit) {
|
|||
}
|
||||
|
||||
fun BaseSimpleActivity.createDirectorySync(directory: String): Boolean {
|
||||
if (getDoesFilePathExist(directory)) {
|
||||
if (File(directory).exists()) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue