From ee32c1ab3a7e39c4060dc488d2ceac492fafd9fb Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 10 Mar 2017 22:21:52 +0100 Subject: [PATCH] use the new radio group dialog for Show Media picking --- app/build.gradle | 2 +- .../gallery/activities/SettingsActivity.kt | 15 +++++- .../gallery/dialogs/ShowMediaDialog.kt | 46 ------------------- app/src/main/res/layout/dialog_show_media.xml | 33 ------------- 4 files changed, 14 insertions(+), 82 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ShowMediaDialog.kt delete mode 100644 app/src/main/res/layout/dialog_show_media.xml diff --git a/app/build.gradle b/app/build.gradle index b51ade6df..ce1f9f228 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ android { } dependencies { - compile 'com.simplemobiletools:commons:2.9.4' + compile 'com.simplemobiletools:commons:2.9.8' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' 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 199168fa5..456e26a06 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SettingsActivity.kt @@ -1,20 +1,26 @@ package com.simplemobiletools.gallery.activities import android.content.Intent +import android.content.res.Resources import android.os.Bundle +import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.updateTextColors +import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.dialogs.ShowMediaDialog import com.simplemobiletools.gallery.extensions.beVisibleIf 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.activity_settings.* class SettingsActivity : SimpleActivity() { + lateinit var res: Resources + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_settings) + res = resources } override fun onResume() { @@ -80,7 +86,12 @@ class SettingsActivity : SimpleActivity() { private fun setupShowMedia() { settings_show_media.text = getShowMediaText() settings_show_media_holder.setOnClickListener { - ShowMediaDialog(this) { + val items = arrayListOf( + RadioItem(IMAGES_AND_VIDEOS, res.getString(R.string.images_and_videos)), + RadioItem(IMAGES, res.getString(R.string.images)), + RadioItem(VIDEOS, res.getString(R.string.videos))) + + RadioGroupDialog(this@SettingsActivity, items, config.showMedia) { config.showMedia = it settings_show_media.text = getShowMediaText() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ShowMediaDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ShowMediaDialog.kt deleted file mode 100644 index 095af6df0..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ShowMediaDialog.kt +++ /dev/null @@ -1,46 +0,0 @@ -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/res/layout/dialog_show_media.xml b/app/src/main/res/layout/dialog_show_media.xml deleted file mode 100644 index 5b295536a..000000000 --- a/app/src/main/res/layout/dialog_show_media.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - -