From c618af4e95fdc4dcd9ccb93f272487a91655e58a Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 29 Jun 2018 16:04:11 +0200 Subject: [PATCH] create the dialog for customizing shown bottom actions --- .../gallery/activities/SettingsActivity.kt | 10 +- .../dialogs/ManageBottomActionsDialog.kt | 65 ++++++++++++ .../dialogs/ManageExtendedDetailsDialog.kt | 2 +- .../gallery/helpers/Config.kt | 2 +- .../gallery/helpers/Constants.kt | 2 + .../layout/dialog_manage_bottom_actions.xml | 98 +++++++++++++++++++ 6 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageBottomActionsDialog.kt create mode 100644 app/src/main/res/layout/dialog_manage_bottom_actions.xml 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 632a3ff51..db12b773a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -12,11 +12,13 @@ import com.simplemobiletools.commons.helpers.SHOW_ALL_TABS import com.simplemobiletools.commons.helpers.sumByLong import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.dialogs.ManageBottomActionsDialog 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.DEFAULT_BOTTOM_ACTIONS 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 @@ -419,7 +421,13 @@ class SettingsActivity : SimpleActivity() { private fun setupManageBottomActions() { settings_manage_bottom_actions_holder.beVisibleIf(config.bottomActions) settings_manage_bottom_actions_holder.setOnClickListener { - + ManageBottomActionsDialog(this) { + if (config.visibleBottomActions == 0) { + settings_bottom_actions_holder.callOnClick() + config.bottomActions = false + config.visibleBottomActions = DEFAULT_BOTTOM_ACTIONS + } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageBottomActionsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageBottomActionsDialog.kt new file mode 100644 index 000000000..d21801eba --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageBottomActionsDialog.kt @@ -0,0 +1,65 @@ +package com.simplemobiletools.gallery.dialogs + +import android.support.v7.app.AlertDialog +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.helpers.* +import kotlinx.android.synthetic.main.dialog_manage_bottom_actions.view.* + +class ManageBottomActionsDialog(val activity: BaseSimpleActivity, val callback: (result: Int) -> Unit) { + private var view = activity.layoutInflater.inflate(R.layout.dialog_manage_bottom_actions, null) + + init { + val actions = activity.config.visibleBottomActions + view.apply { + manage_bottom_actions_toggle_favorite.isChecked = actions and BOTTOM_ACTION_TOGGLE_FAVORITE != 0 + manage_bottom_actions_edit.isChecked = actions and BOTTOM_ACTION_EDIT != 0 + manage_bottom_actions_share.isChecked = actions and BOTTOM_ACTION_SHARE != 0 + manage_bottom_actions_delete.isChecked = actions and BOTTOM_ACTION_DELETE != 0 + manage_bottom_actions_rotate.isChecked = actions and BOTTOM_ACTION_ROTATE != 0 + manage_bottom_actions_properties.isChecked = actions and BOTTOM_ACTION_PROPERTIES != 0 + manage_bottom_actions_lock_orientation.isChecked = actions and BOTTOM_ACTION_LOCK_ORIENTATION != 0 + manage_bottom_actions_slideshow.isChecked = actions and BOTTOM_ACTION_PROPERTIES != 0 + manage_bottom_actions_show_on_map.isChecked = actions and BOTTOM_ACTION_SHOW_ON_MAP != 0 + manage_bottom_actions_toggle_visibility.isChecked = actions and BOTTOM_ACTION_TOGGLE_VISIBILITY != 0 + } + + AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this) + } + } + + private fun dialogConfirmed() { + var result = 0 + view.apply { + if (manage_bottom_actions_toggle_favorite.isChecked) + result += BOTTOM_ACTION_TOGGLE_FAVORITE + if (manage_bottom_actions_edit.isChecked) + result += BOTTOM_ACTION_EDIT + if (manage_bottom_actions_share.isChecked) + result += BOTTOM_ACTION_SHARE + if (manage_bottom_actions_delete.isChecked) + result += BOTTOM_ACTION_DELETE + if (manage_bottom_actions_rotate.isChecked) + result += BOTTOM_ACTION_ROTATE + if (manage_bottom_actions_properties.isChecked) + result += BOTTOM_ACTION_PROPERTIES + if (manage_bottom_actions_lock_orientation.isChecked) + result += BOTTOM_ACTION_LOCK_ORIENTATION + if (manage_bottom_actions_slideshow.isChecked) + result += BOTTOM_ACTION_SLIDESHOW + if (manage_bottom_actions_show_on_map.isChecked) + result += BOTTOM_ACTION_SHOW_ON_MAP + if (manage_bottom_actions_toggle_visibility.isChecked) + result += BOTTOM_ACTION_TOGGLE_VISIBILITY + } + + activity.config.visibleBottomActions = result + callback(result) + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageExtendedDetailsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageExtendedDetailsDialog.kt index 812396346..62e50b612 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageExtendedDetailsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageExtendedDetailsDialog.kt @@ -28,7 +28,7 @@ class ManageExtendedDetailsDialog(val activity: BaseSimpleActivity, val callback } AlertDialog.Builder(activity) - .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) + .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) .create().apply { activity.setupDialogStuff(view, this) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index c758bb6fa..ae036f904 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -362,6 +362,6 @@ class Config(context: Context) : BaseConfig(context) { set(bottomActions) = prefs.edit().putBoolean(BOTTOM_ACTIONS, bottomActions).apply() var visibleBottomActions: Int - get() = prefs.getInt(VISIBLE_BOTTOM_ACTIONS, BOTTOM_ACTION_TOGGLE_FAVORITE or BOTTOM_ACTION_EDIT or BOTTOM_ACTION_SHARE or BOTTOM_ACTION_DELETE) + get() = prefs.getInt(VISIBLE_BOTTOM_ACTIONS, DEFAULT_BOTTOM_ACTIONS) set(visibleBottomActions) = prefs.edit().putInt(VISIBLE_BOTTOM_ACTIONS, visibleBottomActions).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index b42118322..25a1cf11f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -142,3 +142,5 @@ const val BOTTOM_ACTION_LOCK_ORIENTATION = 64 const val BOTTOM_ACTION_SLIDESHOW = 128 const val BOTTOM_ACTION_SHOW_ON_MAP = 256 const val BOTTOM_ACTION_TOGGLE_VISIBILITY = 512 + +const val DEFAULT_BOTTOM_ACTIONS = BOTTOM_ACTION_TOGGLE_FAVORITE or BOTTOM_ACTION_EDIT or BOTTOM_ACTION_SHARE or BOTTOM_ACTION_DELETE diff --git a/app/src/main/res/layout/dialog_manage_bottom_actions.xml b/app/src/main/res/layout/dialog_manage_bottom_actions.xml new file mode 100644 index 000000000..162ab0907 --- /dev/null +++ b/app/src/main/res/layout/dialog_manage_bottom_actions.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +