Skip to content

Commit 32ca1fd

Browse files
committed
improve root content deleting
1 parent 5cb9b6c commit 32ca1fd

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.simplemobiletools.filemanager.adapters.ItemsAdapter
2424
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
2525
import com.simplemobiletools.filemanager.extensions.config
2626
import com.simplemobiletools.filemanager.helpers.RootHelpers
27+
import com.stericson.RootTools.RootTools
2728
import kotlinx.android.synthetic.main.items_fragment.*
2829
import kotlinx.android.synthetic.main.items_fragment.view.*
2930
import java.io.File
@@ -159,16 +160,18 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
159160
}
160161

161162
private fun getItems(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
162-
val config = context.config
163163
Thread({
164-
if (!config.enableRootAccess || path.startsWith(config.internalStoragePath) || (context.hasExternalSDCard() && path.startsWith(config.sdCardPath))) {
164+
if (!context.config.enableRootAccess || !isPathOnRoot(path)) {
165165
getRegularItemsOf(path, callback)
166166
} else {
167167
getRootItemsOf(path, callback)
168168
}
169169
}).start()
170170
}
171171

172+
private fun isPathOnRoot(path: String) =
173+
!(path.startsWith(context.config.internalStoragePath) || (context.hasExternalSDCard() && path.startsWith(context.config.sdCardPath)))
174+
172175
private fun getRegularItemsOf(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
173176
val items = ArrayList<FileDirItem>()
174177
val files = File(path).listFiles()
@@ -262,10 +265,16 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
262265

263266
override fun deleteFiles(files: ArrayList<File>) {
264267
val hasFolder = files.any { it.isDirectory }
265-
(activity as SimpleActivity).deleteFiles(files, hasFolder) {
266-
if (!it) {
267-
activity.runOnUiThread {
268-
activity.toast(R.string.unknown_error_occurred)
268+
if (isPathOnRoot(files.firstOrNull()?.absolutePath ?: context.config.internalStoragePath)) {
269+
files.forEach {
270+
RootTools.deleteFileOrDirectory(it.path, false)
271+
}
272+
} else {
273+
(activity as SimpleActivity).deleteFiles(files, hasFolder) {
274+
if (!it) {
275+
activity.runOnUiThread {
276+
activity.toast(R.string.unknown_error_occurred)
277+
}
269278
}
270279
}
271280
}

0 commit comments

Comments
 (0)