From f2bcac62982a34ace651691052f2798c8aaade3b Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 6 Feb 2017 23:55:42 +0100 Subject: [PATCH] add the showmediapicker dialog --- .../gallery/activities/SettingsActivity.kt | 10 ++-- .../gallery/dialogs/ShowMediaDialog.kt | 46 +++++++++++++++++++ .../gallery/extensions/context.kt | 1 - app/src/main/res/layout/dialog_show_media.xml | 33 +++++++++++++ app/src/main/res/values/array.xml | 8 ---- 5 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ShowMediaDialog.kt create mode 100644 app/src/main/res/layout/dialog_show_media.xml delete mode 100644 app/src/main/res/values/array.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 cd821d518..108b3f52e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.activities import android.os.Bundle import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.dialogs.ShowMediaDialog import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.IMAGES import com.simplemobiletools.gallery.helpers.IMAGES_AND_VIDEOS @@ -65,13 +66,16 @@ class SettingsActivity : SimpleActivity() { } private fun setupShowMedia() { - settings_show_media.text = getShowMediaText(config.showMedia) + settings_show_media.text = getShowMediaText() settings_show_media_holder.setOnClickListener { - + ShowMediaDialog(this) { + config.showMedia = it + settings_show_media.text = getShowMediaText() + } } } - private fun getShowMediaText(id: Int) = getString(when (id) { + private fun getShowMediaText() = getString(when (config.showMedia) { IMAGES_AND_VIDEOS -> R.string.images_and_videos IMAGES -> R.string.images else -> R.string.videos diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ShowMediaDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ShowMediaDialog.kt new file mode 100644 index 000000000..095af6df0 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ShowMediaDialog.kt @@ -0,0 +1,46 @@ +package com.simplemobiletools.gallery.dialogs + +import android.app.Activity +import android.support.v7.app.AlertDialog +import android.view.LayoutInflater +import android.widget.RadioGroup +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.helpers.IMAGES +import com.simplemobiletools.gallery.helpers.IMAGES_AND_VIDEOS +import com.simplemobiletools.gallery.helpers.VIDEOS +import kotlinx.android.synthetic.main.dialog_show_media.view.* + +class ShowMediaDialog(val activity: Activity, val callback: (newValue: Int) -> Unit) : AlertDialog.Builder(activity), RadioGroup.OnCheckedChangeListener { + val dialog: AlertDialog? + + init { + val view = LayoutInflater.from(activity).inflate(R.layout.dialog_show_media, null).dialog_radio_view.apply { + check(getSavedItem()) + setOnCheckedChangeListener(this@ShowMediaDialog) + } + + dialog = AlertDialog.Builder(activity) + .create().apply { + activity.setupDialogStuff(view, this) + } + } + + override fun onCheckedChanged(group: RadioGroup?, checkedId: Int) { + callback.invoke(getNewValue(checkedId)) + dialog?.dismiss() + } + + fun getNewValue(id: Int) = when (id) { + R.id.dialog_radio_images -> IMAGES + R.id.dialog_radio_videos -> VIDEOS + else -> IMAGES_AND_VIDEOS + } + + fun getSavedItem() = when (activity.config.showMedia) { + IMAGES -> R.id.dialog_radio_images + VIDEOS -> R.id.dialog_radio_videos + else -> R.id.dialog_radio_images_and_videos + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index 397bb80ee..3f063037c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -116,4 +116,3 @@ private fun removeNoMediaFolders(paths: MutableList) { } val Context.config: Config get() = Config.newInstance(this) - diff --git a/app/src/main/res/layout/dialog_show_media.xml b/app/src/main/res/layout/dialog_show_media.xml new file mode 100644 index 000000000..5b295536a --- /dev/null +++ b/app/src/main/res/layout/dialog_show_media.xml @@ -0,0 +1,33 @@ + + + + + + + + + + diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml deleted file mode 100644 index 9c379c4f6..000000000 --- a/app/src/main/res/values/array.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - @string/images_and_videos - @string/images - @string/videos - -