Add language preference screen
This commit is contained in:
@@ -525,7 +525,7 @@ fun ConfigureClockWidgetSheet(
|
||||
summary = when (timeFormat) {
|
||||
TimeFormat.TwelveHour -> stringResource(R.string.preference_clock_widget_time_format_12h)
|
||||
TimeFormat.TwentyFourHour -> stringResource(R.string.preference_clock_widget_time_format_24h)
|
||||
TimeFormat.System -> stringResource(R.string.preference_clock_widget_time_format_system)
|
||||
TimeFormat.System -> stringResource(R.string.preference_value_system_default)
|
||||
},
|
||||
icon = R.drawable.schedule_24px,
|
||||
onClick = {
|
||||
@@ -537,7 +537,7 @@ fun ConfigureClockWidgetSheet(
|
||||
onDismissRequest = { showDropdown = false }) {
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Text(stringResource(R.string.preference_clock_widget_time_format_system))
|
||||
Text(stringResource(R.string.preference_value_system_default))
|
||||
},
|
||||
onClick = {
|
||||
viewModel.setTimeFormat(TimeFormat.System)
|
||||
|
||||
@@ -85,6 +85,8 @@ import de.mm20.launcher2.ui.settings.integrations.IntegrationsSettingsRoute
|
||||
import de.mm20.launcher2.ui.settings.integrations.IntegrationsSettingsScreen
|
||||
import de.mm20.launcher2.ui.settings.license.LicenseRoute
|
||||
import de.mm20.launcher2.ui.settings.license.LicenseScreen
|
||||
import de.mm20.launcher2.ui.settings.locale.LocaleSettingsRoute
|
||||
import de.mm20.launcher2.ui.settings.locale.LocaleSettingsScreen
|
||||
import de.mm20.launcher2.ui.settings.locations.LocationsSettingsRoute
|
||||
import de.mm20.launcher2.ui.settings.locations.LocationsSettingsScreen
|
||||
import de.mm20.launcher2.ui.settings.log.LogRoute
|
||||
@@ -276,6 +278,9 @@ class SettingsActivity : BaseActivity() {
|
||||
entry<DebugSettingsRoute> {
|
||||
DebugSettingsScreen()
|
||||
}
|
||||
entry<LocaleSettingsRoute> {
|
||||
LocaleSettingsScreen()
|
||||
}
|
||||
entry<BackupSettingsRoute> {
|
||||
BackupSettingsScreen()
|
||||
}
|
||||
|
||||
@@ -479,7 +479,7 @@ private fun getShapeName(shape: IconShape?): String? {
|
||||
IconShape.Squircle -> R.string.preference_icon_shape_squircle
|
||||
IconShape.Square -> R.string.preference_icon_shape_square
|
||||
IconShape.Pentagon -> R.string.preference_icon_shape_pentagon
|
||||
IconShape.PlatformDefault -> R.string.preference_icon_shape_platform
|
||||
IconShape.PlatformDefault -> R.string.preference_value_system_default
|
||||
IconShape.Circle -> R.string.preference_icon_shape_circle
|
||||
IconShape.Teardrop -> R.string.preference_icon_shape_teardrop
|
||||
IconShape.Pebble -> R.string.preference_icon_shape_pebble
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package de.mm20.launcher2.ui.settings.locale
|
||||
|
||||
import android.app.LocaleConfig
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.LocaleList
|
||||
import androidx.activity.compose.LocalActivity
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalResources
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import androidx.navigation3.runtime.NavKey
|
||||
import de.mm20.launcher2.ktx.isAtLeastApiLevel
|
||||
import de.mm20.launcher2.ktx.tryStartActivity
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.component.preferences.ListPreference
|
||||
import de.mm20.launcher2.ui.component.preferences.Preference
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.util.Locale
|
||||
|
||||
@Serializable
|
||||
data object LocaleSettingsRoute: NavKey
|
||||
|
||||
@Composable
|
||||
fun LocaleSettingsScreen() {
|
||||
val context = LocalContext.current
|
||||
val resources = LocalResources.current
|
||||
|
||||
val language = remember {
|
||||
AppCompatDelegate.getApplicationLocales().get(0)
|
||||
}
|
||||
|
||||
|
||||
PreferenceScreen(
|
||||
title = stringResource(R.string.preference_screen_locale)
|
||||
) {
|
||||
item {
|
||||
PreferenceCategory {
|
||||
Preference(
|
||||
title = stringResource(R.string.preference_language),
|
||||
summary = if (language == null) stringResource(R.string.preference_value_system_default) else language.getDisplayName(language),
|
||||
enabled = isAtLeastApiLevel(33),
|
||||
onClick = {
|
||||
context.tryStartActivity(
|
||||
Intent(android.provider.Settings.ACTION_APP_LOCALE_SETTINGS).apply {
|
||||
setData("package:${context.packageName}".toUri())
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package de.mm20.launcher2.ui.settings.locale
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.koin.core.component.KoinComponent
|
||||
|
||||
class LocaleSettingsScreenVM: ViewModel(), KoinComponent {
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import de.mm20.launcher2.ui.settings.gestures.GesturesSettingsRoute
|
||||
import de.mm20.launcher2.ui.settings.homescreen.HomescreenSettingsRoute
|
||||
import de.mm20.launcher2.ui.settings.icons.IconsSettingsRoute
|
||||
import de.mm20.launcher2.ui.settings.integrations.IntegrationsSettingsRoute
|
||||
import de.mm20.launcher2.ui.settings.locale.LocaleSettingsRoute
|
||||
import de.mm20.launcher2.ui.settings.plugins.PluginsSettingsRoute
|
||||
import de.mm20.launcher2.ui.settings.search.SearchSettingsRoute
|
||||
import kotlinx.serialization.Serializable
|
||||
@@ -87,6 +88,14 @@ fun MainSettingsScreen() {
|
||||
backStack.add(PluginsSettingsRoute)
|
||||
}
|
||||
)
|
||||
Preference(
|
||||
icon = R.drawable.translate_24px,
|
||||
title = stringResource(id = R.string.preference_screen_locale),
|
||||
summary = stringResource(id = R.string.preference_screen_locale_summary),
|
||||
onClick = {
|
||||
backStack.add(LocaleSettingsRoute)
|
||||
}
|
||||
)
|
||||
Preference(
|
||||
icon = R.drawable.settings_backup_restore_24px,
|
||||
title = stringResource(id = R.string.preference_screen_backup),
|
||||
|
||||
@@ -445,7 +445,6 @@
|
||||
<string name="preference_transparencies_default">Default</string>
|
||||
<string name="preference_transparencies_semi_transparent">Semi-transparent</string>
|
||||
<string name="preference_font">Font</string>
|
||||
<string name="preference_font_system">System default</string>
|
||||
<string name="preference_screen_about">About</string>
|
||||
<string name="preference_version">Version</string>
|
||||
<string name="preference_category_links">Links</string>
|
||||
@@ -494,7 +493,6 @@
|
||||
<string name="preference_cards_shape_rounded">Rounded</string>
|
||||
<string name="preference_cards_shape_cut">Cut</string>
|
||||
<string name="preference_icon_shape">Shape</string>
|
||||
<string name="preference_icon_shape_platform">System default</string>
|
||||
<string name="preference_icon_shape_square">Square</string>
|
||||
<string name="preference_icon_shape_rounded_square">Rounded square</string>
|
||||
<string name="preference_icon_shape_squircle">Squircle</string>
|
||||
@@ -587,7 +585,6 @@
|
||||
<string name="preference_clock_widget_time_format">Time format</string>
|
||||
<string name="preference_clock_widget_time_format_24h">24-hour</string>
|
||||
<string name="preference_clock_widget_time_format_12h">12-hour</string>
|
||||
<string name="preference_clock_widget_time_format_system">System default</string>
|
||||
<string name="widget_use_theme_colors">Use theme color</string>
|
||||
<string name="preference_clock_widget_fill_height">Fill screen height</string>
|
||||
<string name="preference_clock_widget_alignment">Alignment</string>
|
||||
@@ -1060,4 +1057,8 @@
|
||||
<string name="font_name_device_headline">Default headline font</string>
|
||||
<string name="font_name_device_body">Device text font</string>
|
||||
<string name="font_category_generic">Generic</string>
|
||||
<string name="preference_screen_locale">Language and region</string>
|
||||
<string name="preference_screen_locale_summary">Language, units, time format</string>
|
||||
<string name="preference_language">Language</string>
|
||||
<string name="preference_value_system_default">System default</string>
|
||||
</resources>
|
||||
@@ -87,7 +87,7 @@ class TypographyRepository(
|
||||
get() = Typography(
|
||||
id = SystemFontId,
|
||||
builtIn = true,
|
||||
name = context.getString(R.string.preference_font_system),
|
||||
name = context.getString(R.string.preference_value_system_default),
|
||||
fonts = mapOf(
|
||||
"brand" to FontFamily.DeviceHeadline,
|
||||
"plain" to FontFamily.DeviceBody,
|
||||
|
||||
Reference in New Issue
Block a user