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

Commit

Permalink
Merge branch 'Ivy-Apps:main' into fix-issue-3565
Browse files Browse the repository at this point in the history
  • Loading branch information
ikergcalvino authored Oct 1, 2024
2 parents 82a6b07 + 7e8cc57 commit 34bc15e
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 19 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ paparazzi = "1.3.3"
# Android
min-sdk = "28"
compile-sdk = "34"
version-name = "2024.09.22"
version-code = "199"
version-name = "2024.09.29"
version-code = "200"
jvm-target = "17"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface Features {
val showTitleSuggestions: BoolFeature
val showCategorySearchBar: BoolFeature
val hideTotalBalance: BoolFeature
val showDecimalNumber: BoolFeature

val allFeatures: List<BoolFeature>
}
16 changes: 14 additions & 2 deletions shared/domain/src/main/java/com/ivy/domain/features/IvyFeatures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class IvyFeatures @Inject constructor() : Features {

override val sortCategoriesAlphabetically = BoolFeature(
key = "sort_categories_alphabetically",
group = FeatureGroup.Other,
group = FeatureGroup.Category,
name = "Sort Categories Alphabetically",
description = "Sort income and expenses" +
" categories alphabetically"
Expand Down Expand Up @@ -52,13 +52,25 @@ class IvyFeatures @Inject constructor() : Features {
defaultValue = false
)

override val showDecimalNumber = BoolFeature(
key = "show_decimal_number",
group = FeatureGroup.Other,
name = "Show Decimal Number",
description = "Whether to show the decimal part in amounts",
defaultValue = true
)

override val allFeatures: List<BoolFeature>
get() = listOf(
sortCategoriesAlphabetically,
compactAccountsMode,
compactCategoriesMode,
showTitleSuggestions,
showCategorySearchBar,
hideTotalBalance
hideTotalBalance,
/* will be uncommented when this functionality
* will be available across the application in up-coming PRs
showDecimalNumber
*/
)
}
29 changes: 29 additions & 0 deletions shared/ui/core/src/main/java/com/ivy/ui/FormatMoneyUseCase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.ivy.ui

import android.content.Context
import com.ivy.domain.features.Features
import com.ivy.ui.time.DevicePreferences
import dagger.hilt.android.qualifiers.ApplicationContext
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import javax.inject.Inject

class FormatMoneyUseCase @Inject constructor(
private val features: Features,
private val devicePreferences: DevicePreferences,
@ApplicationContext private val context: Context
) {

private val locale = devicePreferences.locale()
private val withoutDecimalFormatter = DecimalFormat("###,###", DecimalFormatSymbols(locale))
private val withDecimalFormatter = DecimalFormat("###,###.00", DecimalFormatSymbols(locale))

suspend fun format(value: Double): String {
val showDecimalPoint = features.showDecimalNumber.isEnabled(context)

return when (showDecimalPoint) {
true -> withDecimalFormatter.format(value)
false -> withoutDecimalFormatter.format(value)
}
}
}
20 changes: 10 additions & 10 deletions shared/ui/core/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<string name="accounts">帳戶</string>
<string name="total">總計: %1$s %2$s</string>
<string name="month_income">本月營收</string>
<string name="month_income">本月收入</string>
<string name="month_expenses">本月支出</string>
<string name="excluded">(排除)</string>
<string name="income_uppercase">收入</string>
Expand Down Expand Up @@ -101,10 +101,10 @@
<string name="savings_goal">儲蓄目標</string>
<string name="quick_access">快速存取</string>
<string name="settings">設定</string>
<string name="light_mode">明亮模式</string>
<string name="dark_mode">深色模式</string>
<string name="amoled_mode">Amoled 純黑模式</string>
<string name="auto_mode">自動模式</string>
<string name="light_mode">亮色主題</string>
<string name="dark_mode">暗色主題</string>
<string name="amoled_mode">黑色主題</string>
<string name="auto_mode">系統主題</string>
<string name="planned_payments">經常交易</string>
<string name="share_ivy">分享 Ivy</string>
<string name="reports">報表</string>
Expand Down Expand Up @@ -189,9 +189,9 @@
<string name="planned_for_uppercase">"計畫用於 "</string>
<string name="null_text">空值</string>
<string name="starts_date">"開始 %1$s"</string>
<string name="add_payment">新增付款</string>
<string name="one_time_payments">一次性付款</string>
<string name="recurring_payments">定期付款</string>
<string name="add_payment">新增交易</string>
<string name="one_time_payments">一次性交易</string>
<string name="recurring_payments">定期交易</string>
<string name="no_planned_payments">沒有經常交易</string>
<string name="no_planned_payments_description">您沒有任何經常交易。\n點擊底部的\'⚡\'按鈕即可新增。</string>
<string name="planned_payments_inline">經常交易</string>
Expand Down Expand Up @@ -279,9 +279,9 @@
<string name="sync_failed">同步失敗。點選同步</string>
<string name="anonymous">匿名</string>
<string name="export_to_csv">匯出為 CSV</string>
<string name="left_to_spend">剩下的花</string>
<string name="left_to_spend">剩餘費用</string>
<string name="budget_exceeded_by">超出預算</string>
<string name="buffer_exceeded_by">緩衝區超出</string>
<string name="buffer_exceeded_by">低於目標</string>
<string name="set_transaction_type">設定交易類型</string>
<string name="transfer">傳輸</string>
<string name="selected_text">已選擇</string>
Expand Down
73 changes: 73 additions & 0 deletions shared/ui/core/src/test/java/com/ivy/ui/FormatMoneyUseCaseTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.ivy.ui

import android.content.Context
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import com.ivy.domain.features.Features
import com.ivy.ui.time.DevicePreferences
import io.kotest.common.runBlocking
import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
import org.junit.Test
import org.junit.runner.RunWith
import java.util.Locale

@RunWith(TestParameterInjector::class)
class FormatMoneyUseCaseTest {

private val features = mockk<Features>()
private val devicePreferences = mockk<DevicePreferences>()

enum class MoneyFormatterTestCase(
val amount: Double,
val showDecimal: Boolean,
val locale: Locale,
val expectedOutput: String
) {
ENG_SHOW_DECIMAL(
amount = 1000.12,
showDecimal = true,
locale = Locale.ENGLISH,
expectedOutput = "1,000.12"
),
ENG_HIDE_DECIMAL(
amount = 1000.12,
showDecimal = false,
locale = Locale.ENGLISH,
expectedOutput = "1,000"
),
GERMAN_SHOW_DECIMAL(
amount = 1000.12,
showDecimal = true,
locale = Locale.GERMAN,
expectedOutput = "1.000,12"
),
GERMAN_HIDE_DECIMAL(
amount = 1000.12,
showDecimal = false,
locale = Locale.GERMAN,
expectedOutput = "1.000"
),
}

private lateinit var formatMoneyUseCase: FormatMoneyUseCase

@Test
fun `validate decimal formatting`(
@TestParameter testCase: MoneyFormatterTestCase
): Unit = runBlocking {
// given
val context = mockk<Context>()
every { features.showDecimalNumber } returns mockk { coEvery { isEnabled(any()) } returns testCase.showDecimal }
every { devicePreferences.locale() } returns testCase.locale
formatMoneyUseCase = FormatMoneyUseCase(features, devicePreferences, context)

// when
val result = formatMoneyUseCase.format(value = testCase.amount)

// then
result shouldBe testCase.expectedOutput
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.ivy.wallet.domain.action.viewmodel.home

import com.ivy.base.time.TimeProvider
import com.ivy.data.model.Transaction
import com.ivy.frp.action.FPAction
import com.ivy.frp.lambda
import com.ivy.frp.then
import com.ivy.legacy.utils.dateNowUTC
import com.ivy.wallet.domain.action.account.AccountByIdAct
import com.ivy.wallet.domain.action.exchange.ExchangeAct
import com.ivy.wallet.domain.action.exchange.actInput
Expand All @@ -22,14 +22,15 @@ import javax.inject.Inject
class DueTrnsInfoAct @Inject constructor(
private val dueTrnsAct: DueTrnsAct,
private val accountByIdAct: AccountByIdAct,
private val exchangeAct: ExchangeAct
private val exchangeAct: ExchangeAct,
private val timeProvider: TimeProvider
) : FPAction<DueTrnsInfoAct.Input, DueTrnsInfoAct.Output>() {

override suspend fun Input.compose(): suspend () -> Output =
suspend {
range
} then dueTrnsAct then { trns ->
val dateNow = dateNowUTC()
val dateNow = timeProvider.localDateNow()
trns.filter {
this.dueFilter(it, dateNow)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.ivy.data.model.IntervalType
import com.ivy.design.api.LocalTimeProvider
import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.style
import com.ivy.legacy.IvyWalletCtx
Expand All @@ -47,7 +48,6 @@ import com.ivy.legacy.utils.hideKeyboard
import com.ivy.legacy.utils.onScreenStart
import com.ivy.design.utils.thenIf
import com.ivy.legacy.utils.rememberInteractionSource
import com.ivy.legacy.utils.timeNowUTC
import com.ivy.ui.R
import com.ivy.wallet.ui.theme.Gradient
import com.ivy.wallet.ui.theme.GradientIvy
Expand Down Expand Up @@ -80,8 +80,9 @@ fun BoxWithConstraintsScope.RecurringRuleModal(
dismiss: () -> Unit,
onRuleChanged: (LocalDateTime, oneTime: Boolean, Int?, IntervalType?) -> Unit,
) {
val timeProvider = LocalTimeProvider.current
var startDate by remember(modal) {
mutableStateOf(modal?.initialStartDate ?: timeNowUTC())
mutableStateOf(modal?.initialStartDate ?: timeProvider.localNow())
}
var oneTime by remember(modal) {
mutableStateOf(modal?.initialOneTime ?: false)
Expand Down

0 comments on commit 34bc15e

Please sign in to comment.