|
@@ -7,9 +7,12 @@ import android.provider.Settings
|
|
|
import androidx.annotation.StringRes
|
|
|
import androidx.appcompat.app.AppCompatDelegate
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.runtime.ReadOnlyComposable
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
+import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
-import androidx.compose.runtime.rememberCoroutineScope
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
import androidx.core.os.LocaleListCompat
|
|
@@ -18,8 +21,6 @@ import eu.kanade.domain.library.service.LibraryPreferences
|
|
|
import eu.kanade.presentation.more.settings.Preference
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
|
|
-import kotlinx.coroutines.delay
|
|
|
-import kotlinx.coroutines.launch
|
|
|
import org.xmlpull.v1.XmlPullParser
|
|
|
import uy.kohesive.injekt.Injekt
|
|
|
import uy.kohesive.injekt.api.get
|
|
@@ -33,7 +34,6 @@ class SettingsGeneralScreen : SearchableSettings {
|
|
|
|
|
|
@Composable
|
|
|
override fun getPreferences(): List<Preference> {
|
|
|
- val scope = rememberCoroutineScope()
|
|
|
val prefs = remember { Injekt.get<BasePreferences>() }
|
|
|
val libraryPrefs = remember { Injekt.get<LibraryPreferences>() }
|
|
|
return mutableListOf<Preference>().apply {
|
|
@@ -67,7 +67,7 @@ class SettingsGeneralScreen : SearchableSettings {
|
|
|
}
|
|
|
|
|
|
val langs = remember { getLangs(context) }
|
|
|
- val currentLanguage = remember { AppCompatDelegate.getApplicationLocales().get(0)?.toLanguageTag() ?: "" }
|
|
|
+ var currentLanguage by remember { mutableStateOf(AppCompatDelegate.getApplicationLocales().get(0)?.toLanguageTag() ?: "") }
|
|
|
add(
|
|
|
Preference.PreferenceItem.BasicListPreference(
|
|
|
value = currentLanguage,
|
|
@@ -75,19 +75,20 @@ class SettingsGeneralScreen : SearchableSettings {
|
|
|
subtitle = "%s",
|
|
|
entries = langs,
|
|
|
onValueChanged = { newValue ->
|
|
|
- scope.launch {
|
|
|
- delay(1000)
|
|
|
- val locale = if (newValue.isEmpty()) {
|
|
|
- LocaleListCompat.getEmptyLocaleList()
|
|
|
- } else {
|
|
|
- LocaleListCompat.forLanguageTags(newValue)
|
|
|
- }
|
|
|
- AppCompatDelegate.setApplicationLocales(locale)
|
|
|
- }
|
|
|
+ currentLanguage = newValue
|
|
|
true
|
|
|
},
|
|
|
),
|
|
|
)
|
|
|
+
|
|
|
+ LaunchedEffect(currentLanguage) {
|
|
|
+ val locale = if (currentLanguage.isEmpty()) {
|
|
|
+ LocaleListCompat.getEmptyLocaleList()
|
|
|
+ } else {
|
|
|
+ LocaleListCompat.forLanguageTags(currentLanguage)
|
|
|
+ }
|
|
|
+ AppCompatDelegate.setApplicationLocales(locale)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|