From 9f6936000495b8fda56b16c962c07ae9f67649f5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 4 Sep 2017 19:48:31 +0200 Subject: [PATCH] add some handling for copying root items --- .../filemanager/adapters/ItemsAdapter.kt | 33 +++++++++++++++++-- .../filemanager/helpers/RootHelpers.kt | 1 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 8fc066b5..bacd3b03 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -25,7 +25,9 @@ import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.activities.SimpleActivity import com.simplemobiletools.filemanager.dialogs.CompressAsDialog import com.simplemobiletools.filemanager.extensions.config +import com.simplemobiletools.filemanager.extensions.isPathOnRoot import com.simplemobiletools.filemanager.extensions.isZipFile +import com.stericson.RootTools.RootTools import kotlinx.android.synthetic.main.list_item.view.* import java.io.Closeable import java.io.File @@ -207,11 +209,38 @@ class ItemsAdapter(val activity: SimpleActivity, var mItems: MutableList, destinationPath: String) { + activity.toast(R.string.copying) + Thread({ + var fileCnt = files.count() + files.forEach { + if (RootTools.copyFile(it.absolutePath, destinationPath, false, true)) { + fileCnt-- + } + } + + when { + fileCnt <= 0 -> activity.toast(R.string.copying_success) + fileCnt == files.count() -> activity.toast(R.string.copy_failed) + else -> activity.toast(R.string.copying_success_partial) + } + + activity.runOnUiThread { listener?.refreshItems() actMode?.finish() } - } + }).start() } private fun compressSelection() { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt index c16c7e05..28c2b83c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt @@ -75,6 +75,7 @@ class RootHelpers { super.commandCompleted(id, exitcode) } } + try { RootTools.getShell(true).add(command) } catch (e: Exception) {