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