From 8d509b6b23ea55a003a8ddc64f908845cc6e7c9e Mon Sep 17 00:00:00 2001 From: Michatec Date: Sat, 28 Mar 2026 22:18:12 +0100 Subject: [PATCH] refactor(ui): update theme selection dialog behavior and TV layout --- .../radio/dialogs/ThemeSelectionDialog.kt | 49 +++++++++++-------- .../dialog_theme_selection.xml | 6 +-- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/michatec/radio/dialogs/ThemeSelectionDialog.kt b/app/src/main/java/com/michatec/radio/dialogs/ThemeSelectionDialog.kt index 89661bc..436a4f3 100644 --- a/app/src/main/java/com/michatec/radio/dialogs/ThemeSelectionDialog.kt +++ b/app/src/main/java/com/michatec/radio/dialogs/ThemeSelectionDialog.kt @@ -26,6 +26,28 @@ class ThemeSelectionDialog(private var themeSelectionDialogListener: ThemeSelect 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 */ fun show(context: Context) { // prepare dialog builder @@ -65,32 +87,17 @@ class ThemeSelectionDialog(private var themeSelectionDialogListener: ThemeSelect } // apply theme immediately 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 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 builder.setOnCancelListener { themeSelectionDialogListener.onThemeSelectionDialog(false, Keys.STATE_THEME_FOLLOW_SYSTEM) diff --git a/app/src/main/res/layout-television/dialog_theme_selection.xml b/app/src/main/res/layout-television/dialog_theme_selection.xml index e525edc..b557100 100644 --- a/app/src/main/res/layout-television/dialog_theme_selection.xml +++ b/app/src/main/res/layout-television/dialog_theme_selection.xml @@ -28,7 +28,7 @@ android:textSize="20sp" android:padding="12dp" android:button="@null" - android:drawableStart="?android:attr/listChoiceIndicatorSingle" + android:drawableEnd="?android:attr/listChoiceIndicatorSingle" android:drawablePadding="16dp" android:focusable="true" android:clickable="true" /> @@ -41,7 +41,7 @@ android:textSize="20sp" android:padding="12dp" android:button="@null" - android:drawableStart="?android:attr/listChoiceIndicatorSingle" + android:drawableEnd="?android:attr/listChoiceIndicatorSingle" android:drawablePadding="16dp" android:focusable="true" android:clickable="true" /> @@ -54,7 +54,7 @@ android:textSize="20sp" android:padding="12dp" android:button="@null" - android:drawableStart="?android:attr/listChoiceIndicatorSingle" + android:drawableEnd="?android:attr/listChoiceIndicatorSingle" android:drawablePadding="16dp" android:focusable="true" android:clickable="true" />