Skip to content

Commit 794f6cc

Browse files
committed
make isPathOnRoot a context extension
1 parent 32ca1fd commit 794f6cc

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.simplemobiletools.filemanager.extensions
22

33
import android.content.Context
4+
import com.simplemobiletools.commons.extensions.hasExternalSDCard
45
import com.simplemobiletools.filemanager.Config
56

67
val Context.config: Config get() = Config.newInstance(this)
8+
9+
fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || (hasExternalSDCard() && path.startsWith(config.sdCardPath)))

app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.simplemobiletools.filemanager.activities.SimpleActivity
2323
import com.simplemobiletools.filemanager.adapters.ItemsAdapter
2424
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
2525
import com.simplemobiletools.filemanager.extensions.config
26+
import com.simplemobiletools.filemanager.extensions.isPathOnRoot
2627
import com.simplemobiletools.filemanager.helpers.RootHelpers
2728
import com.stericson.RootTools.RootTools
2829
import kotlinx.android.synthetic.main.items_fragment.*
@@ -161,17 +162,14 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
161162

162163
private fun getItems(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
163164
Thread({
164-
if (!context.config.enableRootAccess || !isPathOnRoot(path)) {
165+
if (!context.config.enableRootAccess || !context.isPathOnRoot(path)) {
165166
getRegularItemsOf(path, callback)
166167
} else {
167168
getRootItemsOf(path, callback)
168169
}
169170
}).start()
170171
}
171172

172-
private fun isPathOnRoot(path: String) =
173-
!(path.startsWith(context.config.internalStoragePath) || (context.hasExternalSDCard() && path.startsWith(context.config.sdCardPath)))
174-
175173
private fun getRegularItemsOf(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
176174
val items = ArrayList<FileDirItem>()
177175
val files = File(path).listFiles()
@@ -265,7 +263,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
265263

266264
override fun deleteFiles(files: ArrayList<File>) {
267265
val hasFolder = files.any { it.isDirectory }
268-
if (isPathOnRoot(files.firstOrNull()?.absolutePath ?: context.config.internalStoragePath)) {
266+
if (context.isPathOnRoot(files.firstOrNull()?.absolutePath ?: context.config.internalStoragePath)) {
269267
files.forEach {
270268
RootTools.deleteFileOrDirectory(it.path, false)
271269
}

0 commit comments

Comments
 (0)