From f5248d5d53dbd2da73b9f12d5034e189874947c5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 12 Dec 2018 19:29:05 +0100 Subject: [PATCH] add a checkbox for grouping direct subfolders at the Change View dialog --- app/build.gradle | 2 +- .../gallery/pro/activities/MainActivity.kt | 10 +--- .../pro/dialogs/ChangeViewTypeDialog.kt | 38 +++++++++++++ .../gallery/pro/helpers/Config.kt | 4 ++ .../gallery/pro/helpers/Constants.kt | 1 + .../res/layout/dialog_change_view_type.xml | 54 +++++++++++++++++++ 6 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt create mode 100644 app/src/main/res/layout/dialog_change_view_type.xml diff --git a/app/build.gradle b/app/build.gradle index 818617211..f76beb22c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.5.15' + implementation 'com.simplemobiletools:commons:5.5.16' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'androidx.multidex:multidex:2.0.0' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 2ac01140e..ec95f9935 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -19,11 +19,9 @@ import androidx.core.view.MenuItemCompat import androidx.recyclerview.widget.RecyclerView import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog -import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.FileDirItem -import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.Release import com.simplemobiletools.commons.views.MyGridLayoutManager import com.simplemobiletools.commons.views.MyRecyclerView @@ -32,6 +30,7 @@ import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.adapters.DirectoryAdapter import com.simplemobiletools.gallery.pro.databases.GalleryDatabase import com.simplemobiletools.gallery.pro.dialogs.ChangeSortingDialog +import com.simplemobiletools.gallery.pro.dialogs.ChangeViewTypeDialog import com.simplemobiletools.gallery.pro.dialogs.FilterMediaDialog import com.simplemobiletools.gallery.pro.extensions.* import com.simplemobiletools.gallery.pro.helpers.* @@ -451,12 +450,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } private fun changeViewType() { - val items = arrayListOf( - RadioItem(VIEW_TYPE_GRID, getString(R.string.grid)), - RadioItem(VIEW_TYPE_LIST, getString(R.string.list))) - - RadioGroupDialog(this, items, config.viewTypeFolders) { - config.viewTypeFolders = it as Int + ChangeViewTypeDialog(this) { invalidateOptionsMenu() setupLayoutManager() val dirs = getCurrentlyDisplayedDirs() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt new file mode 100644 index 000000000..b534b5c3e --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt @@ -0,0 +1,38 @@ +package com.simplemobiletools.gallery.pro.dialogs + +import android.view.View +import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.gallery.pro.R +import com.simplemobiletools.gallery.pro.extensions.config +import com.simplemobiletools.gallery.pro.helpers.VIEW_TYPE_GRID +import com.simplemobiletools.gallery.pro.helpers.VIEW_TYPE_LIST +import kotlinx.android.synthetic.main.dialog_change_view_type.view.* + +class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val callback: () -> Unit) { + private var view: View + private var config = activity.config + + init { + view = activity.layoutInflater.inflate(R.layout.dialog_change_view_type, null).apply { + val viewToCheck = if (config.viewTypeFolders == VIEW_TYPE_GRID) change_view_type_dialog_radio_grid.id else change_view_type_dialog_radio_list.id + change_view_type_dialog_radio.check(viewToCheck) + change_view_type_dialog_group_direct_subfolders.isChecked = config.groupDirectSubfolders + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this) + } + } + + private fun dialogConfirmed() { + val viewType = if (view.change_view_type_dialog_radio.checkedRadioButtonId == view.change_view_type_dialog_radio_grid.id) VIEW_TYPE_GRID else VIEW_TYPE_LIST + config.viewTypeFolders = viewType + config.groupDirectSubfolders = view.change_view_type_dialog_group_direct_subfolders.isChecked + callback() + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt index e25a4073d..3016cf54f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt @@ -423,4 +423,8 @@ class Config(context: Context) : BaseConfig(context) { var lastEditorCropOtherAspectRatioY: Int get() = prefs.getInt(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y, 1) set(lastEditorCropOtherAspectRatioY) = prefs.edit().putInt(LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y, lastEditorCropOtherAspectRatioY).apply() + + var groupDirectSubfolders: Boolean + get() = prefs.getBoolean(GROUP_DIRECT_SUBFOLDERS, false) + set(groupDirectSubfolders) = prefs.edit().putBoolean(GROUP_DIRECT_SUBFOLDERS, groupDirectSubfolders).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index f868a1747..03d5b8436 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -71,6 +71,7 @@ const val ALLOW_DOWN_GESTURE = "allow_down_gesture" const val LAST_EDITOR_CROP_ASPECT_RATIO = "last_editor_crop_aspect_ratio" const val LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_X = "last_editor_crop_other_aspect_ratio_x" const val LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y = "last_editor_crop_other_aspect_ratio_y" +const val GROUP_DIRECT_SUBFOLDERS = "group_direct_subfolders" // slideshow const val SLIDESHOW_INTERVAL = "slideshow_interval" diff --git a/app/src/main/res/layout/dialog_change_view_type.xml b/app/src/main/res/layout/dialog_change_view_type.xml new file mode 100644 index 000000000..003692bb9 --- /dev/null +++ b/app/src/main/res/layout/dialog_change_view_type.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + +