From 0c408f6cf07537eccc68ef145525acb1b3872bcd Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 19 Oct 2017 21:03:19 +0200 Subject: [PATCH] add a checkbox for skiping confirmation dialog at delete in a session --- .../gallery/activities/ViewPagerActivity.kt | 29 ++++++++++++++----- .../gallery/adapters/MediaAdapter.kt | 25 ++++++++++++---- .../dialogs/DeleteWithRememberDialog.kt | 28 ++++++++++++++++++ .../layout/dialog_delete_with_remember.xml | 26 +++++++++++++++++ app/src/main/res/values-ca/strings.xml | 1 + app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-fi/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values-pt-rBR/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 5 ++-- app/src/main/res/values-sk/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 23 files changed, 117 insertions(+), 14 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/DeleteWithRememberDialog.kt create mode 100644 app/src/main/res/layout/dialog_delete_with_remember.xml 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 7aacc2376..68a5908c3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -23,7 +23,6 @@ import android.support.v4.view.ViewPager import android.util.DisplayMetrics import android.view.* import android.view.animation.DecelerateInterpolator -import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* @@ -31,6 +30,7 @@ import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.MediaActivity.Companion.mMedia import com.simplemobiletools.gallery.adapters.MyPagerAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask +import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.dialogs.SaveAsDialog import com.simplemobiletools.gallery.dialogs.SlideshowDialog import com.simplemobiletools.gallery.extensions.* @@ -53,6 +53,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private var mPos = -1 private var mShowAll = false private var mIsSlideshowActive = false + private var mSkipConfirmationDialog = false private var mRotationDegrees = 0f private var mLastHandledOrientation = 0 private var mPrevHashcode = 0 @@ -250,7 +251,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.id.menu_unhide -> toggleFileVisibility(false) R.id.menu_share_1 -> shareMedium(getCurrentMedium()!!) R.id.menu_share_2 -> shareMedium(getCurrentMedium()!!) - R.id.menu_delete -> askConfirmDelete() + R.id.menu_delete -> checkDeleteConfirmation() R.id.menu_rename -> renameFile() R.id.menu_edit -> openFileEditor(getCurrentFile()) R.id.menu_properties -> showProperties() @@ -590,11 +591,24 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View super.onActivityResult(requestCode, resultCode, resultData) } + private fun checkDeleteConfirmation() { + if (mSkipConfirmationDialog) { + deleteConfirmed() + } else { + askConfirmDelete() + } + } + private fun askConfirmDelete() { - ConfirmationDialog(this) { - deleteFileBg(File(getCurrentMedia()[mPos].path)) { - reloadViewPager() - } + DeleteWithRememberDialog(this) { + mSkipConfirmationDialog = it + deleteConfirmed() + } + } + + private fun deleteConfirmed() { + deleteFileBg(File(getCurrentMedia()[mPos].path)) { + reloadViewPager() } } @@ -603,8 +617,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View deleteDirectoryIfEmpty() finish() true - } else + } else { false + } } private fun renameFile() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index f01a50a52..875609abd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -10,13 +10,13 @@ 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.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.beGone import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity +import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST import com.simplemobiletools.gallery.models.Medium @@ -30,6 +30,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, val multiSelector = MultiSelector() val config = activity.config val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST + var skipConfirmationDialog = false var actMode: ActionMode? = null var itemViews = SparseArray() @@ -83,7 +84,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, R.id.cab_copy_to -> copyMoveTo(true) R.id.cab_move_to -> copyMoveTo(false) R.id.cab_select_all -> selectAll() - R.id.cab_delete -> askConfirmDelete() + R.id.cab_delete -> checkDeleteConfirmation() else -> return false } return true @@ -204,12 +205,25 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, updateTitle(cnt) } - private fun askConfirmDelete() { - ConfirmationDialog(activity) { - deleteFiles() + private fun checkDeleteConfirmation() { + if (skipConfirmationDialog) { + deleteConfirmed() + } else { + askConfirmDelete() } } + private fun askConfirmDelete() { + DeleteWithRememberDialog(activity) { + skipConfirmationDialog = it + deleteConfirmed() + } + } + + private fun deleteConfirmed() { + deleteFiles() + } + private fun getCurrentFile() = File(media[selectedPositions.first()].path) private fun deleteFiles() { @@ -244,6 +258,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) } itemViews = newItems + actMode?.finish() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/DeleteWithRememberDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/DeleteWithRememberDialog.kt new file mode 100644 index 000000000..2a5a91d24 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/DeleteWithRememberDialog.kt @@ -0,0 +1,28 @@ +package com.simplemobiletools.gallery.dialogs + +import android.content.Context +import android.support.v7.app.AlertDialog +import android.view.LayoutInflater +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.gallery.R +import kotlinx.android.synthetic.main.dialog_delete_with_remember.view.* + +class DeleteWithRememberDialog(val context: Context, val callback: (Boolean) -> Unit) { + var dialog: AlertDialog + val view = LayoutInflater.from(context).inflate(R.layout.dialog_delete_with_remember, null) + + init { + val builder = AlertDialog.Builder(context) + .setPositiveButton(R.string.yes, { dialog, which -> dialogConfirmed() }) + .setNegativeButton(R.string.no, null) + + dialog = builder.create().apply { + context.setupDialogStuff(view, this) + } + } + + private fun dialogConfirmed() { + dialog.dismiss() + callback(view.delete_remember_checkbox.isChecked) + } +} diff --git a/app/src/main/res/layout/dialog_delete_with_remember.xml b/app/src/main/res/layout/dialog_delete_with_remember.xml new file mode 100644 index 000000000..df4ea5519 --- /dev/null +++ b/app/src/main/res/layout/dialog_delete_with_remember.xml @@ -0,0 +1,26 @@ + + + + + + + + diff --git a/app/src/main/res/values-ca/strings.xml b/app/src/main/res/values-ca/strings.xml index f4ee43fa2..fac61048c 100644 --- a/app/src/main/res/values-ca/strings.xml +++ b/app/src/main/res/values-ca/strings.xml @@ -25,6 +25,7 @@ Set as Volume Brightness + Do not ask again in this session Filter media diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index b49c84832..c6ba60327 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -25,6 +25,7 @@ Nastavit jako Volume Brightness + Do not ask again in this session Filter media diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 137d5a5f0..a3cd8cbdb 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -25,6 +25,7 @@ Festlegen als Lautstärke Helligkeit + Do not ask again in this session Medienfilter diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 25cb4c167..8a364e187 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -25,6 +25,7 @@ Establecer como Volume Brightness + Do not ask again in this session Filter media diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index fad746e5d..a4edf365a 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -25,6 +25,7 @@ Aseta Äänenvoimakkuus Kirkkaus + Do not ask again in this session Suodata media diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 50844b18b..3ae6e9716 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -25,6 +25,7 @@ Définir comme Volume Luminosité + Do not ask again in this session Filtrer les médias diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index f6b77cf01..b04301122 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -25,6 +25,7 @@ Set as Volume Brightness + Do not ask again in this session Filter media diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index a70c5ae7f..2b187ae34 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -25,6 +25,7 @@ Imposta come Volume Luminosità + Do not ask again in this session Filtra i media diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index c85011c6e..93b6e616e 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -25,6 +25,7 @@ 他で使う 音量 明るさ + Do not ask again in this session 表示メディア種 diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index fd9567d52..a148c3a0e 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -25,6 +25,7 @@ Ustaw jako Głośność Jasność + Do not ask again in this session Filtruj multimedia diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index e70507a49..30662f1d9 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -25,6 +25,7 @@ Set as Volume Brightness + Do not ask again in this session Filter media diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 56b0b7819..51ba03b5c 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -25,6 +25,7 @@ Definir como Volume Brilho + Do not ask again in this session Filtrar multimédia diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 35520e679..34ffc082c 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -22,9 +22,10 @@ Изменить обложку Выбрать изображение Использовать по умолчанию - Установить как... + Установить как… Громкость Яркость + Do not ask again in this session Фильтр медиа @@ -84,7 +85,7 @@ Установить не удалось Установить в качестве обоев в: Приложение не найдено - Установка обоев… + Установка обоев… Обои успешно установлены Формат изображения Пейзажное соотношение сторон diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 7844e7df6..50eeece79 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -25,6 +25,7 @@ Nastaviť ako Hlasitosť Jas + Nepýtať sa už v tomto spustení Filter médií diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 2c05e7437..2ba4fc87d 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -25,6 +25,7 @@ Ange som Volym Ljusstyrka + Do not ask again in this session Filtrera media diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 350a1cc73..6263ca620 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -25,6 +25,7 @@ Set as Volume Brightness + Do not ask again in this session Filter media diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 299b82fe9..b43f3c294 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -25,6 +25,7 @@ 设置为 音量 亮度 + Do not ask again in this session Filter media diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 1f454c722..1ec71fd20 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -25,6 +25,7 @@ 設為 音量 亮度 + Do not ask again in this session 篩選媒體檔案 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f4ee43fa2..fac61048c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,6 +25,7 @@ Set as Volume Brightness + Do not ask again in this session Filter media