Add default android locale. Simplify language settings.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -17,7 +17,6 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.navigation.NavHostController
|
||||
@@ -76,12 +75,7 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
||||
}
|
||||
|
||||
override fun onLanguageChanged(language: Language) {
|
||||
val currentLocale = AppCompatDelegate.getApplicationLocales()[0].toString()
|
||||
|
||||
if (language.value != currentLocale) {
|
||||
val newLocale = LocaleListCompat.forLanguageTags(language.value)
|
||||
AppCompatDelegate.setApplicationLocales(newLocale)
|
||||
}
|
||||
AppCompatDelegate.setApplicationLocales(language.value)
|
||||
}
|
||||
|
||||
override fun onThemeChanged(theme: Theme) {
|
||||
@@ -90,10 +84,7 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
||||
Theme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
Theme.DEFAULT -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
|
||||
if (themeValue != AppCompatDelegate.getDefaultNightMode()) {
|
||||
AppCompatDelegate.setDefaultNightMode(themeValue)
|
||||
}
|
||||
AppCompatDelegate.setDefaultNightMode(themeValue)
|
||||
}
|
||||
|
||||
override fun onScreenOnChanged(keepOn: KeepScreenOn) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import me.zobrist.tichucounter.data.GameWithScores
|
||||
|
||||
fun GameWithScores.getTotalPoints(): Pair<Int, Int> {
|
||||
var scoreA = 0
|
||||
var scoreB = 0
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import android.content.Context
|
||||
import androidx.appcompat.app.AppCompatDelegate.getApplicationLocales
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
enum class Theme { DEFAULT, DARK, LIGHT }
|
||||
enum class Language(val value: String) { ENGLISH("en"), GERMAN("de") }
|
||||
enum class Language(val value: LocaleListCompat) {
|
||||
DEFAULT(LocaleListCompat.getEmptyLocaleList()),
|
||||
ENGLISH(LocaleListCompat.forLanguageTags("en")),
|
||||
GERMAN(LocaleListCompat.forLanguageTags("de"))
|
||||
}
|
||||
|
||||
enum class KeepScreenOn(val value: Boolean) { ON(true), OFF(false) }
|
||||
|
||||
interface ISettingsChangeListener {
|
||||
@@ -36,7 +41,7 @@ class SettingsAdapter @Inject constructor(@ApplicationContext private val contex
|
||||
language = try {
|
||||
enumValueOf(sharedPreferences.getString(Language::class.simpleName, null)!!)
|
||||
} catch (_: NullPointerException) {
|
||||
getCurrentAppLanguage()
|
||||
Language.DEFAULT
|
||||
}
|
||||
|
||||
theme = try {
|
||||
@@ -90,13 +95,6 @@ class SettingsAdapter @Inject constructor(@ApplicationContext private val contex
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
private fun getCurrentAppLanguage(): Language {
|
||||
return when (getApplicationLocales()[0].toString()) {
|
||||
"de" -> Language.GERMAN
|
||||
else -> Language.ENGLISH
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifyListeners(language: Language) {
|
||||
listenerList.forEach {
|
||||
it.onLanguageChanged(language)
|
||||
|
||||
@@ -42,6 +42,7 @@ class HistoryViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun deleteAllInactiveGames() {
|
||||
viewModelScope.launch {
|
||||
gameRepository.deleteAllInactive()
|
||||
|
||||
@@ -25,6 +25,7 @@ import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||
|
||||
|
||||
val languageMap = mapOf(
|
||||
Language.DEFAULT to R.string.android_default_text,
|
||||
Language.ENGLISH to R.string.english,
|
||||
Language.GERMAN to R.string.german
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user