From 8bb21848183006401e551a48bcdd761e1da84486 Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sat, 17 Aug 2024 00:07:52 +0200 Subject: [PATCH] Make string translatable --- app/app/build.gradle.kts | 2 +- .../CalendarSearchSettingsScreen.kt | 9 ++- .../settings/plugins/PluginSettingsScreen.kt | 75 ++++++++++--------- core/i18n/src/main/res/values/strings.xml | 4 + 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/app/app/build.gradle.kts b/app/app/build.gradle.kts index 142121be..de1b516c 100644 --- a/app/app/build.gradle.kts +++ b/app/app/build.gradle.kts @@ -32,7 +32,7 @@ android { targetSdk = libs.versions.targetSdk.get().toInt() @SuppressLint("HighAppVersionCode") versionCode = System.getenv("VERSION_CODE_OVERRIDE")?.toIntOrNull() ?: 2024072400 - versionName = "1.32.2" + versionName = "1.33.0" signingConfig = signingConfigs.getByName("debug") } diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/calendarsearch/CalendarSearchSettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/calendarsearch/CalendarSearchSettingsScreen.kt index 93c8070e..e3be947b 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/calendarsearch/CalendarSearchSettingsScreen.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/calendarsearch/CalendarSearchSettingsScreen.kt @@ -26,6 +26,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.lifecycle.Lifecycle @@ -125,7 +126,13 @@ fun CalendarSearchSettingsScreen() { title = plugin.plugin.label, enabled = state is PluginState.Ready, summary = (state as? PluginState.SetupRequired)?.message - ?: if (selectedCalendars != null && calendarLists != null) "$selectedCalendars lists selected" + ?: if (selectedCalendars != null && calendarLists != null) { + pluralStringResource( + R.plurals.calendar_search_enabled_lists, + selectedCalendars, + selectedCalendars + ) + } else (state as? PluginState.Ready)?.text ?: plugin.plugin.description, switchValue = enabledProviders.contains(plugin.plugin.authority) && state is PluginState.Ready, onSwitchChanged = { diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/plugins/PluginSettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/plugins/PluginSettingsScreen.kt index 4c0370a8..15cd0b7b 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/plugins/PluginSettingsScreen.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/plugins/PluginSettingsScreen.kt @@ -16,8 +16,6 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.rememberScrollState @@ -33,12 +31,11 @@ import androidx.compose.material.icons.rounded.Place import androidx.compose.material.icons.rounded.Settings import androidx.compose.material.icons.rounded.Today import androidx.compose.material.icons.rounded.Verified -import androidx.compose.material3.AlertDialogDefaults -import androidx.compose.material3.BasicAlertDialog import androidx.compose.material3.CheckboxDefaults import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Text @@ -55,6 +52,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.lifecycle.Lifecycle @@ -471,17 +469,31 @@ fun PluginSettingsScreen(pluginId: String) { } val calendarLists by remember(plugin.state, plugin.plugin) { viewModel.getCalendarLists(plugin.plugin) - }.collectAsStateWithLifecycle(null, minActiveState = Lifecycle.State.RESUMED) + }.collectAsStateWithLifecycle( + null, + minActiveState = Lifecycle.State.RESUMED + ) var showDialog by remember { mutableStateOf(false) } val selectedCalendars = remember(excludedCalendars, calendarLists) { - calendarLists?.size?.minus(excludedCalendars.count { it.startsWith(plugin.plugin.authority) }) + calendarLists?.size?.minus(excludedCalendars.count { + it.startsWith( + plugin.plugin.authority + ) + }) } PreferenceWithSwitch( title = plugin.plugin.label, enabled = enabledCalendarSearchPlugins != null && state is PluginState.Ready, summary = (state as? PluginState.SetupRequired)?.message - ?: if (selectedCalendars != null && calendarLists != null) "$selectedCalendars lists selected" - else (state as? PluginState.Ready)?.text ?: plugin.plugin.description, + ?: if (selectedCalendars != null && calendarLists != null) { + pluralStringResource( + R.plurals.calendar_search_enabled_lists, + selectedCalendars, + selectedCalendars + ) + } + else (state as? PluginState.Ready)?.text + ?: plugin.plugin.description, switchValue = enabledCalendarSearchPlugins?.contains(plugin.plugin.authority) == true && state is PluginState.Ready, onSwitchChanged = { viewModel.setCalendarSearchPluginEnabled( @@ -495,40 +507,33 @@ fun PluginSettingsScreen(pluginId: String) { } ) if (showDialog && calendarLists?.isNotEmpty() == true) { - BasicAlertDialog( + ModalBottomSheet( onDismissRequest = { showDialog = false }, ) { - Surface( - modifier = Modifier.wrapContentWidth() - .wrapContentHeight(), - shape = MaterialTheme.shapes.large, - tonalElevation = AlertDialogDefaults.TonalElevation - ) { - LazyColumn { - items(calendarLists!!) { - CheckboxPreference( - title = it.name, - summary = it.owner, - iconPadding = false, - value = it.id !in excludedCalendars, - onValueChanged = { value -> - viewModel.setCalendarExcluded(it.id, !value) - }, + LazyColumn { + items(calendarLists!!) { + CheckboxPreference( + title = it.name, + summary = it.owner, + iconPadding = false, + value = it.id !in excludedCalendars, + onValueChanged = { value -> + viewModel.setCalendarExcluded(it.id, !value) + }, - checkboxColors = CheckboxDefaults.colors( - checkedColor = if (it.color == 0) MaterialTheme.colorScheme.primary - else Color( - it.color.atTone(if (LocalDarkTheme.current) 80 else 40) - ), - checkmarkColor = if (it.color == 0) MaterialTheme.colorScheme.onPrimary - else Color( - it.color.atTone(if (LocalDarkTheme.current) 20 else 100) - ) + checkboxColors = CheckboxDefaults.colors( + checkedColor = if (it.color == 0) MaterialTheme.colorScheme.primary + else Color( + it.color.atTone(if (LocalDarkTheme.current) 80 else 40) + ), + checkmarkColor = if (it.color == 0) MaterialTheme.colorScheme.onPrimary + else Color( + it.color.atTone(if (LocalDarkTheme.current) 20 else 100) ) ) - } + ) } } } diff --git a/core/i18n/src/main/res/values/strings.xml b/core/i18n/src/main/res/values/strings.xml index 1189fe51..c72fc67f 100644 --- a/core/i18n/src/main/res/values/strings.xml +++ b/core/i18n/src/main/res/values/strings.xml @@ -998,4 +998,8 @@ Unlock Lock private space Hold and drag items to rearrange them + + %1$s list selected + %1$s lists selected + \ No newline at end of file