mirror of
https://github.com/Michatec/Radio.git
synced 2026-04-01 07:56:27 +02:00
refactor(ui): update theme selection dialog behavior and TV layout
This commit is contained in:
@@ -26,6 +26,28 @@ class ThemeSelectionDialog(private var themeSelectionDialogListener: ThemeSelect
|
|||||||
private lateinit var dialog: AlertDialog
|
private lateinit var dialog: AlertDialog
|
||||||
|
|
||||||
|
|
||||||
|
/* Update radio buttons to reflect current theme */
|
||||||
|
private fun updateRadioButtons(
|
||||||
|
context: Context,
|
||||||
|
radioFollowSystem: RadioButton,
|
||||||
|
radioLight: RadioButton,
|
||||||
|
radioDark: RadioButton
|
||||||
|
) {
|
||||||
|
val currentTheme = AppThemeHelper.getCurrentTheme(context)
|
||||||
|
when (currentTheme) {
|
||||||
|
context.getString(R.string.pref_theme_selection_mode_device_default) -> {
|
||||||
|
radioFollowSystem.isChecked = true
|
||||||
|
}
|
||||||
|
context.getString(R.string.pref_theme_selection_mode_light) -> {
|
||||||
|
radioLight.isChecked = true
|
||||||
|
}
|
||||||
|
context.getString(R.string.pref_theme_selection_mode_dark) -> {
|
||||||
|
radioDark.isChecked = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Construct and show dialog */
|
/* Construct and show dialog */
|
||||||
fun show(context: Context) {
|
fun show(context: Context) {
|
||||||
// prepare dialog builder
|
// prepare dialog builder
|
||||||
@@ -65,32 +87,17 @@ class ThemeSelectionDialog(private var themeSelectionDialogListener: ThemeSelect
|
|||||||
}
|
}
|
||||||
// apply theme immediately
|
// apply theme immediately
|
||||||
AppThemeHelper.setTheme(selectedTheme)
|
AppThemeHelper.setTheme(selectedTheme)
|
||||||
|
// update radio buttons to reflect new theme
|
||||||
|
updateRadioButtons(context, radioFollowSystem, radioLight, radioDark)
|
||||||
|
// notify listener
|
||||||
|
themeSelectionDialogListener.onThemeSelectionDialog(true, selectedTheme)
|
||||||
|
// dismiss dialog
|
||||||
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
// set custom view
|
// set custom view
|
||||||
builder.setView(view)
|
builder.setView(view)
|
||||||
|
|
||||||
// add OK button
|
|
||||||
builder.setPositiveButton(R.string.dialog_generic_button_okay) { dialog, _ ->
|
|
||||||
// get selected theme
|
|
||||||
val selectedTheme = when (radioGroup.checkedRadioButtonId) {
|
|
||||||
R.id.radio_theme_follow_system -> Keys.STATE_THEME_FOLLOW_SYSTEM
|
|
||||||
R.id.radio_theme_light -> Keys.STATE_THEME_LIGHT_MODE
|
|
||||||
R.id.radio_theme_dark -> Keys.STATE_THEME_DARK_MODE
|
|
||||||
else -> Keys.STATE_THEME_FOLLOW_SYSTEM
|
|
||||||
}
|
|
||||||
// notify listener
|
|
||||||
themeSelectionDialogListener.onThemeSelectionDialog(true, selectedTheme)
|
|
||||||
dialog.dismiss()
|
|
||||||
}
|
|
||||||
|
|
||||||
// add cancel button
|
|
||||||
builder.setNegativeButton(R.string.dialog_generic_button_cancel) { dialog, _ ->
|
|
||||||
// notify listener
|
|
||||||
themeSelectionDialogListener.onThemeSelectionDialog(false, Keys.STATE_THEME_FOLLOW_SYSTEM)
|
|
||||||
dialog.dismiss()
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle outside-click as cancel
|
// handle outside-click as cancel
|
||||||
builder.setOnCancelListener {
|
builder.setOnCancelListener {
|
||||||
themeSelectionDialogListener.onThemeSelectionDialog(false, Keys.STATE_THEME_FOLLOW_SYSTEM)
|
themeSelectionDialogListener.onThemeSelectionDialog(false, Keys.STATE_THEME_FOLLOW_SYSTEM)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
android:button="@null"
|
android:button="@null"
|
||||||
android:drawableStart="?android:attr/listChoiceIndicatorSingle"
|
android:drawableEnd="?android:attr/listChoiceIndicatorSingle"
|
||||||
android:drawablePadding="16dp"
|
android:drawablePadding="16dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:clickable="true" />
|
android:clickable="true" />
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
android:button="@null"
|
android:button="@null"
|
||||||
android:drawableStart="?android:attr/listChoiceIndicatorSingle"
|
android:drawableEnd="?android:attr/listChoiceIndicatorSingle"
|
||||||
android:drawablePadding="16dp"
|
android:drawablePadding="16dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:clickable="true" />
|
android:clickable="true" />
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
android:button="@null"
|
android:button="@null"
|
||||||
android:drawableStart="?android:attr/listChoiceIndicatorSingle"
|
android:drawableEnd="?android:attr/listChoiceIndicatorSingle"
|
||||||
android:drawablePadding="16dp"
|
android:drawablePadding="16dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:clickable="true" />
|
android:clickable="true" />
|
||||||
|
|||||||
Reference in New Issue
Block a user