From 10ff0ee321b7da299cae6f9aaf2cbeed29adafae Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Sat, 15 Apr 2023 23:17:07 +0300 Subject: [PATCH] WIP: Fix bugs (terrible code!) --- app/src/main/java/com/ivy/wallet/ui/csv/CSVScreen.kt | 5 ++++- .../java/com/ivy/wallet/ui/csv/domain/ParseStatus.kt | 11 ++++++++++- .../main/java/com/ivy/wallet/ui/csv/domain/Parser.kt | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/ui/csv/domain/Parser.kt diff --git a/app/src/main/java/com/ivy/wallet/ui/csv/CSVScreen.kt b/app/src/main/java/com/ivy/wallet/ui/csv/CSVScreen.kt index 8bb9e97b68..09d69d33fd 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csv/CSVScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csv/CSVScreen.kt @@ -304,13 +304,16 @@ private fun AmountMetadata( multiplier < 0 -> "/$multiplier" multiplier > 1 -> "*$multiplier" else -> "None" - } + }, + style = UI.typo.nB2, + color = UI.colors.primary, ) Spacer8(horizontal = true) Button(onClick = { onEvent( CSVEvent.AmountMultiplier( when { + multiplier == -10 -> 1 multiplier == -1 -> 10 multiplier > 0 -> multiplier * 10 else -> multiplier / 10 diff --git a/app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseStatus.kt b/app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseStatus.kt index e0d1c0d76a..c17b6b3036 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseStatus.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseStatus.kt @@ -34,7 +34,16 @@ private fun parseAmountStatus( ): MappingStatus = tryStatus { val values = rows.values(mapping) .mapNotNull { - it.toDoubleOrNull()?.plus(mapping.metadata)?.let(::abs) + val multiplier = when (mapping.metadata) { + -1000 -> 0.001 + -100 -> 0.01 + -10 -> 0.1 + 10 -> 10.0 + 100 -> 100.0 + 1000 -> 1000.0 + else -> 1.0 + } + it.toDoubleOrNull()?.times(multiplier)?.let(::abs) } MappingStatus( diff --git a/app/src/main/java/com/ivy/wallet/ui/csv/domain/Parser.kt b/app/src/main/java/com/ivy/wallet/ui/csv/domain/Parser.kt new file mode 100644 index 0000000000..fb0314e9bf --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/ui/csv/domain/Parser.kt @@ -0,0 +1,2 @@ +package com.ivy.wallet.ui.csv.domain +