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

Refactor TransactionCard UI to support compactMode #3623

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion screen/home/src/main/java/com/ivy/home/HomeState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ data class HomeState(
val customerJourneyCards: ImmutableList<CustomerJourneyCardModel>,
val hideBalance: Boolean,
val hideIncome: Boolean,
val expanded: Boolean
val expanded: Boolean,
val compactTransactionsModeEnabled: Boolean
)
10 changes: 6 additions & 4 deletions screen/home/src/main/java/com/ivy/home/HomeTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fun BoxWithConstraintsScope.HomeUi(

stats = uiState.stats,
history = uiState.history,

compactTransactionsEnabled = uiState.compactTransactionsModeEnabled,
customerJourneyCards = uiState.customerJourneyCards,

onPayOrGet = forward<Transaction>() then2 {
Expand Down Expand Up @@ -295,7 +295,7 @@ fun HomeLazyColumn(
balance: BigDecimal,
stats: IncomeExpensePair,
history: ImmutableList<TransactionHistoryItem>,

compactTransactionsEnabled: Boolean,
customerJourneyCards: ImmutableList<CustomerJourneyCardModel>,

setUpcomingExpanded: (Boolean) -> Unit,
Expand Down Expand Up @@ -387,7 +387,8 @@ fun HomeLazyColumn(
)
),
onSkipTransaction = onSkipTransaction,
onSkipAllTransactions = onSkipAllTransactions
onSkipAllTransactions = onSkipAllTransactions,
compactModeEnabled = compactTransactionsEnabled
)
}
}
Expand Down Expand Up @@ -428,7 +429,8 @@ private fun BoxWithConstraintsScope.PreviewHomeTab(isDark: Boolean = false) {
period = TimePeriod(month = Month.monthsList().first(), year = 2023),
hideBalance = false,
hideIncome = false,
expanded = false
expanded = false,
compactTransactionsModeEnabled = false
),
onEvent = {}
)
Expand Down
10 changes: 9 additions & 1 deletion screen/home/src/main/java/com/ivy/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.ivy.base.time.TimeProvider
import com.ivy.data.model.primitive.AssetCode
import com.ivy.data.repository.CategoryRepository
import com.ivy.data.repository.mapper.TransactionMapper
import com.ivy.domain.features.Features
import com.ivy.domain.usecase.exchange.SyncExchangeRatesUseCase
import com.ivy.frp.fixUnit
import com.ivy.frp.then
Expand Down Expand Up @@ -81,6 +82,7 @@ class HomeViewModel @Inject constructor(
private val upcomingAct: UpcomingAct,
private val overdueAct: OverdueAct,
private val hasTrnsAct: HasTrnsAct,
private val features: Features,
private val startDayOfMonthAct: StartDayOfMonthAct,
private val shouldHideBalanceAct: ShouldHideBalanceAct,
private val shouldHideIncomeAct: ShouldHideIncomeAct,
Expand Down Expand Up @@ -151,7 +153,8 @@ class HomeViewModel @Inject constructor(
customerJourneyCards = getCustomerJourneyCards(),
hideBalance = getHideBalance(),
expanded = getExpanded(),
hideIncome = getHideIncome()
hideIncome = getHideIncome(),
compactTransactionsModeEnabled = getCompactTransactionsMode()
)
}

Expand Down Expand Up @@ -225,6 +228,11 @@ class HomeViewModel @Inject constructor(
return hideIncome
}

@Composable
private fun getCompactTransactionsMode(): Boolean {
return features.compactTransactionsMode.asEnabledState()
}

