mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-23 13:02:33 +01:00
Set android app language on startup
This commit is contained in:
@@ -10,6 +10,11 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
modules {
|
||||||
|
module("androidx.lifecycle:lifecycle-viewmodel-ktx") {
|
||||||
|
replacedBy("androidx.lifecycle:lifecycle-viewmodel")
|
||||||
|
}
|
||||||
|
}
|
||||||
implementation(projects.core)
|
implementation(projects.core)
|
||||||
implementation(projects.i18n)
|
implementation(projects.i18n)
|
||||||
implementation(projects.data)
|
implementation(projects.data)
|
||||||
|
|||||||
@@ -8,14 +8,18 @@ package ca.gosyer.jui.android
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
import androidx.core.os.LocaleListCompat
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import androidx.lifecycle.ProcessLifecycleOwner
|
import androidx.lifecycle.ProcessLifecycleOwner
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import ca.gosyer.core.logging.CKLogger
|
import ca.gosyer.core.logging.CKLogger
|
||||||
|
import ca.gosyer.core.prefs.Preference
|
||||||
import ca.gosyer.core.prefs.getAsFlow
|
import ca.gosyer.core.prefs.getAsFlow
|
||||||
import ca.gosyer.data.ui.model.ThemeMode
|
import ca.gosyer.data.ui.model.ThemeMode
|
||||||
import ca.gosyer.jui.android.data.notification.Notifications
|
import ca.gosyer.jui.android.data.notification.Notifications
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
class App : Application(), DefaultLifecycleObserver {
|
class App : Application(), DefaultLifecycleObserver {
|
||||||
|
|
||||||
@@ -43,6 +47,8 @@ class App : Application(), DefaultLifecycleObserver {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
|
.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
|
||||||
|
|
||||||
|
setupAppLanguage(appComponent.dataComponent.uiPreferences.language())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupNotificationChannels() {
|
private fun setupNotificationChannels() {
|
||||||
@@ -53,5 +59,32 @@ class App : Application(), DefaultLifecycleObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupAppLanguage(languagePref: Preference<String>) {
|
||||||
|
val defaultLocaleList = AppCompatDelegate.getApplicationLocales()
|
||||||
|
if (languagePref.isSet() && languagePref.defaultValue() != languagePref.get()) {
|
||||||
|
AppCompatDelegate.setApplicationLocales(
|
||||||
|
LocaleListCompat.create(
|
||||||
|
Locale.forLanguageTag(languagePref.get()),
|
||||||
|
Locale.forLanguageTag("en")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
languagePref
|
||||||
|
.changes()
|
||||||
|
.onEach {
|
||||||
|
if (languagePref.isSet() && languagePref.defaultValue() != it) {
|
||||||
|
AppCompatDelegate.setApplicationLocales(
|
||||||
|
LocaleListCompat.create(
|
||||||
|
Locale.forLanguageTag(it),
|
||||||
|
Locale.forLanguageTag("en")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else if (languagePref.isSet() && it == languagePref.defaultValue()) {
|
||||||
|
AppCompatDelegate.setApplicationLocales(defaultLocaleList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.launchIn(ProcessLifecycleOwner.get().lifecycleScope)
|
||||||
|
}
|
||||||
|
|
||||||
protected companion object : CKLogger({})
|
protected companion object : CKLogger({})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ materialDialogs = "0.6.6"
|
|||||||
|
|
||||||
# Android
|
# Android
|
||||||
core = "1.7.0"
|
core = "1.7.0"
|
||||||
appCompat = "1.4.1"
|
appCompat = "1.6.0-alpha01"
|
||||||
activityCompose = "1.4.0"
|
activityCompose = "1.4.0"
|
||||||
work = "2.6.0"
|
work = "2.6.0"
|
||||||
|
|
||||||
# Android Lifecycle
|
# Android Lifecycle
|
||||||
lifecycle = "2.4.1"
|
lifecycle = "2.5.0-alpha03"
|
||||||
|
|
||||||
# Swing
|
# Swing
|
||||||
darklaf = "2.7.3"
|
darklaf = "2.7.3"
|
||||||
|
|||||||
Reference in New Issue
Block a user