From 0c7d8407f5b6c55614822c86f5a5e850def4e6db Mon Sep 17 00:00:00 2001 From: Dias Mashikov <50723693+diasmashikov@users.noreply.github.com> Date: Sat, 24 Feb 2024 17:16:22 -0500 Subject: [PATCH] [FEATURE] Fix issue #2984: Added UI to reflect category of Account Transfers (#2985) * Fix issue #2984: Categories are now reflected for each Account Transfer in the TransactionCard * Fix issue #2984: Made sure extra vertical Spacer() is not being rendered if user chooses no category for Account Transfer * Fix issue #2984: Added modifier to lacking TransactionHeaderRow * Fix issue #2984: Fixed CI complaints --- .../legacy/ui/theme/wallet/AmountCurrency.kt | 2 + .../component/transaction/TransactionCard.kt | 68 ++++++++++++------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/temp/legacy-code/src/main/java/com/ivy/legacy/legacy/ui/theme/wallet/AmountCurrency.kt b/temp/legacy-code/src/main/java/com/ivy/legacy/legacy/ui/theme/wallet/AmountCurrency.kt index 6c24388aec..8a1eb5ddc7 100644 --- a/temp/legacy-code/src/main/java/com/ivy/legacy/legacy/ui/theme/wallet/AmountCurrency.kt +++ b/temp/legacy-code/src/main/java/com/ivy/legacy/legacy/ui/theme/wallet/AmountCurrency.kt @@ -1,5 +1,6 @@ package com.ivy.wallet.ui.theme.wallet +import android.annotation.SuppressLint import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.width @@ -65,6 +66,7 @@ fun AmountCurrencyB1Row( } } +@SuppressLint("ComposeContentEmitterReturningValues") @Composable fun AmountCurrencyB1( amount: Double, diff --git a/temp/legacy-code/src/main/java/com/ivy/legacy/ui/component/transaction/TransactionCard.kt b/temp/legacy-code/src/main/java/com/ivy/legacy/ui/component/transaction/TransactionCard.kt index 00dbd3e808..5d3fd453ab 100644 --- a/temp/legacy-code/src/main/java/com/ivy/legacy/ui/component/transaction/TransactionCard.kt +++ b/temp/legacy-code/src/main/java/com/ivy/legacy/ui/component/transaction/TransactionCard.kt @@ -41,6 +41,7 @@ import com.ivy.legacy.utils.format import com.ivy.legacy.utils.formatNicely import com.ivy.legacy.utils.isNotNullOrBlank import com.ivy.legacy.utils.timeNowUTC +import com.ivy.navigation.Navigation import com.ivy.navigation.TransactionsScreen import com.ivy.navigation.navigation import com.ivy.resources.R @@ -109,7 +110,7 @@ fun TransactionCard( TransactionHeaderRow( transaction = transaction, categories = baseData.categories, - accounts = baseData.accounts + accounts = baseData.accounts, ) if (transaction.dueDate != null) { @@ -240,40 +241,35 @@ fun TransactionCard( private fun TransactionHeaderRow( transaction: Transaction, categories: List, - accounts: List + accounts: List, ) { val nav = navigation() + val category = category( + categoryId = transaction.categoryId, + categories = categories + ) + if (transaction.type == TransactionType.TRANSFER) { - TransferHeader( - accounts = accounts, - transaction = transaction - ) + Column( + modifier = Modifier.padding(horizontal = 20.dp), + ) { + if (category != null) { + CategoryBadgeDisplay(category, nav) + Spacer(modifier = Modifier.height(8.dp)) + } + TransferHeader( + accounts = accounts, + transaction = transaction + ) + } } else { Row( modifier = Modifier.padding(horizontal = 20.dp), verticalAlignment = Alignment.CenterVertically ) { - val category = category( - categoryId = transaction.categoryId, - categories = categories - ) - if (category != null) { - TransactionBadge( - text = category.name, - backgroundColor = category.color.toComposeColor(), - icon = category.icon, - defaultIcon = R.drawable.ic_custom_category_s - ) { - nav.navigateTo( - TransactionsScreen( - accountId = null, - categoryId = category.id - ) - ) - } - + CategoryBadgeDisplay(category, nav) Spacer(Modifier.width(12.dp)) } @@ -301,6 +297,27 @@ private fun TransactionHeaderRow( } } +@Composable +fun CategoryBadgeDisplay( + category: Category, + nav: Navigation, +) { + TransactionBadge( + text = category.name, + backgroundColor = category.color.toComposeColor(), + icon = category.icon, + defaultIcon = R.drawable.ic_custom_category_s + ) { + // Navigation logic + nav.navigateTo( + TransactionsScreen( + accountId = null, + categoryId = category.id + ) + ) + } +} + @Composable private fun TransactionBadge( text: String, @@ -351,7 +368,6 @@ private fun TransferHeader( ) { Row( modifier = Modifier - .padding(horizontal = 20.dp) .background(UI.colors.pure, UI.shapes.rFull), verticalAlignment = Alignment.CenterVertically ) {