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

Commit

Permalink
Implement CSVScreen.kt UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Apr 15, 2023
1 parent f051ae3 commit d0d31cb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
31 changes: 26 additions & 5 deletions app/src/main/java/com/ivy/wallet/ui/csv/CSVScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private fun UI(
if (state.columns != null && state.optional != null) {
optionalFields(state.columns, state.optional, onEvent = onEvent)
}
continueButton(state.continueEnabled, onEvent)
}
}

Expand Down Expand Up @@ -191,9 +192,9 @@ private fun <M> LazyListScope.mappingRow(
style = UI.typo.b1.colorAs(UI.colors.primary),
)
Spacer(modifier = Modifier.height(4.dp))
Text(text = mapping.helpInfo, style = UI.typo.c)
Text(text = mapping.helpInfo, style = UI.typo.c.colorAs(UI.colors.gray))
Spacer8()
Text(text = "Choose a column:", style = UI.typo.b2)
Text(text = "Choose a matching CSV column:", style = UI.typo.b2)
Spacer(modifier = Modifier.height(4.dp))
Row(
modifier = Modifier
Expand Down Expand Up @@ -239,7 +240,7 @@ fun LazyListScope.sectionDivider(text: String) {
If the parsing is successful the border will turn green.
""".trimIndent(),
style = UI.typo.nB2,
color = UI.colors.pureInverse
color = UI.colors.gray
)
Spacer8()
}
Expand Down Expand Up @@ -481,5 +482,25 @@ fun LazyListScope.optionalFields(
)
}



private fun LazyListScope.continueButton(
enabled: Boolean,
onEvent: (CSVEvent) -> Unit
) {
item {
Spacer8()
Spacer8()
Button(
modifier = Modifier
.fillMaxWidth()
.height(48.dp),
enabled = enabled,
onClick = {
onEvent(CSVEvent.Continue)
}
) {
Text(text = "Continue")
}
Spacer8()
Spacer8()
}
}
5 changes: 2 additions & 3 deletions app/src/main/java/com/ivy/wallet/ui/csv/CSVViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class CSVViewModel @Inject constructor(
fun uiState(): CSVState {
val sampleCSV = remember(csv) {
// drop the header
csv?.drop(1)?.take(10)
csv?.drop(1)?.shuffled()?.take(SAMPLE_SIZE)
}

val important = importantFields(sampleCSV)
Expand Down Expand Up @@ -248,7 +248,7 @@ class CSVViewModel @Inject constructor(
private fun optionalFields(sampleCSV: List<CSVRow>?): OptionalFields? {
return produceState<OptionalFields?>(
initialValue = null,
sampleCSV, toAccount, toAccountCurrency,
sampleCSV, category, title, description,
) {
val result = withContext(Dispatchers.Default) {
if (sampleCSV != null) {
Expand Down Expand Up @@ -403,7 +403,6 @@ class CSVViewModel @Inject constructor(
}



// region Boiler-plate
private val events = MutableSharedFlow<CSVEvent>(replay = 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ivy.wallet.ui.csv.CSVRow
import com.ivy.wallet.ui.csv.ColumnMapping
import com.ivy.wallet.ui.csv.MappingStatus

const val SAMPLE_SIZE = 20

fun <T, M> List<CSVRow>.parseStatus(
mapping: ColumnMapping<M>,
Expand All @@ -15,7 +16,7 @@ fun <T, M> List<CSVRow>.parseStatus(

MappingStatus(
sampleValues = parsed.map { it.toString() },
success = parsed.size == this.size
success = parsed.size >= SAMPLE_SIZE / 2
)
}

Expand Down

0 comments on commit d0d31cb

Please sign in to comment.