improve root content deleting
This commit is contained in:
parent
5cb9b6cc4f
commit
32ca1fdf70
|
@ -24,6 +24,7 @@ import com.simplemobiletools.filemanager.adapters.ItemsAdapter
|
||||||
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
|
||||||
import com.simplemobiletools.filemanager.extensions.config
|
import com.simplemobiletools.filemanager.extensions.config
|
||||||
import com.simplemobiletools.filemanager.helpers.RootHelpers
|
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.*
|
||||||
import kotlinx.android.synthetic.main.items_fragment.view.*
|
import kotlinx.android.synthetic.main.items_fragment.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -159,9 +160,8 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getItems(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
private fun getItems(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
||||||
val config = context.config
|
|
||||||
Thread({
|
Thread({
|
||||||
if (!config.enableRootAccess || path.startsWith(config.internalStoragePath) || (context.hasExternalSDCard() && path.startsWith(config.sdCardPath))) {
|
if (!context.config.enableRootAccess || !isPathOnRoot(path)) {
|
||||||
getRegularItemsOf(path, callback)
|
getRegularItemsOf(path, callback)
|
||||||
} else {
|
} else {
|
||||||
getRootItemsOf(path, callback)
|
getRootItemsOf(path, callback)
|
||||||
|
@ -169,6 +169,9 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
||||||
}).start()
|
}).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) {
|
private fun getRegularItemsOf(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
||||||
val items = ArrayList<FileDirItem>()
|
val items = ArrayList<FileDirItem>()
|
||||||
val files = File(path).listFiles()
|
val files = File(path).listFiles()
|
||||||
|
@ -262,6 +265,11 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
||||||
|
|
||||||
override fun deleteFiles(files: ArrayList<File>) {
|
override fun deleteFiles(files: ArrayList<File>) {
|
||||||
val hasFolder = files.any { it.isDirectory }
|
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) {
|
(activity as SimpleActivity).deleteFiles(files, hasFolder) {
|
||||||
if (!it) {
|
if (!it) {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
|
@ -270,6 +278,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun itemLongClicked(position: Int) {
|
override fun itemLongClicked(position: Int) {
|
||||||
items_list.setDragSelectActive(position)
|
items_list.setDragSelectActive(position)
|
||||||
|
|
Loading…
Reference in New Issue