handle root file/folder moving too

This commit is contained in:
tibbi 2018-04-17 15:16:01 +02:00
parent fa268f16f5
commit f19166491e
2 changed files with 11 additions and 6 deletions

View file

@ -197,7 +197,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
val source = if (firstFile.isDirectory) firstFile.path else firstFile.getParentPath()
FilePickerDialog(activity, source, false, activity.config.shouldShowHidden, true) {
if (activity.isPathOnRoot(it) || activity.isPathOnRoot(firstFile.path)) {
copyRootItems(files, it)
copyMoveRootItems(files, it, isCopyOperation)
} else {
activity.copyMoveFilesTo(files, source, it, isCopyOperation, false, activity.config.shouldShowHidden) {
listener?.refreshItems()
@ -207,11 +207,11 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
}
}
private fun copyRootItems(files: ArrayList<FileDirItem>, destinationPath: String) {
private fun copyMoveRootItems(files: ArrayList<FileDirItem>, destinationPath: String, isCopyOperation: Boolean) {
activity.toast(R.string.copying)
Thread {
val fileCnt = files.size
RootHelpers(activity).copyFiles(files, destinationPath) {
RootHelpers(activity).copyMoveFiles(files, destinationPath, isCopyOperation) {
when (it) {
fileCnt -> activity.toast(R.string.copying_success)
0 -> activity.toast(R.string.copy_failed)

View file

@ -255,9 +255,14 @@ class RootHelpers(val activity: Activity) {
}
}
fun copyFiles(fileDirItems: ArrayList<FileDirItem>, destination: String, successes: Int = 0, callback: (Int) -> Unit) {
fun copyMoveFiles(fileDirItems: ArrayList<FileDirItem>, destination: String, isCopyOperation: Boolean, successes: Int = 0, callback: (Int) -> Unit) {
val fileDirItem = fileDirItems.first()
val mainCommand = if (fileDirItem.isDirectory) "cp -R" else "cp"
val mainCommand = if (isCopyOperation) {
if (fileDirItem.isDirectory) "cp -R" else "cp"
} else {
"mv"
}
val cmd = "$mainCommand \"${fileDirItem.path}\" \"$destination\""
val command = object : Command(0, cmd) {
override fun commandCompleted(id: Int, exitcode: Int) {
@ -266,7 +271,7 @@ class RootHelpers(val activity: Activity) {
callback(newSuccesses)
} else {
fileDirItems.removeAt(0)
copyFiles(fileDirItems, destination, newSuccesses, callback)
copyMoveFiles(fileDirItems, destination, isCopyOperation, newSuccesses, callback)
}
super.commandCompleted(id, exitcode)
}