diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt index b6af5c2e..d23446db 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -252,8 +252,7 @@ class MainActivity : SimpleActivity() { FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons) ) - startAboutActivity(R.string.app_name, LICENSE_MULTISELECT or LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT, - BuildConfig.VERSION_NAME, faqItems) + startAboutActivity(R.string.app_name, LICENSE_MULTISELECT or LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT, BuildConfig.VERSION_NAME, faqItems) } override fun onBackPressed() { 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 6dc8efd7..35395990 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -28,8 +28,8 @@ import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.activities.SimpleActivity import com.simplemobiletools.filemanager.dialogs.CompressAsDialog import com.simplemobiletools.filemanager.extensions.* +import com.simplemobiletools.filemanager.helpers.RootHelpers import com.simplemobiletools.filemanager.interfaces.ItemOperationsListener -import com.stericson.RootTools.RootTools import kotlinx.android.synthetic.main.list_item.view.* import java.io.Closeable import java.io.File @@ -189,12 +189,14 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList() - selectedPositions.forEach { files.add(fileDirItems[it]) } + selectedPositions.forEach { + files.add(fileDirItems[it]) + } val firstFile = files[0] val source = if (firstFile.isDirectory) firstFile.path else firstFile.getParentPath() FilePickerDialog(activity, source, false, activity.config.shouldShowHidden, true) { - if (activity.isPathOnRoot(it)) { + if (activity.isPathOnRoot(it) || activity.isPathOnRoot(firstFile.path)) { copyRootItems(files, it) } else { activity.copyMoveFilesTo(files, source, it, isCopyOperation, false, activity.config.shouldShowHidden) { @@ -208,22 +210,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList, destinationPath: String) { activity.toast(R.string.copying) Thread { - var fileCnt = files.count() - files.forEach { - if (RootTools.copyFile(it.path, destinationPath, false, true)) { - fileCnt-- + val fileCnt = files.size + RootHelpers(activity).copyFiles(files, destinationPath) { + when (it) { + fileCnt -> activity.toast(R.string.copying_success) + 0 -> activity.toast(R.string.copy_failed) + else -> activity.toast(R.string.copying_success_partial) } - } - 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() - finishActMode() + activity.runOnUiThread { + listener?.refreshItems() + finishActMode() + } } }.start() } 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 0946bae2..b6a1b496 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt @@ -255,4 +255,23 @@ class RootHelpers(val activity: Activity) { } } } + + fun copyFiles(fileDirItems: ArrayList, destination: String, successes: Int = 0, callback: (Int) -> Unit) { + val fileDirItem = fileDirItems.first() + val mainCommand = if (fileDirItem.isDirectory) "cp -R" else "cp" + val cmd = "$mainCommand \"${fileDirItem.path}\" \"$destination\"" + val command = object : Command(0, cmd) { + override fun commandCompleted(id: Int, exitcode: Int) { + val newSuccesses = successes + (if (exitcode == 0) 1 else 0) + if (fileDirItems.size == 1) { + callback(newSuccesses) + } else { + fileDirItems.removeAt(0) + copyFiles(fileDirItems, destination, newSuccesses, callback) + } + super.commandCompleted(id, exitcode) + } + } + runCommand(command) + } }