mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-29 19:27:59 +01:00
use a callback for copy/move result
This commit is contained in:
parent
77d8bce189
commit
8d1145e038
2 changed files with 22 additions and 15 deletions
|
@ -13,11 +13,13 @@ import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
open class SimpleActivity : BaseSimpleActivity() {
|
open class SimpleActivity : BaseSimpleActivity() {
|
||||||
|
var copyMoveCallback: (() -> Unit)? = null
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun copyMoveFilesTo(source: String, files: ArrayList<File>, isCopyOperation: Boolean, copyMoveListener: CopyMoveTask.CopyMoveListener) {
|
protected fun copyMoveFilesTo(source: String, files: ArrayList<File>, isCopyOperation: Boolean, callback: () -> Unit) {
|
||||||
|
copyMoveCallback = callback
|
||||||
val currPath = source.trimEnd('/')
|
val currPath = source.trimEnd('/')
|
||||||
PickAlbumDialog(this, currPath) {
|
PickAlbumDialog(this, currPath) {
|
||||||
val destinationFolder = File(it)
|
val destinationFolder = File(it)
|
||||||
|
@ -69,4 +71,21 @@ open class SimpleActivity : BaseSimpleActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import android.util.DisplayMetrics
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
|
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
|
@ -188,22 +187,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
private fun copyMoveTo(isCopyOperation: Boolean) {
|
private fun copyMoveTo(isCopyOperation: Boolean) {
|
||||||
val currPath = File(getCurrentPath()).parent.trimEnd('/')
|
val currPath = File(getCurrentPath()).parent.trimEnd('/')
|
||||||
val files = ArrayList<File>(1).apply { add(getCurrentFile()) }
|
val files = ArrayList<File>(1).apply { add(getCurrentFile()) }
|
||||||
copyMoveFilesTo(currPath, files, isCopyOperation, copyMoveListener)
|
copyMoveFilesTo(currPath, files, isCopyOperation) {
|
||||||
}
|
if (!isCopyOperation) {
|
||||||
|
|
||||||
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 {
|
|
||||||
reloadViewPager()
|
reloadViewPager()
|
||||||
toast(if (copiedAll) R.string.moving_success else R.string.moving_success_partial)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun copyFailed() {
|
|
||||||
toast(R.string.copy_move_failed)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveImageAs() {
|
private fun saveImageAs() {
|
||||||
|
|
Loading…
Reference in a new issue