From e86cb60c2700778a44bf4bab8816bea5b98a38e6 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Mon, 17 Apr 2023 15:19:49 +0300 Subject: [PATCH] Fix transaction type parsing when there's bad chars --- .../com/ivy/wallet/ui/csv/domain/ParseFields.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseFields.kt b/app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseFields.kt index 64ab7c59bb..acaf94d5a6 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseFields.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csv/domain/ParseFields.kt @@ -65,16 +65,17 @@ fun parseTransactionType( } return tryParse { - with(value) { + val cleaned = value.filter { it.isLetterOrDigit() || it == '+' || it == '-' } + with(cleaned) { when { tryMeta(metadata.expense) -> TransactionType.EXPENSE tryMeta(metadata.income) -> TransactionType.INCOME tryMeta(metadata.transfer ?: "") -> TransactionType.TRANSFER - value.contains("income", ignoreCase = true) -> TransactionType.INCOME - value.contains("expense", ignoreCase = true) -> TransactionType.EXPENSE - value.contains("transfer", ignoreCase = true) -> TransactionType.TRANSFER - value.toDoubleOrNull()?.let { it > 0 } == true -> TransactionType.INCOME - value.toDoubleOrNull()?.let { it < 0 } == true -> TransactionType.EXPENSE + cleaned.contains("income", ignoreCase = true) -> TransactionType.INCOME + cleaned.contains("expense", ignoreCase = true) -> TransactionType.EXPENSE + cleaned.contains("transfer", ignoreCase = true) -> TransactionType.TRANSFER + cleaned.toDoubleOrNull()?.let { it > 0 } == true -> TransactionType.INCOME + cleaned.toDoubleOrNull()?.let { it < 0 } == true -> TransactionType.EXPENSE else -> null } }