override fun onEvent(event: HomeEvent) {
viewModelScope.launch {
when (event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ private fun BoxWithConstraintsScope.UI(
},
onSkipAllTransactions = {
onEventHandler.invoke(ReportScreenEvent.SkipTransactionsLegacy(transactions = it))
}
},
compactModeEnabled = state.compactTransactionsModeEnabled
)
} else {
item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ data class ReportScreenState(
val filterOverlayVisible: Boolean = false,
val showTransfersAsIncExpCheckbox: Boolean = false,
val treatTransfersAsIncExp: Boolean = false,
val allTags: ImmutableList<Tag> = persistentListOf()
val allTags: ImmutableList<Tag> = persistentListOf(),
val compactTransactionsModeEnabled: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.ivy.data.repository.mapper.TransactionMapper
import com.ivy.data.temp.migration.getTransactionType
import com.ivy.data.temp.migration.getValue
import com.ivy.domain.RootScreen
import com.ivy.domain.features.Features
import com.ivy.domain.usecase.csv.ExportCsvUseCase
import com.ivy.frp.filterSuspend
import com.ivy.legacy.IvyWalletCtx
Expand Down Expand Up @@ -80,6 +81,7 @@ class ReportViewModel @Inject constructor(
private val ivyContext: IvyWalletCtx,
private val exchangeAct: ExchangeAct,
private val accountsAct: AccountsAct,
private val features: Features,
private val categoryRepository: CategoryRepository,
private val trnsWithDateDivsAct: TrnsWithDateDivsAct,
private val calcTrnsIncomeExpenseAct: CalcTrnsIncomeExpenseAct,
Expand Down Expand Up @@ -157,10 +159,16 @@ class ReportViewModel @Inject constructor(
upcomingExpenses = upcomingExpenses,
upcomingIncome = upcomingIncome,
upcomingTransactions = upcomingTransactions,
allTags = allTags
allTags = allTags,
compactTransactionsModeEnabled = getCompactTransactionsMode()
)
}

@Composable
private fun getCompactTransactionsMode(): Boolean {
return features.compactTransactionsMode.asEnabledState()
}

override fun onEvent(event: ReportScreenEvent) {
viewModelScope.launch(Dispatchers.Default) {
when (event) {
Expand Down
6 changes: 4 additions & 2 deletions screen/search/src/main/java/com/ivy/search/SearchScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private fun SearchUi(
onPayOrGet = { },
emptyStateTitle = emptyStateTitle,
emptyStateText = emptyStateText,
dateDividerMarginTop = 16.dp
dateDividerMarginTop = 16.dp,
compactModeEnabled = uiState.compactTransactionsModeEnabled
)

item {
Expand Down Expand Up @@ -134,7 +135,8 @@ private fun Preview(isDark: Boolean = false) {
transactions = persistentListOf(),
baseCurrency = "",
accounts = persistentListOf(),
categories = persistentListOf()
categories = persistentListOf(),
compactTransactionsModeEnabled = false
),
onEvent = {}
)
Expand Down
3 changes: 2 additions & 1 deletion screen/search/src/main/java/com/ivy/search/SearchState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ data class SearchState(
val transactions: ImmutableList<TransactionHistoryItem>,
val baseCurrency: String,
val accounts: ImmutableList<Account>,
val categories: ImmutableList<Category>
val categories: ImmutableList<Category>,
val compactTransactionsModeEnabled: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.ivy.data.model.primitive.NotBlankTrimmedString
import com.ivy.ui.ComposeViewModel
import com.ivy.data.model.Category
import com.ivy.data.repository.CategoryRepository
import com.ivy.domain.features.Features
import com.ivy.legacy.datamodel.Account
import com.ivy.legacy.utils.getDefaultFIATCurrency
import com.ivy.legacy.utils.ioThread
Expand All @@ -29,6 +30,7 @@ import javax.inject.Inject
class SearchViewModel @Inject constructor(
private val trnsWithDateDivsAct: TrnsWithDateDivsAct,
private val accountsAct: AccountsAct,
private val features: Features,
private val categoryRepository: CategoryRepository,
private val baseCurrencyAct: BaseCurrencyAct,
private val allTrnsAct: AllTrnsAct
Expand All @@ -52,10 +54,16 @@ class SearchViewModel @Inject constructor(
transactions = transactions.value,
baseCurrency = baseCurrency.value,
accounts = accounts.value,
categories = categories.value
categories = categories.value,
compactTransactionsModeEnabled = getCompactTransactionsMode()
)
}

@Composable
private fun getCompactTransactionsMode(): Boolean {
return features.compactTransactionsMode.asEnabledState()
}

override fun onEvent(event: SearchEvent) {
when (event) {
is SearchEvent.Search -> search(event.query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ fun BoxWithConstraintsScope.TransactionsScreen(screen: TransactionsScreen) {
onChoosePeriodModal = {
viewModel.onEvent(TransactionsEvent.OnChoosePeriodModalData(it))
},
choosePeriodModal = uiState.choosePeriodModal
choosePeriodModal = uiState.choosePeriodModal,
compactTransactionsEnabled = uiState.compactTransactionsModeEnabled
)
}

Expand Down Expand Up @@ -231,7 +232,7 @@ private fun BoxWithConstraintsScope.UI(
choosePeriodModal: ChoosePeriodModalData?,

history: ImmutableList<TransactionHistoryItem>,

compactTransactionsEnabled: Boolean,
onPreviousMonth: () -> Unit,
onNextMonth: () -> Unit,
onSetPeriod: (TimePeriod) -> Unit,
Expand All @@ -240,7 +241,6 @@ private fun BoxWithConstraintsScope.UI(
onDelete: () -> Unit,
deleteModal1Visible: Boolean,
onDeleteModal1Visible: (Boolean) -> Unit,

initWithTransactions: Boolean = false,
treatTransfersAsIncomeExpense: Boolean = false,
upcomingExpanded: Boolean = true,
Expand Down Expand Up @@ -410,7 +410,6 @@ private fun BoxWithConstraintsScope.UI(
lastItemSpacer = with(density) {
(ivyContext.screenHeight * 0.7f).toDp()
},

onPayOrGet = onPayOrGet,
onSkipTransaction = onSkipTransaction,
onSkipAllTransactions = {
Expand All @@ -425,7 +424,8 @@ private fun BoxWithConstraintsScope.UI(
timeConverter = timeConverter,
timeFormatter = timeFormatter,
)
)
),
compactModeEnabled = compactTransactionsEnabled,
)
}
}
Expand Down Expand Up @@ -857,6 +857,7 @@ private fun BoxWithConstraintsScope.Preview_empty() {
onChoosePeriodModal = {},
choosePeriodModal = null,
screen = TransactionsScreen(),
compactTransactionsEnabled = false
)
}
}
Expand Down Expand Up @@ -903,6 +904,7 @@ private fun BoxWithConstraintsScope.Preview_crypto() {
onChoosePeriodModal = {},
choosePeriodModal = null,
screen = TransactionsScreen(),
compactTransactionsEnabled = false
)
}
}
Expand Down Expand Up @@ -949,6 +951,7 @@ private fun BoxWithConstraintsScope.Preview_empty_upcoming() {
onChoosePeriodModal = {},
choosePeriodModal = null,
screen = TransactionsScreen(),
compactTransactionsEnabled = false
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ data class TransactionsState(
val skipAllModalVisible: Boolean,
val deleteModal1Visible: Boolean,
val choosePeriodModal: ChoosePeriodModalData?,
val compactTransactionsModeEnabled: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.ivy.data.repository.TagRepository
import com.ivy.data.repository.TransactionRepository
import com.ivy.data.repository.mapper.TransactionMapper
import com.ivy.design.l0_system.RedLight
import com.ivy.domain.features.Features
import com.ivy.frp.then
import com.ivy.legacy.IvyWalletCtx
import com.ivy.legacy.data.model.TimePeriod
Expand Down Expand Up @@ -83,6 +84,7 @@ class TransactionsViewModel @Inject constructor(
private val sharedPrefs: SharedPrefs,
private val accountsAct: AccountsAct,
private val accTrnsAct: AccTrnsAct,
private val features: Features,
private val trnsWithDateDivsAct: LegacyTrnsWithDateDivsAct,
private val baseCurrencyAct: BaseCurrencyAct,
private val calcAccBalanceAct: CalcAccBalanceAct,
Expand Down Expand Up @@ -161,7 +163,8 @@ class TransactionsViewModel @Inject constructor(
enableDeletionButton = getEnableDeletionButton(),
skipAllModalVisible = getSkipAllModalVisible(),
deleteModal1Visible = getDeleteModal1Visible(),
choosePeriodModal = getChoosePeriodModal()
choosePeriodModal = getChoosePeriodModal(),
compactTransactionsModeEnabled = getCompactTransactionsMode()
)
}

Expand Down Expand Up @@ -295,6 +298,11 @@ class TransactionsViewModel @Inject constructor(
return choosePeriodModal.value
}

@Composable
private fun getCompactTransactionsMode(): Boolean {
return features.compactTransactionsMode.asEnabledState()
}

override fun onEvent(event: TransactionsEvent) {
when (event) {
is TransactionsEvent.Delete -> delete(event.screen)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.ivy.domain.features

enum class FeatureGroup {
Category, Account, Other
Transactions, Category, Account, Other
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ivy.domain.features

interface Features {
val compactTransactionsMode: BoolFeature
val sortCategoriesAscending: BoolFeature
val compactAccountsMode: BoolFeature
val compactCategoriesMode: BoolFeature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import javax.inject.Singleton
@Singleton
class IvyFeatures @Inject constructor() : Features {

override val compactTransactionsMode = BoolFeature(
key = "compact_transactions_ui",
group = FeatureGroup.Transactions,
name = "Compact transaction cards",
description = "Simplified design of the transaction card"
)

override val sortCategoriesAscending = BoolFeature(
key = "sort_categories_ascending",
group = FeatureGroup.Category,
Expand Down Expand Up @@ -69,6 +76,7 @@ class IvyFeatures @Inject constructor() : Features {

override val allFeatures: List<BoolFeature>
get() = listOf(
compactTransactionsMode,
sortCategoriesAscending,
compactAccountsMode,
compactCategoriesMode,
Expand Down
2 changes: 2 additions & 0 deletions shared/ui/core/src/main/res/values-gl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@
<string name="warning_import_csv_file">"\n!!!⚠️ADVERTENCIA: A importación pode duplicar as transaccións!!!\nAs transaccións duplicadas non se poden eliminar facilmente e terás que eliminalas manualmente unha a unha! \nMotivo: Non podemos analizar os identificadores de transacción porque Ivy Wallet só funciona con UUID e outras aplicacións non.\nSe estás comezando de cero, non te preocupes - ignora amablemente esta mensaxe."</string>
<string name="select_tags">Seleccionar etiquetas</string>
<string name="bill_paid">A túa factura de %1$s %2$s foi pagada</string>
<!-- TODO - Edit this 'income_received' accordingly-->
<string name="income_received">A túa factura de %1$s %2$s foi pagada</string>
<string name="language">Lingua</string>
<string name="advanced_features">Funcionalidades avanzadas</string>
</resources>
2 changes: 2 additions & 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 @@ -493,6 +493,8 @@
<string name="warning_import_csv_file">"\n!!!⚠️警告: 導入可能會重複交易!!!\n重複的交易無法輕易刪除,您需要手動刪除其中的每一項!\n原因: 我們無法解析交易 ID,因為 Ivy wallet 僅適用於 UUID,而其他應用程式則不能。\n如果您剛開始,不用擔心 -請忽略此訊息。"</string>
<string name="select_tags">選擇標籤</string>
<string name="bill_paid">您的 %1$s %2$s 帳單已支付</string>
<!-- TODO - Edit this 'income_received' accordingly-->
<string name="income_received">您的 %1$s %2$s 帳單已支付</string>
<string name="language">語言</string>
<string name="advanced_features">進階功能</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 @@ -493,6 +493,7 @@
<string name="warning_import_csv_file">"\n!!!⚠️ WARNING: Importing may create duplicate transactions!!!\nPlease note that duplicate transactions cannot be easily removed and will need to be deleted individually.\nReason: We cannot parse transaction IDs because Ivy Wallet uses UUIDs exclusively, while other apps do not.\nIf you\'re starting fresh, you can safely 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="income_received">Income for %1$s %2$s received</string>
<string name="language">Language</string>
<string name="advanced_features">Advanced features</string>
</resources>
Loading
Loading