feat(ui): save theme selection to preferences

This commit is contained in:
2026-03-28 22:37:55 +01:00
parent 93008f7247
commit d0e412ca83
2 changed files with 11 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.michatec.radio.Keys import com.michatec.radio.Keys
import com.michatec.radio.R import com.michatec.radio.R
import com.michatec.radio.helpers.AppThemeHelper import com.michatec.radio.helpers.AppThemeHelper
import com.michatec.radio.helpers.PreferencesHelper
/* /*
@@ -85,10 +86,10 @@ class ThemeSelectionDialog(private var themeSelectionDialogListener: ThemeSelect
R.id.radio_theme_dark -> Keys.STATE_THEME_DARK_MODE R.id.radio_theme_dark -> Keys.STATE_THEME_DARK_MODE
else -> Keys.STATE_THEME_FOLLOW_SYSTEM else -> Keys.STATE_THEME_FOLLOW_SYSTEM
} }
// save theme selection to preferences
PreferencesHelper.saveThemeSelection(selectedTheme)
// 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 // notify listener
themeSelectionDialogListener.onThemeSelectionDialog(true, selectedTheme) themeSelectionDialogListener.onThemeSelectionDialog(true, selectedTheme)
// dismiss dialog // dismiss dialog

View File

@@ -223,6 +223,14 @@ object PreferencesHelper {
} }
/* Save currently selected app theme */
fun saveThemeSelection(theme: String) {
sharedPreferences.edit {
putString(Keys.PREF_THEME_SELECTION, theme)
}
}
/* Loads value of the option: Edit Stations */ /* Loads value of the option: Edit Stations */
fun loadEditStationsEnabled(context: Context): Boolean { fun loadEditStationsEnabled(context: Context): Boolean {
val defaultValue = !context.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK) val defaultValue = !context.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)