From 2dc18e716693e5c465f30a3de8254b7ea194308f Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 27 Jun 2018 20:46:14 +0200 Subject: [PATCH] add some additional menu items for restoring recycle bin items --- .../gallery/activities/MediaActivity.kt | 19 ++++++++++++++++--- .../gallery/activities/SettingsActivity.kt | 3 ++- .../gallery/adapters/DirectoryAdapter.kt | 12 ++++++++---- .../gallery/adapters/MediaAdapter.kt | 9 +++++++++ .../gallery/extensions/Activity.kt | 12 +++++++++++- app/src/main/res/menu/cab_media.xml | 4 ++++ app/src/main/res/menu/menu_media.xml | 4 ++++ 7 files changed, 54 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 57739f38c..7feb65b33 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -200,6 +200,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { findItem(R.id.empty_recycle_bin).isVisible = mPath == RECYCLE_BIN findItem(R.id.empty_disable_recycle_bin).isVisible = mPath == RECYCLE_BIN + findItem(R.id.restore_all_files).isVisible = mPath == RECYCLE_BIN findItem(R.id.folder_view).isVisible = mShowAll findItem(R.id.open_camera).isVisible = mShowAll @@ -224,6 +225,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { R.id.filter -> showFilterMediaDialog() R.id.empty_recycle_bin -> emptyRecycleBin() R.id.empty_disable_recycle_bin -> emptyAndDisableRecycleBin() + R.id.restore_all_files -> restoreAllFiles() R.id.toggle_filename -> toggleFilenameVisibility() R.id.open_camera -> launchCamera() R.id.folder_view -> switchToFolderView() @@ -424,13 +426,24 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun emptyRecycleBin() { - emptyTheRecycleBin { - finish() + showRecycleBinEmptyingDialog { + emptyTheRecycleBin { + finish() + } } } private fun emptyAndDisableRecycleBin() { - emptyAndDisableTheRecycleBin { + showRecycleBinEmptyingDialog { + emptyAndDisableTheRecycleBin { + finish() + } + } + } + + private fun restoreAllFiles() { + val paths = mMedia.filter { it is Medium }.map { (it as Medium).path } as ArrayList + restoreRecycleBinPaths(paths) { finish() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt index 7eaf6c5d7..42d8d09de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.dialogs.ManageExtendedDetailsDialog import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.emptyTheRecycleBin import com.simplemobiletools.gallery.extensions.galleryDB +import com.simplemobiletools.gallery.extensions.showRecycleBinEmptyingDialog import com.simplemobiletools.gallery.helpers.ROTATE_BY_ASPECT_RATIO import com.simplemobiletools.gallery.helpers.ROTATE_BY_DEVICE_ROTATION import com.simplemobiletools.gallery.helpers.ROTATE_BY_SYSTEM_SETTING @@ -435,7 +436,7 @@ class SettingsActivity : SimpleActivity() { if (mRecycleBinContentSize == 0L) { toast(R.string.recycle_bin_empty) } else { - ConfirmationDialog(this, "", R.string.empty_recycle_bin_confirmation, R.string.yes, R.string.no) { + showRecycleBinEmptyingDialog { emptyTheRecycleBin() mRecycleBinContentSize = 0L settings_empty_recycle_bin_size.text = 0L.formatSize() 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 12283589b..d1f50a9a8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -214,14 +214,18 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList 0 + findItem(R.id.cab_restore_recycle_bin_files).isVisible = getSelectedPaths().all { it.startsWith(activity.filesDir.toString()) } checkHideBtnVisibility(this) checkFavoriteBtnVisibility(this) @@ -128,6 +129,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList toggleFileVisibility(false) R.id.cab_add_to_favorites -> toggleFavorites(true) R.id.cab_remove_from_favorites -> toggleFavorites(false) + R.id.cab_restore_recycle_bin_files -> restoreFiles() R.id.cab_share -> shareMedia() R.id.cab_copy_to -> copyMoveTo(true) R.id.cab_move_to -> copyMoveTo(false) @@ -244,6 +246,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList, callback out?.close() } } - callback() + + runOnUiThread { + callback() + } }.start() } @@ -254,3 +258,9 @@ fun BaseSimpleActivity.emptyAndDisableTheRecycleBin(callback: () -> Unit) { } }.start() } + +fun BaseSimpleActivity.showRecycleBinEmptyingDialog(callback: () -> Unit) { + ConfirmationDialog(this, "", R.string.empty_recycle_bin_confirmation, R.string.yes, R.string.no) { + callback() + } +} diff --git a/app/src/main/res/menu/cab_media.xml b/app/src/main/res/menu/cab_media.xml index 748d13541..60b2735c3 100644 --- a/app/src/main/res/menu/cab_media.xml +++ b/app/src/main/res/menu/cab_media.xml @@ -56,6 +56,10 @@ android:icon="@drawable/ic_star_on" android:title="@string/remove_from_favorites" app:showAsAction="ifRoom"/> + +