From c2178d467e7d1af4fc3e4579ac799dd6676cfc0e Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 24 Dec 2018 12:33:44 +0100 Subject: [PATCH] reuse the same ChangeViewType dialog at media view too --- .../gallery/pro/activities/MainActivity.kt | 2 +- .../gallery/pro/activities/MediaActivity.kt | 14 ++------- .../pro/dialogs/ChangeViewTypeDialog.kt | 30 +++++++++++++++---- 3 files changed, 28 insertions(+), 18 deletions(-) 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 ad9ef43f1..f1f33fd10 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 @@ -459,7 +459,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } private fun changeViewType() { - ChangeViewTypeDialog(this) { + ChangeViewTypeDialog(this, true) { invalidateOptionsMenu() setupLayoutManager() directories_grid.adapter = null diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 536e05245..8eaa3ccf4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -22,23 +22,18 @@ import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.transition.Transition import com.simplemobiletools.commons.dialogs.ConfirmationDialog -import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.commons.models.FileDirItem -import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.views.MyGridLayoutManager import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.adapters.MediaAdapter import com.simplemobiletools.gallery.pro.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.pro.databases.GalleryDatabase -import com.simplemobiletools.gallery.pro.dialogs.ChangeGroupingDialog -import com.simplemobiletools.gallery.pro.dialogs.ChangeSortingDialog -import com.simplemobiletools.gallery.pro.dialogs.ExcludeFolderDialog -import com.simplemobiletools.gallery.pro.dialogs.FilterMediaDialog +import com.simplemobiletools.gallery.pro.dialogs.* import com.simplemobiletools.gallery.pro.extensions.* import com.simplemobiletools.gallery.pro.helpers.* import com.simplemobiletools.gallery.pro.interfaces.DirectoryDao @@ -493,12 +488,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } 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.viewTypeFiles) { - config.viewTypeFiles = it as Int + ChangeViewTypeDialog(this, false) { invalidateOptionsMenu() setupLayoutManager() media_grid.adapter = null 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 index b534b5c3e..858101b04 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ChangeViewTypeDialog.kt @@ -3,6 +3,7 @@ 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.beVisibleIf import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.extensions.config @@ -10,15 +11,29 @@ 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) { +class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val fromFoldersView: Boolean, 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 + val viewToCheck = if (fromFoldersView) { + if (config.viewTypeFolders == VIEW_TYPE_GRID) { + change_view_type_dialog_radio_grid.id + } else { + change_view_type_dialog_radio_list.id + } + } else if (config.viewTypeFiles == 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 + change_view_type_dialog_group_direct_subfolders.apply { + beVisibleIf(fromFoldersView) + isChecked = config.groupDirectSubfolders + } } AlertDialog.Builder(activity) @@ -31,8 +46,13 @@ class ChangeViewTypeDialog(val activity: BaseSimpleActivity, val callback: () -> 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 + if (fromFoldersView) { + config.viewTypeFolders = viewType + config.groupDirectSubfolders = view.change_view_type_dialog_group_direct_subfolders.isChecked + } else { + config.viewTypeFiles = viewType + } + callback() } }