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 5f51cef028..2758fc5dd6 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 @@ -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) } } @@ -191,9 +192,9 @@ private fun 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 @@ -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() } @@ -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() + } +} diff --git a/app/src/main/java/com/ivy/wallet/ui/csv/CSVViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/csv/CSVViewModel.kt index 7afa4f9393..c31e40d49e 100644 --- a/app/src/main/java/com/ivy/wallet/ui/csv/CSVViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/csv/CSVViewModel.kt @@ -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) @@ -248,7 +248,7 @@ class CSVViewModel @Inject constructor( private fun optionalFields(sampleCSV: List?): OptionalFields? { return produceState( initialValue = null, - sampleCSV, toAccount, toAccountCurrency, + sampleCSV, category, title, description, ) { val result = withContext(Dispatchers.Default) { if (sampleCSV != null) { @@ -403,7 +403,6 @@ class CSVViewModel @Inject constructor( } - // region Boiler-plate private val events = MutableSharedFlow(replay = 0) 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 2935ca094f..f129107477 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 @@ -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 List.parseStatus( mapping: ColumnMapping, @@ -15,7 +16,7 @@ fun List.parseStatus( MappingStatus( sampleValues = parsed.map { it.toString() }, - success = parsed.size == this.size + success = parsed.size >= SAMPLE_SIZE / 2 ) }