Skip to content

Commit

Permalink
feat: Add ability to switch app locale on Android 13 & above (#122)
Browse files Browse the repository at this point in the history
---------
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam authored May 9, 2024
1 parent c1a4465 commit 76e474d
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 13 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
androidResources {
generateLocaleConfig true
}
}

aboutLibraries {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,28 +456,52 @@ fun GoalItemCompact(
color = MaterialTheme.colorScheme.onSecondaryContainer
)

Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
if (savedAmount.length >= 12) {
Text(
text = savedAmount,
modifier = Modifier.padding(start = 4.dp),
fontSize = 24.sp,
fontFamily = greenstashNumberFont,
fontWeight = FontWeight.Bold,
maxLines = 2,
maxLines = 3,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colorScheme.onSecondaryContainer
)

Text(
text = daysLeftText,
modifier = Modifier.padding(top = 18.dp),
fontSize = 16.sp,
fontFamily = greenstashFont,
fontWeight = FontWeight.Medium,
color = MaterialTheme.colorScheme.onSecondaryContainer
)
Row(Modifier.fillMaxWidth()) {
Spacer(modifier = Modifier.weight(1f))
Text(
text = daysLeftText,
fontSize = 16.sp,
fontFamily = greenstashFont,
fontWeight = FontWeight.Medium,
color = MaterialTheme.colorScheme.onSecondaryContainer
)
}
} else {
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = savedAmount,
modifier = Modifier.padding(start = 4.dp),
fontSize = 24.sp,
fontFamily = greenstashNumberFont,
fontWeight = FontWeight.Bold,
maxLines = 1,
color = MaterialTheme.colorScheme.onSecondaryContainer
)

Text(
text = daysLeftText,
modifier = Modifier.padding(top = 18.dp),
fontSize = 16.sp,
fontFamily = greenstashFont,
fontWeight = FontWeight.Medium,
color = MaterialTheme.colorScheme.onSecondaryContainer
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
Expand Down Expand Up @@ -274,6 +275,9 @@ fun GoalInfoCard(
fontWeight = FontWeight.Bold,
fontSize = 38.sp,
fontFamily = greenstashNumberFont,
maxLines = 3,
lineHeight = 1.3f.em,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.padding(start = 8.dp)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

package com.starry.greenstash.ui.screens.settings.composables

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import androidx.biometric.BiometricPrompt
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -43,6 +46,7 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.BrightnessMedium
import androidx.compose.material.icons.filled.Contrast
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.Language
import androidx.compose.material.icons.filled.LocalPolice
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material.icons.filled.Palette
Expand Down Expand Up @@ -356,6 +360,19 @@ private fun LocaleSettings(viewModel: SettingsViewModel) {

SettingsContainer {
SettingsCategory(title = stringResource(id = R.string.locales_setting_title))
// App locale setting is only available on Android 13+.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
SettingsItem(title = stringResource(id = R.string.app_locale_setting),
description = stringResource(id = R.string.app_locale_setting_desc),
icon = Icons.Filled.Language,
onClick = {
val intent = Intent(Settings.ACTION_APP_LOCALE_SETTINGS).apply {
data = Uri.parse("package:${context.packageName}")
}
context.startActivity(intent)
}
)
}
SettingsItem(title = stringResource(id = R.string.date_format_setting),
description = dateValue,
icon = ImageVector.vectorResource(id = R.drawable.ic_settings_calender),
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/resources.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unqualifiedResLocale=en-US
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@
<string name="goal_card_option1">Clásico</string>
<string name="goal_card_option2">Compacto</string>
<string name="locales_setting_title">Configuración regional</string>
<string name="app_locale_setting">Idioma predeterminado</string>
<string name="app_locale_setting_desc">Selecciona tu idioma preferido</string>
<string name="date_format_setting">Formato de Fecha</string>
<string name="date_format_dialog_title">Cambiar Formato de Fecha</string>
<string name="preferred_currency_setting">Moneda preferida</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@
<string name="goal_card_option1">Классический</string>
<string name="goal_card_option2">Компактный</string>
<string name="locales_setting_title">Региональные настройки</string>
<string name="app_locale_setting">Язык по умолчанию</string>
<string name="app_locale_setting_desc">Выберите предпочитаемый язык</string>
<string name="date_format_setting">Формат даты</string>
<string name="date_format_dialog_title">Изменить формат даты</string>
<string name="preferred_currency_setting">Предпочтительная валюта</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
<string name="goal_card_option1">Klasik</string>
<string name="goal_card_option2">Kompakt</string>
<string name="locales_setting_title">Yerel</string>
<string name="app_locale_setting">Varsayılan Yerelleştirme</string>
<string name="app_locale_setting_desc">Tercih ettiğiniz yerelleştirmeyi seçin</string>
<string name="date_format_setting">Tarih Biçimi</string>
<string name="date_format_dialog_title">Tarih Biçimini Değiştir</string>
<string name="preferred_currency_setting">Tercih Edilen Para Birimi</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@
<string name="goal_card_option1">经典</string>
<string name="goal_card_option2">紧凑</string>
<string name="locales_setting_title">地区</string>
<string name="app_locale_setting">默认语言环境</string>
<string name="app_locale_setting_desc">选择您喜欢的语言环境</string>
<string name="date_format_setting">日期格式</string>
<string name="date_format_dialog_title">修改日期格式</string>
<string name="preferred_currency_setting">首选货币</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@
<string name="goal_card_option1">傳統</string>
<string name="goal_card_option2">緊湊</string>
<string name="locales_setting_title">地區</string>
<string name="app_locale_setting">預設語言環境</string>
<string name="app_locale_setting_desc">選擇您喜歡的語言環境</string>
<string name="date_format_setting">日期格式</string>
<string name="date_format_dialog_title">更改日期格式</string>
<string name="preferred_currency_setting">預設貨幣</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@
<string name="goal_card_option1">Classic</string>
<string name="goal_card_option2">Compact</string>
<string name="locales_setting_title">Locales</string>
<string name="app_locale_setting">Default Locale</string>
<string name="app_locale_setting_desc">Select your preferred locale</string>
<string name="date_format_setting">Date Format</string>
<string name="date_format_dialog_title">Change Date Format</string>
<string name="preferred_currency_setting">Preferred Currency</string>
Expand Down

0 comments on commit 76e474d

Please sign in to comment.