From 794f6cc4624f5f74e07391331a43726de2e285ac Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 4 Sep 2017 19:27:19 +0200 Subject: [PATCH] make isPathOnRoot a context extension --- .../simplemobiletools/filemanager/extensions/context.kt | 3 +++ .../filemanager/fragments/ItemsFragment.kt | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/extensions/context.kt index ca5c3a72..c0e44f45 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/extensions/context.kt @@ -1,6 +1,9 @@ package com.simplemobiletools.filemanager.extensions import android.content.Context +import com.simplemobiletools.commons.extensions.hasExternalSDCard import com.simplemobiletools.filemanager.Config val Context.config: Config get() = Config.newInstance(this) + +fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || (hasExternalSDCard() && path.startsWith(config.sdCardPath))) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index f571be74..b6d89adc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -23,6 +23,7 @@ import com.simplemobiletools.filemanager.activities.SimpleActivity import com.simplemobiletools.filemanager.adapters.ItemsAdapter import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog import com.simplemobiletools.filemanager.extensions.config +import com.simplemobiletools.filemanager.extensions.isPathOnRoot import com.simplemobiletools.filemanager.helpers.RootHelpers import com.stericson.RootTools.RootTools import kotlinx.android.synthetic.main.items_fragment.* @@ -161,7 +162,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener { private fun getItems(path: String, callback: (items: ArrayList) -> Unit) { Thread({ - if (!context.config.enableRootAccess || !isPathOnRoot(path)) { + if (!context.config.enableRootAccess || !context.isPathOnRoot(path)) { getRegularItemsOf(path, callback) } else { getRootItemsOf(path, callback) @@ -169,9 +170,6 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener { }).start() } - private fun isPathOnRoot(path: String) = - !(path.startsWith(context.config.internalStoragePath) || (context.hasExternalSDCard() && path.startsWith(context.config.sdCardPath))) - private fun getRegularItemsOf(path: String, callback: (items: ArrayList) -> Unit) { val items = ArrayList() val files = File(path).listFiles() @@ -265,7 +263,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener { override fun deleteFiles(files: ArrayList) { val hasFolder = files.any { it.isDirectory } - if (isPathOnRoot(files.firstOrNull()?.absolutePath ?: context.config.internalStoragePath)) { + if (context.isPathOnRoot(files.firstOrNull()?.absolutePath ?: context.config.internalStoragePath)) { files.forEach { RootTools.deleteFileOrDirectory(it.path, false) }