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

Commit

Permalink
WIP: Prototype almost done (ugly code!)
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Apr 15, 2023
1 parent d0d31cb commit 0b851db
Show file tree
Hide file tree
Showing 6 changed files with 385 additions and 19 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/csv/CSVEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ sealed interface CSVEvent {

data class MapToAccount(val index: Int, val name: String) : CSVEvent
data class MapToAccountCurrency(val index: Int, val name: String) : CSVEvent
data class MapToAmount(val index: Int, val name: String) : CSVEvent
data class ToAmountMetaChange(val multiplier: Int) : CSVEvent

data class MapCategory(val index: Int, val name: String) : CSVEvent
data class MapTitle(val index: Int, val name: String) : CSVEvent
Expand Down
47 changes: 28 additions & 19 deletions app/src/main/java/com/ivy/wallet/ui/csv/CSVScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ fun LazyListScope.importantFields(
status = importantFields.amountStatus,
onMapTo = { index, name -> onEvent(CSVEvent.MapAmount(index, name)) },
metadataContent = { multiplier ->
AmountMetadata(multiplier = multiplier, onEvent = onEvent)
AmountMetadata(multiplier = multiplier, onMetaChange = {
onEvent(CSVEvent.AmountMultiplier(it))
})
}
)
mappingRow(
Expand Down Expand Up @@ -297,18 +299,16 @@ fun LazyListScope.importantFields(
@Composable
private fun AmountMetadata(
multiplier: Int,
onEvent: (CSVEvent) -> Unit,
onMetaChange: (Int) -> Unit,
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Button(onClick = {
onEvent(
CSVEvent.AmountMultiplier(
when {
multiplier < 0 -> multiplier * 10
multiplier == 1 -> -10
else -> multiplier / 10
}
)
onMetaChange(
when {
multiplier < 0 -> multiplier * 10
multiplier == 1 -> -10
else -> multiplier / 10
}
)
}) {
Text(text = "/10")
Expand All @@ -325,15 +325,13 @@ private fun AmountMetadata(
)
Spacer8(horizontal = true)
Button(onClick = {
onEvent(
CSVEvent.AmountMultiplier(
when {
multiplier == -10 -> 1
multiplier == -1 -> 10
multiplier > 0 -> multiplier * 10
else -> multiplier / 10
}
)
onMetaChange(
when {
multiplier == -10 -> 1
multiplier == -1 -> 10
multiplier > 0 -> multiplier * 10
else -> multiplier / 10
}
)
}) {
Text(text = "*10")
Expand Down Expand Up @@ -454,6 +452,17 @@ fun LazyListScope.transferFields(
status = transferFields.toAccountCurrencyStatus,
onMapTo = { index, name -> onEvent(CSVEvent.MapToAccountCurrency(index, name)) },
)
mappingRow(
columns = columns,
mapping = transferFields.toAmount,
status = transferFields.toAmountStatus,
onMapTo = { index, name -> onEvent(CSVEvent.MapToAmount(index, name)) },
metadataContent = { multiplier ->
AmountMetadata(multiplier = multiplier, onMetaChange = {
onEvent(CSVEvent.ToAmountMetaChange(it))
})
}
)
}

fun LazyListScope.optionalFields(
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/csv/CSVState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ data class TransferFields(
val toAccountStatus: MappingStatus,
val toAccountCurrency: ColumnMapping<Unit>,
val toAccountCurrencyStatus: MappingStatus,
val toAmount: ColumnMapping<Int>,
val toAmountStatus: MappingStatus,
)

data class OptionalFields(
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/csv/CSVViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import javax.inject.Inject
@HiltViewModel
class CSVViewModel @Inject constructor(
private val fileReader: IvyFileReader,
private val csvImporterV2: CSVImporterV2,
) : ViewModel() {

private var columns by mutableStateOf<CSVRow?>(null)
Expand Down Expand Up @@ -124,6 +125,19 @@ class CSVViewModel @Inject constructor(
metadata = Unit,
)
)
private var toAmount by mutableStateOf(
ColumnMapping(
ivyColumn = "To Amount",
helpInfo = """
The amount that the "To Account" will receive".
Skip it if there's no such.
""".trimIndent(),
name = "",
index = -1,
required = false,
metadata = 1,
)
)
// endregion

// region Optional fields
Expand Down Expand Up @@ -237,6 +251,8 @@ class CSVViewModel @Inject constructor(
toAccountCurrency,
::parseToAccountCurrency
),
toAmount = toAmount,
toAmountStatus = sampleCSV.parseStatus(toAmount, ::parseAmount)
)
} else null
}
Expand Down Expand Up @@ -346,6 +362,17 @@ class CSVViewModel @Inject constructor(
)
}
CSVEvent.Continue -> handleContinue()
is CSVEvent.MapToAmount -> {
toAmount = toAmount.copy(
index = event.index,
name = event.name
)
}
is CSVEvent.ToAmountMetaChange -> {
toAmount = toAmount.copy(
metadata = event.multiplier
)
}
}
}

Expand Down
Loading

0 comments on commit 0b851db

Please sign in to comment.