diff --git a/build.gradle b/build.gradle index cee49040d..1165d6c16 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { propMinSdkVersion = 21 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 - propVersionName = '5.18.17' + propVersionName = '5.18.19' kotlin_version = '1.3.50' } 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 f60a9d5dc..0156058f6 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 @@ -191,17 +191,18 @@ fun Context.getFastDocumentFile(path: String): DocumentFile? { return DocumentFile.fromSingleUri(this, Uri.parse(fullUri)) } -fun Context.getOTGFastDocumentFile(path: String): DocumentFile? { +fun Context.getOTGFastDocumentFile(path: String, otgPathToUse: String? = null): DocumentFile? { if (baseConfig.OTGTreeUri.isEmpty()) { return null } + val otgPath = otgPathToUse ?: baseConfig.OTGPath if (baseConfig.OTGPartition.isEmpty()) { baseConfig.OTGPartition = baseConfig.OTGTreeUri.removeSuffix("%3A").substringAfterLast('/').trimEnd('/') updateOTGPathFromPartition() } - val relativePath = Uri.encode(path.substring(baseConfig.OTGPath.length).trim('/')) + val relativePath = Uri.encode(path.substring(otgPath.length).trim('/')) val fullUri = "${baseConfig.OTGTreeUri}/document/${baseConfig.OTGPartition}%3A$relativePath" return DocumentFile.fromSingleUri(this, Uri.parse(fullUri)) } @@ -409,7 +410,8 @@ fun Context.trySAFFileDelete(fileDirItem: FileDirItem, allowDeleteFolder: Boolea } fun Context.updateOTGPathFromPartition() { - baseConfig.OTGPath = if (File("/storage/${baseConfig.OTGPartition}").exists()) { + val otgPath = "/storage/${baseConfig.OTGPartition}" + baseConfig.OTGPath = if (getOTGFastDocumentFile(otgPath, otgPath)?.exists() == true) { "/storage/${baseConfig.OTGPartition}" } else { "/mnt/media_rw/${baseConfig.OTGPartition}"