Cleanup general settings

This commit is contained in:
Syer10
2021-06-23 14:09:06 -04:00
parent c5aaa5e6fa
commit 4dfd13845e

View File

@@ -20,7 +20,6 @@ import ca.gosyer.ui.base.resources.stringResource
import ca.gosyer.ui.base.vm.ViewModel import ca.gosyer.ui.base.vm.ViewModel
import ca.gosyer.ui.base.vm.viewModel import ca.gosyer.ui.base.vm.viewModel
import ca.gosyer.ui.main.Route import ca.gosyer.ui.main.Route
import ca.gosyer.util.lang.capitalize
import com.github.zsoltk.compose.router.BackStack import com.github.zsoltk.compose.router.BackStack
import java.time.Instant import java.time.Instant
import java.time.ZoneId import java.time.ZoneId
@@ -42,25 +41,24 @@ class SettingsGeneralViewModel @Inject constructor(
private val now: Instant = Instant.now() private val now: Instant = Instant.now()
private val currentLocale = Locale.getDefault() private val currentLocale = Locale.getDefault()
private fun getLocalePair(locale: String): Pair<String, String> { fun getStartScreenChoices() = mapOf(
return locale to Locale.forLanguageTag(locale).getDisplayName(currentLocale) StartScreen.Library to resources.getStringA("location_library"),
} StartScreen.Sources to resources.getStringA("location_sources"),
StartScreen.Extensions to resources.getStringA("location_extensions")
)
@Composable @Composable
fun getLanguageChoices(): Map<String, String> { fun getLanguageChoices(): Map<String, String> = mapOf(
val currentLocaleDisplayName = currentLocale.getDisplayName(currentLocale).capitalize(currentLocale) "" to resources.getString("language_system_default", currentLocale.getDisplayName(currentLocale))
) + listOf(
return mapOf( "en",
"" to resources.getString("language_system_default", currentLocaleDisplayName), "en-CA",
getLocalePair("en"), "fa",
getLocalePair("en-CA"), "hi",
getLocalePair("fa"), "pt-BR",
getLocalePair("hi"), "sv",
getLocalePair("pt-BR"), "tam"
getLocalePair("sv"), ).associateWith { Locale.forLanguageTag(it).getDisplayName(currentLocale) }
getLocalePair("tam")
)
}
@Composable @Composable
fun getDateChoices(): Map<String, String> { fun getDateChoices(): Map<String, String> {
@@ -92,11 +90,7 @@ fun SettingsGeneralScreen(navController: BackStack<Route>) {
ChoicePreference( ChoicePreference(
preference = vm.startScreen, preference = vm.startScreen,
title = stringResource("start_screen"), title = stringResource("start_screen"),
choices = mapOf( choices = vm.getStartScreenChoices()
StartScreen.Library to stringResource("location_library"),
StartScreen.Sources to stringResource("location_sources"),
StartScreen.Extensions to stringResource("location_extensions"),
)
) )
} }
item { item {