remove the leftovers of CopyDialog

This commit is contained in:
tibbi 2017-04-01 16:58:17 +02:00
parent 627ddeea0a
commit 9a0cde9796
6 changed files with 64 additions and 200 deletions

View file

@ -32,7 +32,7 @@ android {
}
dependencies {
compile 'com.simplemobiletools:commons:2.14.8'
compile 'com.simplemobiletools:commons:2.14.9'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View file

@ -13,6 +13,7 @@ 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
@ -26,7 +27,7 @@ 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.CopyDialog
import com.simplemobiletools.gallery.dialogs.PickAlbumDialog
import com.simplemobiletools.gallery.dialogs.SaveAsDialog
import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.fragments.PhotoFragment
@ -148,8 +149,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
when (item.itemId) {
R.id.menu_set_as_wallpaper -> setAsWallpaper(getCurrentFile())
R.id.cab_copy_to -> copyTo()
R.id.cab_move_to -> moveTo()
R.id.menu_copy_to -> copyTo()
R.id.menu_move_to -> moveTo()
R.id.menu_open_with -> openWith(getCurrentFile())
R.id.menu_share -> shareMedium(getCurrentMedium()!!)
R.id.menu_delete -> askConfirmDelete()
@ -178,27 +179,75 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
}
}
private fun displayCopyDialog() {
val files = ArrayList<File>()
files.add(getCurrentFile())
CopyDialog(this, files, object : CopyMoveTask.CopyMoveListener {
override fun copySucceeded(deleted: Boolean, copiedAll: Boolean) {
if (deleted) {
private fun copyTo() {
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()
toast(if (copiedAll) R.string.moving_success else R.string.moving_success_partial)
} else {
toast(if (copiedAll) R.string.copying_success else R.string.copying_success_partial)
}
}
override fun copyFailed() {
toast(R.string.copy_move_failed)
}
})
}
private fun copyTo() {
val currPath = File(getCurrentPath()).parent.trimEnd('/')
val files = ArrayList<File>(1).apply { add(getCurrentFile()) }
val isCopyOperation = true
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, false, 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, true, 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)
}
}
}
}
}
}
}
private fun moveTo() {

View file

@ -9,7 +9,6 @@ import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback
import com.bignerdranch.android.multiselector.MultiSelector
import com.bignerdranch.android.multiselector.SwappingHolder
import com.bumptech.glide.Glide
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.dialogs.RenameItemDialog
@ -19,7 +18,6 @@ import com.simplemobiletools.commons.extensions.needsStupidWritePermissions
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.dialogs.CopyDialog
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.models.Directory
@ -236,22 +234,6 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
val dir = File(dirs[it].path)
files.addAll(dir.listFiles().filter { it.isFile && it.isImageVideoGif() })
}
CopyDialog(activity, files, object : CopyMoveTask.CopyMoveListener {
override fun copySucceeded(deleted: Boolean, copiedAll: Boolean) {
if (deleted) {
activity.toast(if (copiedAll) R.string.moving_success else R.string.moving_success_partial)
} else {
activity.toast(if (copiedAll) R.string.copying_success else R.string.copying_success_partial)
}
listener?.refreshItems()
actMode?.finish()
}
override fun copyFailed() {
activity.toast(R.string.copy_move_failed)
}
})
}
private fun copyTo() {

View file

@ -9,15 +9,12 @@ import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback
import com.bignerdranch.android.multiselector.MultiSelector
import com.bignerdranch.android.multiselector.SwappingHolder
import com.bumptech.glide.Glide
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.dialogs.RenameItemDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.dialogs.CopyDialog
import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.models.Medium
import kotlinx.android.synthetic.main.photo_video_item.view.*
@ -144,22 +141,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val files = ArrayList<File>()
val positions = multiSelector.selectedPositions
positions.forEach { files.add(File(media[it].path)) }
CopyDialog(activity, files, object : CopyMoveTask.CopyMoveListener {
override fun copySucceeded(deleted: Boolean, copiedAll: Boolean) {
if (deleted) {
activity.toast(if (copiedAll) R.string.moving_success else R.string.moving_success_partial)
} else {
activity.toast(if (copiedAll) R.string.copying_success else R.string.copying_success_partial)
}
listener?.refreshItems()
actMode?.finish()
}
override fun copyFailed() {
activity.toast(R.string.copy_move_failed)
}
})
}
private fun copyTo() {

View file

@ -1,99 +0,0 @@
package com.simplemobiletools.gallery.dialogs
import android.support.v4.util.Pair
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.extensions.config
import kotlinx.android.synthetic.main.dialog_copy_move.view.*
import java.io.File
import java.util.*
class CopyDialog(val activity: SimpleActivity, val files: ArrayList<File>, val copyMoveListener: CopyMoveTask.CopyMoveListener) {
companion object {
lateinit var view: View
}
init {
view = LayoutInflater.from(activity).inflate(R.layout.dialog_copy_move, null)
val sourcePath = files[0].parent.trimEnd('/')
var destinationPath = ""
view.destination.setOnClickListener {
PickAlbumDialog(activity, sourcePath) {
destinationPath = it
view.destination.text = activity.humanizePath(it)
}
}
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this, R.string.copy_move)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
if (destinationPath == context.resources.getString(R.string.select_destination) || destinationPath.isEmpty()) {
context.toast(R.string.please_select_destination)
return@setOnClickListener
}
if (sourcePath == destinationPath.trimEnd('/')) {
context.toast(R.string.source_and_destination_same)
return@setOnClickListener
}
val destinationDir = File(destinationPath)
if (!destinationDir.exists()) {
context.toast(R.string.invalid_destination)
return@setOnClickListener
}
if (files.size == 1) {
if (File(destinationPath, files[0].name).exists()) {
context.toast(R.string.name_taken)
return@setOnClickListener
}
}
activity.handleSAFDialog(destinationDir) {
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) {
context.toast(R.string.copying)
val pair = Pair<ArrayList<File>, File>(files, destinationDir)
CopyMoveTask(activity, false, context.config.treeUri, true, copyMoveListener).execute(pair)
dismiss()
} else {
if (context.isPathOnSD(sourcePath) || context.isPathOnSD(destinationPath)) {
activity.handleSAFDialog(files[0]) {
context.toast(R.string.moving)
val pair = Pair<ArrayList<File>, File>(files, destinationDir)
CopyMoveTask(activity, true, context.config.treeUri, true, copyMoveListener).execute(pair)
dismiss()
}
} else {
val updatedFiles = ArrayList<File>(files.size * 2)
updatedFiles.addAll(files)
for (file in files) {
val destination = File(destinationDir, file.name)
if (!destination.exists() && file.renameTo(destination))
updatedFiles.add(destination)
}
context.scanFiles(updatedFiles) {
activity.runOnUiThread {
copyMoveListener.copySucceeded(true, files.size * 2 == updatedFiles.size)
dismiss()
}
}
}
}
}
})
}
view.destination.performClick()
}
}

View file

@ -1,49 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/destination_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/destination"
android:textSize="@dimen/smaller_text_size"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:layout_marginLeft="@dimen/activity_margin"
android:paddingBottom="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
android:paddingTop="@dimen/small_margin"
android:text="@string/click_select_destination"/>
<RadioGroup
android:id="@+id/dialog_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkedButton="@+id/dialog_radio_copy">
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/dialog_radio_copy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/medium_margin"
android:text="@string/copy"/>
<com.simplemobiletools.commons.views.MyCompatRadioButton
android:id="@+id/dialog_radio_move"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/move"/>
</RadioGroup>
</LinearLayout>