mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
use the copy/move functionality from the commons library
This commit is contained in:
parent
3629f0ff55
commit
409ecbe4b5
2 changed files with 3 additions and 77 deletions
|
@ -32,7 +32,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.simplemobiletools:commons:2.16.9'
|
||||
compile 'com.simplemobiletools:commons:2.17.0'
|
||||
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
|
||||
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
|
||||
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package com.simplemobiletools.gallery.activities
|
||||
|
||||
import android.support.v4.util.Pair
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
|
||||
import com.simplemobiletools.commons.extensions.isPathOnSD
|
||||
import com.simplemobiletools.commons.extensions.scanFiles
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.dialogs.PickAlbumDialog
|
||||
|
@ -12,85 +8,15 @@ import java.io.File
|
|||
import java.util.*
|
||||
|
||||
open class SimpleActivity : BaseSimpleActivity() {
|
||||
var copyMoveCallback: (() -> Unit)? = null
|
||||
|
||||
fun tryCopyMoveFilesTo(files: ArrayList<File>, isCopyOperation: Boolean, callback: () -> Unit) {
|
||||
if (files.isEmpty()) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
return
|
||||
}
|
||||
|
||||
val source = if (files[0].isFile) files[0].parent.trimEnd('/') else files[0].absolutePath.trimEnd('/')
|
||||
val source = if (files[0].isFile) files[0].parent else files[0].absolutePath
|
||||
PickAlbumDialog(this, source) {
|
||||
copyMoveFilesTo(files, source, it, isCopyOperation, callback)
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyMoveFilesTo(files: ArrayList<File>, source: String, destination: String, isCopyOperation: Boolean, callback: () -> Unit) {
|
||||
if (source == destination) {
|
||||
toast(R.string.source_and_destination_same)
|
||||
return
|
||||
}
|
||||
|
||||
val destinationFolder = File(destination)
|
||||
if (!destinationFolder.exists()) {
|
||||
toast(R.string.invalid_destination)
|
||||
return
|
||||
}
|
||||
|
||||
if (files.size == 1) {
|
||||
if (File(destinationFolder.absolutePath, files[0].name).exists()) {
|
||||
toast(R.string.name_taken)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
handleSAFDialog(destinationFolder) {
|
||||
copyMoveCallback = callback
|
||||
if (isCopyOperation) {
|
||||
toast(R.string.copying)
|
||||
val pair = Pair<ArrayList<File>, File>(files, destinationFolder)
|
||||
CopyMoveTask(this, isCopyOperation, true, copyMoveListener).execute(pair)
|
||||
} else {
|
||||
if (isPathOnSD(source) || isPathOnSD(destinationFolder.absolutePath)) {
|
||||
handleSAFDialog(files[0]) {
|
||||
toast(R.string.moving)
|
||||
val pair = Pair<ArrayList<File>, File>(files, destinationFolder)
|
||||
CopyMoveTask(this, isCopyOperation, true, copyMoveListener).execute(pair)
|
||||
}
|
||||
} else {
|
||||
val updatedFiles = ArrayList<File>(files.size * 2)
|
||||
updatedFiles.addAll(files)
|
||||
for (file in files) {
|
||||
val newFile = File(destinationFolder, file.name)
|
||||
if (!newFile.exists() && file.renameTo(newFile))
|
||||
updatedFiles.add(newFile)
|
||||
}
|
||||
|
||||
scanFiles(updatedFiles) {
|
||||
runOnUiThread {
|
||||
copyMoveListener.copySucceeded(true, files.size * 2 == updatedFiles.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val copyMoveListener = object : CopyMoveTask.CopyMoveListener {
|
||||
override fun copySucceeded(copyOnly: Boolean, copiedAll: Boolean) {
|
||||
if (copyOnly) {
|
||||
toast(if (copiedAll) R.string.copying_success else R.string.copying_success_partial)
|
||||
} else {
|
||||
toast(if (copiedAll) R.string.moving_success else R.string.moving_success_partial)
|
||||
}
|
||||
copyMoveCallback?.invoke()
|
||||
copyMoveCallback = null
|
||||
}
|
||||
|
||||
override fun copyFailed() {
|
||||
toast(R.string.copy_move_failed)
|
||||
copyMoveCallback = null
|
||||
copyMoveFilesTo(files, source.trimEnd('/'), it, isCopyOperation, callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue