From 9a0cde9796f4a105cebb99596137d1e49e1fe0b5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 1 Apr 2017 16:58:17 +0200 Subject: [PATCH] remove the leftovers of CopyDialog --- app/build.gradle | 2 +- .../gallery/activities/ViewPagerActivity.kt | 77 ++++++++++++--- .../gallery/adapters/DirectoryAdapter.kt | 18 ---- .../gallery/adapters/MediaAdapter.kt | 19 ---- .../gallery/dialogs/CopyDialog.kt | 99 ------------------- app/src/main/res/layout/dialog_copy_move.xml | 49 --------- 6 files changed, 64 insertions(+), 200 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt delete mode 100644 app/src/main/res/layout/dialog_copy_move.xml diff --git a/app/build.gradle b/app/build.gradle index 7494f0499..cd49f84cc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index ff439cc8e..f9bc8a66e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -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() - 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(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, 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, File>(files, destinationFolder) + CopyMoveTask(this, true, true, copyMoveListener).execute(pair) + } + } else { + val updatedFiles = ArrayList(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() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 296b42cc9..20d6c0ff6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -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, val files = ArrayList() 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() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt deleted file mode 100644 index 49a9a6a15..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt +++ /dev/null @@ -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, 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, 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, File>(files, destinationDir) - CopyMoveTask(activity, true, context.config.treeUri, true, copyMoveListener).execute(pair) - dismiss() - } - } else { - val updatedFiles = ArrayList(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() - } -} diff --git a/app/src/main/res/layout/dialog_copy_move.xml b/app/src/main/res/layout/dialog_copy_move.xml deleted file mode 100644 index 2f67e7a63..000000000 --- a/app/src/main/res/layout/dialog_copy_move.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - -