improve root content deleting

This commit is contained in:
tibbi 2017-09-04 19:23:07 +02:00
parent 5cb9b6cc4f
commit 32ca1fdf70
1 changed files with 15 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import com.simplemobiletools.filemanager.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
import com.simplemobiletools.filemanager.extensions.config
import com.simplemobiletools.filemanager.helpers.RootHelpers
import com.stericson.RootTools.RootTools
import kotlinx.android.synthetic.main.items_fragment.*
import kotlinx.android.synthetic.main.items_fragment.view.*
import java.io.File
@ -159,9 +160,8 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
}
private fun getItems(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
val config = context.config
Thread({
if (!config.enableRootAccess || path.startsWith(config.internalStoragePath) || (context.hasExternalSDCard() && path.startsWith(config.sdCardPath))) {
if (!context.config.enableRootAccess || !isPathOnRoot(path)) {
getRegularItemsOf(path, callback)
} else {
getRootItemsOf(path, callback)
@ -169,6 +169,9 @@ 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<FileDirItem>) -> Unit) {
val items = ArrayList<FileDirItem>()
val files = File(path).listFiles()
@ -262,6 +265,11 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
override fun deleteFiles(files: ArrayList<File>) {
val hasFolder = files.any { it.isDirectory }
if (isPathOnRoot(files.firstOrNull()?.absolutePath ?: context.config.internalStoragePath)) {
files.forEach {
RootTools.deleteFileOrDirectory(it.path, false)
}
} else {
(activity as SimpleActivity).deleteFiles(files, hasFolder) {
if (!it) {
activity.runOnUiThread {
@ -270,6 +278,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
}
}
}
}
override fun itemLongClicked(position: Int) {
items_list.setDragSelectActive(position)