mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 14:37:59 +01:00
move the copyMoveFilesTo into SimpleActivity
This commit is contained in:
parent
57a0baa253
commit
77d8bce189
2 changed files with 63 additions and 52 deletions
|
@ -1,10 +1,72 @@
|
|||
package com.simplemobiletools.gallery.activities
|
||||
|
||||
import android.os.Bundle
|
||||
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
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
open class SimpleActivity : BaseSimpleActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
protected fun copyMoveFilesTo(source: String, files: ArrayList<File>, isCopyOperation: Boolean, copyMoveListener: CopyMoveTask.CopyMoveListener) {
|
||||
val currPath = source.trimEnd('/')
|
||||
PickAlbumDialog(this, currPath) {
|
||||
val destinationFolder = File(it)
|
||||
if (currPath == it.trimEnd('/')) {
|
||||
toast(R.string.source_and_destination_same)
|
||||
return@PickAlbumDialog
|
||||
}
|
||||
|
||||
if (!destinationFolder.exists()) {
|
||||
toast(R.string.invalid_destination)
|
||||
return@PickAlbumDialog
|
||||
}
|
||||
|
||||
if (files.size == 1) {
|
||||
if (File(destinationFolder.absolutePath, files[0].name).exists()) {
|
||||
toast(R.string.name_taken)
|
||||
return@PickAlbumDialog
|
||||
}
|
||||
}
|
||||
|
||||
handleSAFDialog(destinationFolder) {
|
||||
if (isCopyOperation) {
|
||||
toast(R.string.copying)
|
||||
val pair = Pair<ArrayList<File>, File>(files, destinationFolder)
|
||||
CopyMoveTask(this, isCopyOperation, true, copyMoveListener).execute(pair)
|
||||
} else {
|
||||
if (isPathOnSD(currPath) || 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 destination = File(destinationFolder, file.name)
|
||||
if (!destination.exists() && file.renameTo(destination))
|
||||
updatedFiles.add(destination)
|
||||
}
|
||||
|
||||
scanFiles(updatedFiles) {
|
||||
runOnUiThread {
|
||||
copyMoveListener.copySucceeded(true, files.size * 2 == updatedFiles.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import android.net.Uri
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.support.v4.util.Pair
|
||||
import android.support.v4.view.ViewPager
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.Menu
|
||||
|
@ -27,7 +26,6 @@ import com.simplemobiletools.commons.extensions.*
|
|||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.adapters.MyPagerAdapter
|
||||
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
||||
import com.simplemobiletools.gallery.dialogs.PickAlbumDialog
|
||||
import com.simplemobiletools.gallery.dialogs.SaveAsDialog
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
||||
|
@ -190,56 +188,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private fun copyMoveTo(isCopyOperation: Boolean) {
|
||||
val currPath = File(getCurrentPath()).parent.trimEnd('/')
|
||||
val files = ArrayList<File>(1).apply { add(getCurrentFile()) }
|
||||
|
||||
PickAlbumDialog(this, currPath) {
|
||||
val destinationFolder = File(it)
|
||||
if (currPath == it.trimEnd('/')) {
|
||||
toast(R.string.source_and_destination_same)
|
||||
return@PickAlbumDialog
|
||||
}
|
||||
|
||||
if (!destinationFolder.exists()) {
|
||||
toast(R.string.invalid_destination)
|
||||
return@PickAlbumDialog
|
||||
}
|
||||
|
||||
if (files.size == 1) {
|
||||
if (File(destinationFolder.absolutePath, files[0].name).exists()) {
|
||||
toast(R.string.name_taken)
|
||||
return@PickAlbumDialog
|
||||
}
|
||||
}
|
||||
|
||||
handleSAFDialog(destinationFolder) {
|
||||
if (isCopyOperation) {
|
||||
toast(R.string.copying)
|
||||
val pair = Pair<ArrayList<File>, File>(files, destinationFolder)
|
||||
CopyMoveTask(this, isCopyOperation, true, copyMoveListener).execute(pair)
|
||||
} else {
|
||||
if (isPathOnSD(currPath) || 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 destination = File(destinationFolder, file.name)
|
||||
if (!destination.exists() && file.renameTo(destination))
|
||||
updatedFiles.add(destination)
|
||||
}
|
||||
|
||||
scanFiles(updatedFiles) {
|
||||
runOnUiThread {
|
||||
copyMoveListener.copySucceeded(true, files.size * 2 == updatedFiles.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
copyMoveFilesTo(currPath, files, isCopyOperation, copyMoveListener)
|
||||
}
|
||||
|
||||
private val copyMoveListener = object : CopyMoveTask.CopyMoveListener {
|
||||
|
|
Loading…
Reference in a new issue