@@ -101,10 +101,9 @@ class SettingsFragment : Fragment() {
101101 )
102102 val languageCodes = arrayOf(" system" , " en" , " id" )
103103
104- // Get current from AppCompatDelegate
105- val currentLocales = AppCompatDelegate .getApplicationLocales()
106- val currentLang = if (currentLocales.isEmpty) " system" else currentLocales.toLanguageTags().split(" -" )[0 ]
107- val currentIndex = languageCodes.indexOf(currentLang).coerceAtLeast(0 )
104+ // Get current from prefs (more reliable)
105+ val savedLang = prefs.getString(Constants .PREFS_LANGUAGE , " system" ) ? : " system"
106+ val currentIndex = languageCodes.indexOf(savedLang).coerceAtLeast(0 )
108107
109108 MaterialAlertDialogBuilder (requireContext())
110109 .setTitle(R .string.settings_language)
@@ -119,8 +118,10 @@ class SettingsFragment : Fragment() {
119118 }
120119
121120 private fun updateLanguageText () {
121+ // Check from prefs first (more reliable), then AppCompatDelegate
122+ val savedLang = prefs.getString(Constants .PREFS_LANGUAGE , null )
122123 val currentLocales = AppCompatDelegate .getApplicationLocales()
123- val langTag = if (currentLocales.isEmpty) " system" else currentLocales.toLanguageTags()
124+ val langTag = savedLang ? : if (currentLocales.isEmpty) " system" else currentLocales.toLanguageTags()
124125
125126 binding.tvCurrentLanguage.text = when {
126127 langTag.startsWith(" en" ) -> getString(R .string.language_english)
@@ -130,6 +131,9 @@ class SettingsFragment : Fragment() {
130131 }
131132
132133 private fun applyLanguage (langCode : String ) {
134+ // Save to prefs for persistence
135+ prefs.edit().putString(Constants .PREFS_LANGUAGE , langCode).apply ()
136+
133137 // Use AppCompatDelegate for proper locale handling (Android 13+ compatible)
134138 val localeList = when (langCode) {
135139 " en" -> LocaleListCompat .forLanguageTags(" en" )
@@ -138,7 +142,11 @@ class SettingsFragment : Fragment() {
138142 }
139143
140144 AppCompatDelegate .setApplicationLocales(localeList)
141- // Activity will recreate automatically, no need for manual restart
145+
146+ // For older Android versions, we need to restart the app
147+ if (android.os.Build .VERSION .SDK_INT < android.os.Build .VERSION_CODES .TIRAMISU ) {
148+ restartApp()
149+ }
142150 }
143151
144152 private fun setupCurrentMode () {
0 commit comments