From 0e112f2836451180bbc0fe85bbfaec3684da1355 Mon Sep 17 00:00:00 2001
From: Virat Kumar <155217162+viratde@users.noreply.github.com>
Date: Fri, 25 Oct 2024 23:43:45 +0530
Subject: [PATCH] Fix issue 3637 (#3647)
* Added Horizontal Linear Gradient To Transfer Header Composable, If feature is enabled through advances feature settings
* Added Ccontast color to text akso
* Horizontal Gradient depends on a single magic number
* Fixed Magic Number Link Check
* Fixed Magic Number Link Check
* Made Changed Based On Feedback, Added ide conf files in gitignore and Added Private constant in the composable also
* Corrected Formatting
* Added Remember call to transfer account and toAccount finding
* Format Corrections
* Removed extra files inside .idea folder
---
.gitignore | 1 +
.idea/inspectionProfiles/Project_Default.xml | 41 ------------
.../component/transaction/TransactionCard.kt | 64 +++++++++++++++----
3 files changed, 54 insertions(+), 52 deletions(-)
delete mode 100644 .idea/inspectionProfiles/Project_Default.xml
diff --git a/.gitignore b/.gitignore
index d0da9b341f..1cecc98015 100644
--- a/.gitignore
+++ b/.gitignore
@@ -62,6 +62,7 @@ captures/
.DS_Store
.idea/deploymentTargetSelector.xml
.idea/other.xml
+.idea/appInsightsSettings.xml
# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
deleted file mode 100644
index 44ca2d9b03..0000000000
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
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 51028297e9..46c2981b07 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
@@ -21,9 +21,11 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.testTag
@@ -325,7 +327,8 @@ private fun TransactionHeaderRow(
}
TransferHeader(
accounts = accounts,
- transaction = transaction
+ transaction = transaction,
+ shouldShowAccountSpecificColorInTransactions = shouldShowAccountSpecificColorInTransactions
)
}
} else {
@@ -454,22 +457,54 @@ private fun TransactionBadge(
}
}
+private const val TransferHeaderGradientThreshold = 0.35f
+
@Composable
private fun TransferHeader(
accounts: List,
- transaction: Transaction
+ transaction: Transaction,
+ shouldShowAccountSpecificColorInTransactions: Boolean
) {
+ val account = remember(accounts, transaction) {
+ accounts.find { transaction.accountId == it.id }
+ }
+ val toAccount = remember(accounts, transaction) {
+ accounts.find { transaction.toAccountId == it.id }
+ }
+
Row(
modifier = Modifier
- .background(UI.colors.pure, UI.shapes.rFull),
+ .then(
+ if (shouldShowAccountSpecificColorInTransactions && account != null && toAccount != null) {
+ Modifier
+ .background(
+ brush = Brush.horizontalGradient(
+ 0f to account.color.toComposeColor(),
+ (TransferHeaderGradientThreshold) to account.color.toComposeColor(),
+ (1f - TransferHeaderGradientThreshold) to toAccount.color.toComposeColor(),
+ 1f to toAccount.color.toComposeColor()
+ ),
+ shape = UI.shapes.rFull
+ )
+ } else {
+ Modifier.background(UI.colors.pure, UI.shapes.rFull)
+ }
+ ),
verticalAlignment = Alignment.CenterVertically
) {
Spacer(Modifier.width(8.dp))
- val account = accounts.find { transaction.accountId == it.id }
+ val accountContrastColor =
+ if (shouldShowAccountSpecificColorInTransactions && account != null) {
+ findContrastTextColor(account.color.toComposeColor())
+ } else {
+ UI.colors.pureInverse
+ }
+
ItemIconSDefaultIcon(
iconName = account?.icon,
- defaultIcon = R.drawable.ic_custom_account_s
+ defaultIcon = R.drawable.ic_custom_account_s,
+ tint = accountContrastColor
)
Spacer(Modifier.width(4.dp))
@@ -481,20 +516,27 @@ private fun TransferHeader(
text = account?.name.toString(),
style = UI.typo.c.style(
fontWeight = FontWeight.ExtraBold,
- color = UI.colors.pureInverse
+ color = accountContrastColor
)
)
Spacer(Modifier.width(12.dp))
- IvyIcon(icon = R.drawable.ic_arrow_right)
+ IvyIcon(icon = R.drawable.ic_arrow_right, tint = accountContrastColor)
Spacer(Modifier.width(12.dp))
- val toAccount = accounts.find { transaction.toAccountId == it.id }
+ val toAccountContrastColor =
+ if (shouldShowAccountSpecificColorInTransactions && toAccount != null) {
+ findContrastTextColor(toAccount.color.toComposeColor())
+ } else {
+ UI.colors.pureInverse
+ }
+
ItemIconSDefaultIcon(
iconName = toAccount?.icon,
- defaultIcon = R.drawable.ic_custom_account_s
+ defaultIcon = R.drawable.ic_custom_account_s,
+ tint = toAccountContrastColor
)
Spacer(Modifier.width(4.dp))
@@ -506,7 +548,7 @@ private fun TransferHeader(
text = toAccount?.name.toString(),
style = UI.typo.c.style(
fontWeight = FontWeight.ExtraBold,
- color = UI.colors.pureInverse
+ color = toAccountContrastColor
)
)
@@ -863,7 +905,7 @@ private fun PreviewTransfer_differentCurrency() {
dateTime = timeNowUTC().toInstant(ZoneOffset.UTC),
type = TransactionType.TRANSFER
),
- shouldShowAccountSpecificColorInTransactions = false,
+ shouldShowAccountSpecificColorInTransactions = true,
onPayOrGet = {},
) {
}