add a checkbox for skiping confirmation dialog at delete in a session

This commit is contained in:
tibbi 2017-10-19 21:03:19 +02:00
parent 5441457611
commit 0c408f6cf0
23 changed files with 117 additions and 14 deletions

View file

@ -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,22 +591,36 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
super.onActivityResult(requestCode, resultCode, resultData)
}
private fun checkDeleteConfirmation() {
if (mSkipConfirmationDialog) {
deleteConfirmed()
} else {
askConfirmDelete()
}
}
private fun askConfirmDelete() {
ConfirmationDialog(this) {
DeleteWithRememberDialog(this) {
mSkipConfirmationDialog = it
deleteConfirmed()
}
}
private fun deleteConfirmed() {
deleteFileBg(File(getCurrentMedia()[mPos].path)) {
reloadViewPager()
}
}
}
private fun isDirEmpty(media: ArrayList<Medium>): Boolean {
return if (media.isEmpty()) {
deleteDirectoryIfEmpty()
finish()
true
} else
} else {
false
}
}
private fun renameFile() {
RenameItemDialog(this, getCurrentPath()) {

View file

@ -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<Medium>,
val multiSelector = MultiSelector()
val config = activity.config
val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST
var skipConfirmationDialog = false
var actMode: ActionMode? = null
var itemViews = SparseArray<View>()
@ -83,7 +84,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
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<Medium>,
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<Medium>,
.forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) }
itemViews = newItems
actMode?.finish()
}
}

View file

@ -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)
}
}

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/delete_remember_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/big_margin"
android:paddingRight="@dimen/big_margin"
android:paddingTop="@dimen/big_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/delete_remember_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_margin"
android:text="@string/proceed_with_deletion"
android:textSize="@dimen/bigger_text_size"/>
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/delete_remember_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/delete_remember_title"
android:text="@string/do_not_ask_again"/>
</RelativeLayout>

View file

@ -25,6 +25,7 @@
<string name="set_as">Set as</string>
<string name="volume">Volume</string>
<string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Nastavit jako</string>
<string name="volume">Volume</string>
<string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Festlegen als</string>
<string name="volume">Lautstärke</string>
<string name="brightness">Helligkeit</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Medienfilter</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Establecer como</string>
<string name="volume">Volume</string>
<string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Aseta</string>
<string name="volume">Äänenvoimakkuus</string>
<string name="brightness">Kirkkaus</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Suodata media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Définir comme</string>
<string name="volume">Volume</string>
<string name="brightness">Luminosité</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filtrer les médias</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Set as</string>
<string name="volume">Volume</string>
<string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Imposta come</string>
<string name="volume">Volume</string>
<string name="brightness">Luminosità</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filtra i media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">他で使う</string>
<string name="volume">音量</string>
<string name="brightness">明るさ</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">表示メディア種</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Ustaw jako</string>
<string name="volume">Głośność</string>
<string name="brightness">Jasność</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filtruj multimedia</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Set as</string>
<string name="volume">Volume</string>
<string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Definir como</string>
<string name="volume">Volume</string>
<string name="brightness">Brilho</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filtrar multimédia</string>

View file

@ -22,9 +22,10 @@
<string name="change_cover_image">Изменить обложку</string>
<string name="select_photo">Выбрать изображение</string>
<string name="use_default">Использовать по умолчанию</string>
<string name="set_as">Установить как...</string>
<string name="set_as">Установить как</string>
<string name="volume">Громкость</string>
<string name="brightness">Яркость</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Фильтр медиа</string>
@ -84,7 +85,7 @@
<string name="set_as_wallpaper_failed">Установить не удалось</string>
<string name="set_as_wallpaper_with">Установить в качестве обоев в:</string>
<string name="no_capable_app_found">Приложение не найдено</string>
<string name="setting_wallpaper">Установка обоев&#8230;</string>
<string name="setting_wallpaper">Установка обоев</string>
<string name="wallpaper_set_successfully">Обои успешно установлены</string>
<string name="portrait_aspect_ratio">Формат изображения</string>
<string name="landscape_aspect_ratio">Пейзажное соотношение сторон</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Nastaviť ako</string>
<string name="volume">Hlasitosť</string>
<string name="brightness">Jas</string>
<string name="do_not_ask_again">Nepýtať sa už v tomto spustení</string>
<!-- Filter -->
<string name="filter_media">Filter médií</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Ange som</string>
<string name="volume">Volym</string>
<string name="brightness">Ljusstyrka</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filtrera media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Set as</string>
<string name="volume">Volume</string>
<string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">设置为</string>
<string name="volume">音量</string>
<string name="brightness">亮度</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">設為</string>
<string name="volume">音量</string>
<string name="brightness">亮度</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">篩選媒體檔案</string>

View file

@ -25,6 +25,7 @@
<string name="set_as">Set as</string>
<string name="volume">Volume</string>
<string name="brightness">Brightness</string>
<string name="do_not_ask_again">Do not ask again in this session</string>
<!-- Filter -->
<string name="filter_media">Filter media</string>