From f08f7474ae34d129cb9e656442493a813cb91c5a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 16 Feb 2019 17:57:24 +0100 Subject: [PATCH] updating Commons with the new way of handling OTG files --- app/build.gradle | 2 +- .../pro/activities/MainActivity.kt | 4 +-- .../filemanager/pro/adapters/ItemsAdapter.kt | 27 +++++++------------ .../pro/dialogs/CompressAsDialog.kt | 5 ++-- .../pro/dialogs/CreateNewItemDialog.kt | 2 +- .../filemanager/pro/dialogs/SaveAsDialog.kt | 3 ++- .../filemanager/pro/extensions/Context.kt | 6 ++--- .../pro/fragments/ItemsFragment.kt | 7 +++-- .../filemanager/pro/helpers/Config.kt | 6 +---- build.gradle | 4 +-- 10 files changed, 28 insertions(+), 38 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a5de2181..f485bf1e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,7 +51,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.7.5' + implementation 'com.simplemobiletools:commons:5.8.2' implementation 'com.github.Stericson:RootTools:df729dcb13' implementation 'com.alexvasilkov:gesture-views:2.5.2' } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index 84fe2d33..f9fed1e1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -183,7 +183,7 @@ class MainActivity : SimpleActivity() { val file = File(path) if (file.exists() && !file.isDirectory) { newPath = file.parent - } else if (!file.exists() && !newPath.startsWith(OTG_PATH)) { + } else if (!file.exists() && !isPathOnOTG(newPath)) { newPath = internalStoragePath } @@ -290,7 +290,7 @@ class MainActivity : SimpleActivity() { private fun checkInvalidFavorites() { Thread { config.favorites.forEach { - if (!it.startsWith(OTG_PATH) && !isPathOnSD(it) && !getDoesFilePathExist(it)) { + if (!isPathOnOTG(it) && !isPathOnSD(it) && !File(it).exists()) { config.removeFavorite(it) } } 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 cb691538..cb7489c7 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 @@ -17,7 +17,6 @@ import com.simplemobiletools.commons.dialogs.* import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE import com.simplemobiletools.commons.helpers.CONFLICT_SKIP -import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.views.FastScroller @@ -203,9 +202,9 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList) { - if (activity.getIsPathDirectory(path)) { + if (File(path).isDirectory) { val shouldShowHidden = activity.config.shouldShowHidden - if (path.startsWith(OTG_PATH)) { + if (activity.isPathOnOTG(path)) { activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name!!.startsWith(".") }?.forEach { addFileUris(it.uri.toString(), paths) } @@ -285,17 +284,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList Unit) { private val view = activity.layoutInflater.inflate(R.layout.dialog_compress_as, null) init { val filename = path.getFilenameFromPath() - val indexOfDot = if (filename.contains('.') && !activity.getIsPathDirectory(path)) filename.lastIndexOf(".") else filename.length + val indexOfDot = if (filename.contains('.') && !File(path).isDirectory) filename.lastIndexOf(".") else filename.length val baseFilename = filename.substring(0, indexOfDot) var realPath = path.getParentPath() @@ -42,7 +43,7 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c name.isEmpty() -> activity.toast(R.string.empty_name) name.isAValidFilename() -> { val newPath = "$realPath/$name.zip" - if (activity.getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { activity.toast(R.string.name_taken) return@OnClickListener } 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 8046e712..931eef1b 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 @@ -26,7 +26,7 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca activity.toast(R.string.empty_name) } else if (name.isAValidFilename()) { val newPath = "$path/$name" - if (activity.getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { activity.toast(R.string.name_taken) return@OnClickListener } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/SaveAsDialog.kt index 97fab1b5..2dc543aa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/SaveAsDialog.kt @@ -7,6 +7,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.filemanager.pro.R import kotlinx.android.synthetic.main.dialog_save_as.view.* +import java.io.File class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callback: (savePath: String) -> Unit) { @@ -64,7 +65,7 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb return@setOnClickListener } - if (activity.getDoesFilePathExist(newPath)) { + if (File(newPath).exists()) { val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename) ConfirmationDialog(activity, title) { callback(newPath) 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 8471588c..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 @@ -1,10 +1,10 @@ package com.simplemobiletools.filemanager.pro.extensions import android.content.Context -import com.simplemobiletools.commons.extensions.hasExternalSDCard -import com.simplemobiletools.commons.helpers.OTG_PATH +import com.simplemobiletools.commons.extensions.isPathOnOTG +import com.simplemobiletools.commons.extensions.isPathOnSD import com.simplemobiletools.filemanager.pro.helpers.Config val Context.config: Config get() = Config.newInstance(applicationContext) -fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || path.startsWith(OTG_PATH) || (hasExternalSDCard() && path.startsWith(config.sdCardPath))) +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 ce055dc3..17acced3 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 @@ -9,7 +9,6 @@ import androidx.fragment.app.Fragment import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.StoragePickerDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.views.Breadcrumbs @@ -115,7 +114,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb return } - var realPath = if (path == OTG_PATH) OTG_PATH else path.trimEnd('/') + var realPath = path.trimEnd('/') if (realPath.isEmpty()) { realPath = "/" } @@ -174,12 +173,12 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb skipItemUpdating = false Thread { if (activity?.isDestroyed == false) { - if (path.startsWith(OTG_PATH)) { + /*if (path.startsWith(OTG_PATH)) { val getProperFileSize = context!!.config.sorting and SORT_BY_SIZE != 0 context!!.getOTGItems(path, context!!.config.shouldShowHidden, getProperFileSize) { callback(path, it) } - } else if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) { + } else */if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) { getRegularItemsOf(path, callback) } else { RootHelpers(activity!!).getFiles(path, callback) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt index 1c73efce..ae47cb47 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt @@ -1,10 +1,8 @@ package com.simplemobiletools.filemanager.pro.helpers import android.content.Context -import com.simplemobiletools.commons.extensions.getDocumentFile import com.simplemobiletools.commons.extensions.getInternalStoragePath import com.simplemobiletools.commons.helpers.BaseConfig -import com.simplemobiletools.commons.helpers.OTG_PATH import java.io.File class Config(context: Context) : BaseConfig(context) { @@ -25,9 +23,7 @@ class Config(context: Context) : BaseConfig(context) { var homeFolder: String get(): String { var path = prefs.getString(HOME_FOLDER, "") - if (path.isEmpty() || - (path.startsWith(OTG_PATH) && context.getDocumentFile(path)?.isDirectory != true) || - (!path.startsWith(OTG_PATH) && !File(path).isDirectory)) { + if (path.isEmpty() || !File(path).isDirectory) { path = context.getInternalStoragePath() homeFolder = path } diff --git a/build.gradle b/build.gradle index 7694217e..0be76662 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.20' + ext.kotlin_version = '1.3.21' repositories { google() @@ -9,7 +9,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.3.0' + classpath 'com.android.tools.build:gradle:3.3.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong