Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Fix issue 3138 (#3337)
Browse files Browse the repository at this point in the history
* added language change option for android 13+

* fixed detekt issues

* removed :app dependency for language selection

* removed unused dependency
  • Loading branch information
suyash01 authored Jul 13, 2024
1 parent 77c1df1 commit 84fff68
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ sealed interface SettingsEvent {
data class SetStartDateOfMonth(val startDate: Int) : SettingsEvent
data object DeleteCloudUserData : SettingsEvent
data object DeleteAllUserData : SettingsEvent
data object SwitchLanguage : SettingsEvent
}
24 changes: 22 additions & 2 deletions screen/settings/src/main/java/com/ivy/settings/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import com.ivy.wallet.ui.theme.modal.CurrencyModal
import com.ivy.wallet.ui.theme.modal.DeleteModal
import com.ivy.wallet.ui.theme.modal.NameModal
import com.ivy.wallet.ui.theme.modal.ProgressModal
import java.util.Locale

@ExperimentalFoundationApi
@Composable
Expand All @@ -95,6 +96,7 @@ fun BoxWithConstraintsScope.SettingsScreen() {
treatTransfersAsIncomeExpense = uiState.treatTransfersAsIncomeExpense,
nameLocalAccount = uiState.name,
startDateOfMonth = uiState.startDateOfMonth.toInt(),
languageOptionVisible = uiState.languageOptionVisible,
onSetCurrency = {
viewModel.onEvent(SettingsEvent.SetCurrency(it))
},
Expand Down Expand Up @@ -131,17 +133,22 @@ fun BoxWithConstraintsScope.SettingsScreen() {
onDeleteCloudUserData = {
viewModel.onEvent(SettingsEvent.DeleteCloudUserData)
},
onSwitchLanguage = {
viewModel.onEvent(SettingsEvent.SwitchLanguage)
}
)
}

@ExperimentalFoundationApi
@Composable
@Suppress("LongMethod")
private fun BoxWithConstraintsScope.UI(
currencyCode: String,
theme: Theme,
onSwitchTheme: () -> Unit,
lockApp: Boolean,
nameLocalAccount: String?,
languageOptionVisible: Boolean,
onSetCurrency: (String) -> Unit,
startDateOfMonth: Int = 1,
showNotifications: Boolean = true,
Expand All @@ -160,8 +167,8 @@ private fun BoxWithConstraintsScope.UI(
onSetStartDateOfMonth: (Int) -> Unit = {},
onDeleteAllUserData: () -> Unit = {},
onDeleteCloudUserData: () -> Unit = {},

) {
onSwitchLanguage: () -> Unit = {}
) {
var currencyModalVisible by remember { mutableStateOf(false) }
var nameModalVisible by remember { mutableStateOf(false) }
var chooseStartDateOfMonthVisible by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -296,6 +303,18 @@ private fun BoxWithConstraintsScope.UI(
//
// Spacer(Modifier.height(12.dp))

if (languageOptionVisible) {
SettingsDefaultButton(
icon = R.drawable.ic_vue_location_global,
text = stringResource(R.string.language),
description = Locale.getDefault().displayName
) {
onSwitchLanguage()
}

Spacer(Modifier.height(12.dp))
}

SettingsDefaultButton(
icon = R.drawable.ic_currency,
text = stringResource(R.string.exchange_rates),
Expand Down Expand Up @@ -1124,6 +1143,7 @@ private fun Preview(theme: Theme = Theme.LIGHT) {
lockApp = false,
currencyCode = "BGN",
onSetCurrency = {},
languageOptionVisible = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ data class SettingsState(
val hideIncome: Boolean,
val treatTransfersAsIncomeExpense: Boolean,
val startDateOfMonth: String,
val progressState: Boolean
val progressState: Boolean,
val languageOptionVisible: Boolean
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.ivy.settings

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.Stable
Expand All @@ -15,8 +20,8 @@ import com.ivy.data.db.dao.read.SettingsDao
import com.ivy.data.db.dao.write.WriteSettingsDao
import com.ivy.data.model.primitive.AssetCode
import com.ivy.domain.RootScreen
import com.ivy.domain.usecase.exchange.SyncExchangeRatesUseCase
import com.ivy.domain.usecase.csv.ExportCsvUseCase
import com.ivy.domain.usecase.exchange.SyncExchangeRatesUseCase
import com.ivy.frp.monad.Res
import com.ivy.legacy.IvyWalletCtx
import com.ivy.legacy.LogoutLogic
Expand All @@ -31,6 +36,7 @@ import com.ivy.wallet.domain.action.global.UpdateStartDayOfMonthAct
import com.ivy.wallet.domain.action.settings.SettingsAct
import com.ivy.widget.balance.WalletBalanceWidgetReceiver
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand All @@ -51,6 +57,7 @@ class SettingsViewModel @Inject constructor(
private val updateSettingsAct: UpdateSettingsAct,
private val settingsWriter: WriteSettingsDao,
private val exportCsvUseCase: ExportCsvUseCase,
@ApplicationContext private val context: Context
) : ComposeViewModel<SettingsState, SettingsEvent>() {

private val currencyCode = mutableStateOf("")
Expand Down Expand Up @@ -80,7 +87,8 @@ class SettingsViewModel @Inject constructor(
treatTransfersAsIncomeExpense = getTreatTransfersAsIncomeExpense(),
startDateOfMonth = getStartDateOfMonth(),
progressState = getProgressState(),
hideIncome = getHideIncome()
hideIncome = getHideIncome(),
languageOptionVisible = isLanguageOptionVisible()
)
}

Expand Down Expand Up @@ -195,6 +203,10 @@ class SettingsViewModel @Inject constructor(
return progressState.value
}

private fun isLanguageOptionVisible(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
}

override fun onEvent(event: SettingsEvent) {
when (event) {
is SettingsEvent.SetCurrency -> setCurrency(event.newCurrency)
Expand All @@ -220,6 +232,7 @@ class SettingsViewModel @Inject constructor(

SettingsEvent.DeleteCloudUserData -> deleteCloudUserData()
SettingsEvent.DeleteAllUserData -> deleteAllUserData()
SettingsEvent.SwitchLanguage -> switchLanguage()
}
}

Expand Down Expand Up @@ -383,4 +396,13 @@ class SettingsViewModel @Inject constructor(
logoutLogic.logout()
}
}

private fun switchLanguage() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val intent = Intent(Settings.ACTION_APP_LOCALE_SETTINGS)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.data = Uri.fromParts("package", context.packageName, null)
context.applicationContext.startActivity(intent)
}
}
}
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,5 @@
<string name="total_balance">المجموع المحفظة</string>
<string name="total_balance_excluded">المجموع المحفظة(مستبعد)</string>
<string name="search_tags">وسوم البحث</string>
<string name="language">لغة</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,5 @@
<string name="total_balance">Общо БАЛАНС</string>
<string name="total_balance_excluded">Общо БАЛАНС (изключен)</string>
<string name="search_tags">Търсени етикети</string>
<string name="language">Eзик</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,5 @@
<string name="import_csv_continue">Fortsetzen</string>
<string name="warning_import_csv_file">" !!!⚠️ACHTUNG: Ein Import kann zu doppelten Einträgen führen!!! Ivy Wallet kann diese NICHT automatisch entfernt und alle Einträge müssen manuell geprüft werden! Wenn du noch keine Einträge erfasst hast, kannst du diese Meldung ignorieren."</string>
<string name="select_tags">Tags auswählen</string>
<string name="language">Sprache</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,5 @@
<string name="total_balance">Total Balance</string>
<string name="total_balance_excluded">Total Balance (excluido)</string>
<string name="search_tags">Etiquetas de búsqueda</string>
<string name="language">Idioma</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,5 @@
<string name="total_balance">कुल बैलेंस</string>
<string name="total_balance_excluded">कुल बैलेंस (छोड़ा गया)</string>
<string name="search_tags">\"खोज टैग्स</string>
<string name="language">भाषा</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-id/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,5 @@
<string name="total_balance">Total dompet</string>
<string name="total_balance_excluded">Total dompet (tidak termasuk)</string>
<string name="search_tags">Tag Pencarian</string>
<string name="language">Bahasa</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,5 @@
<string name="total_balance">Total dompet</string>
<string name="total_balance_excluded">Total dompet (tidak termasuk)</string>
<string name="search_tags">Tag Pencarian</string>
<string name="language">Bahasa</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,5 @@
<string name="your_data_will_be_saved_only_locally">I tuoi dati saranno salvati localmente sul tuo dispositivo. Rischi di perdere i tuoi dati se disinstalli l\'app o se cambi dispositivo. Per prevenire perdite di dati, raccomandiamo di esportare regolarmente un backup dalle impostazioni.</string>
<string name="you_owe">Sei in debito di: %1$s</string>
<string name="you_are_owed">Ti sono dovuti %1$s</string>
<string name="language">Lingua</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-kn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,5 @@
<string name="total_balance">ಒಟ್ಟು ಮೊತ್ತ</string>
<string name="total_balance_excluded">ಒಟ್ಟು ಮೊತ್ತ (ಹೊರತುಪಡಿಸಿ)</string>
<string name="search_tags">ಹುಡುಕಿನ ಟ್ಯಾಗ್‌ಗಳು</string>
<string name="language">ಭಾಷೆ</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-mn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,5 @@
<string name="total_balance">Нийт ҮЛДЭГДЭЛ</string>
<string name="total_balance_excluded">Нийт ҮЛДЭГДЭЛ (үлдэгдэл тооцохгүй)</string>
<string name="search_tags">Хайлтын тагууд</string>
<string name="language">Хэл</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,5 @@
<string name="total_balance">Łącznie Saldo</string>
<string name="total_balance_excluded">Łącznie Saldo (wykluczony)</string>
<string name="search_tags">Tagi wyszukiwania</string>
<string name="language">Język</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,5 @@
<string name="import_csv_continue">Continuar</string>
<string name="warning_import_csv_file">"\n!!!⚠️AVISO: A importação pode duplicar transações!!!\nTransações duplicadas NÃO podem ser excluídas facilmente e você precisará remover manualmente cada uma delas! \nMotivo: podemos Não analisamos IDs de transação porque o Ivy Wallet funciona apenas com UUID e outros aplicativos não.\nSe você está começando do zero, não se preocupe. Por favor, ignore esta mensagem."</string>
<string name="select_tags">Selecionar tags</string>
<string name="language">Linguagem</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,5 @@
<string name="total_balance">Итого БАЛАНС</string>
<string name="total_balance_excluded">Итого БАЛАНС (исключенный)</string>
<string name="search_tags">Теги поиска</string>
<string name="language">Язык</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,5 @@
<string name="import_csv_continue">Tiếp tục</string>
<string name="warning_import_csv_file">"\n!!!⚠️CẢNH BÁO: Việc tải tệp lên có thể gây ra trùng lặp các giao dịch!!!\nGiao dịch trùng lặp KHÔNG thể dễ dàng xóa và bạn sẽ cần phải xóa từng giao dịch một cách thủ công!\nLý do: Chúng tôi không thể phân tích các ID giao dịch vì Ivy Wallet chỉ hoạt động với UUID và các ứng dụng khác không.\nNếu bạn chọn Bắt đầu, không cần lo lắng - vui lòng bỏ qua thông báo này.\n "</string>
<string name="select_tags">Chọn thẻ</string>
<string name="language">Ngôn ngữ</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,5 @@
<string name="import_csv_continue">继续</string>
<string name="warning_import_csv_file">"\n!!!⚠️警告:导入可能会导致交易重复!!!\n重复的交易无法轻松删除,您需要手动删除每一笔重复的交易!\n原因:我们无法解析交易 ID,因为 Ivy Wallet 仅使用 UUID,而其他应用程序不使用。\n如果您是从头开始的,不用担心-请忽略此消息。"</string>
<string name="select_tags">选择标签</string>
<string name="language">语言</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,5 @@
<string name="warning_import_csv_file">"\n!!!⚠️警告: 導入可能會重複交易!!!\n重複的交易無法輕易刪除,您需要手動刪除其中的每一項!\n原因: 我們無法解析交易 ID,因為 Ivy 錢包僅適用於 UUID,而其他應用程式則不能。\n如果您剛開始,不用擔心 -請忽略此訊息。"</string>
<string name="select_tags">選擇標籤</string>
<string name="bill_paid">您的 %1$s %2$s 帳單已支付</string>
<string name="language">语言</string>
</resources>
1 change: 1 addition & 0 deletions shared/ui/core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,5 @@
<string name="warning_import_csv_file">"\n!!!⚠️WARNING: Importing may duplicate transactions!!!\nDuplicate transactions can NOT be easily deleted and you'll need to remove manually each one of them! \nReason: We can't parse transaction ids because Ivy Wallet works only with UUID and other apps don't.\nIf you're starting fresh, no worries - kindly ignore this message."</string>
<string name="select_tags">Select Tags</string>
<string name="bill_paid">Your bill for %1$s %2$s has been paid</string>
<string name="language">Language</string>
</resources>

0 comments on commit 84fff68

Please sign in to comment.