mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-18 06:17:59 +01:00
add the showmediapicker dialog
This commit is contained in:
parent
762662a976
commit
f2bcac6298
5 changed files with 86 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -116,4 +116,3 @@ private fun removeNoMediaFolders(paths: MutableList<String>) {
|
|||
}
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(this)
|
||||
|
||||
|
|
33
app/src/main/res/layout/dialog_show_media.xml
Normal file
33
app/src/main/res/layout/dialog_show_media.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RadioGroup
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dialog_radio_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/dialog_radio_images"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/images"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/dialog_radio_videos"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/videos"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||
android:id="@+id/dialog_radio_images_and_videos"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:text="@string/images_and_videos"/>
|
||||
|
||||
</RadioGroup>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="show_media_items" translatable="false">
|
||||
<item>@string/images_and_videos</item>
|
||||
<item>@string/images</item>
|
||||
<item>@string/videos</item>
|
||||
</string-array>
|
||||
</resources>
|
Loading…
Reference in a new issue