From 22fa7aaa6bf5c6639da92759b5f941f66c7fff86 Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Mon, 17 Apr 2023 19:53:40 +0300 Subject: [PATCH] Fix Onboarding manual import UX --- .../java/com/ivy/wallet/ui/csv/CSVScreen.kt | 46 +++++++++++++++---- .../com/ivy/wallet/ui/csv/CSVViewModel.kt | 1 + 2 files changed, 37 insertions(+), 10 deletions(-) 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 58ab72e720..a1bed8a8ca 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 @@ -13,11 +13,12 @@ import androidx.compose.material.Button import androidx.compose.material.ButtonDefaults import androidx.compose.material.Text import androidx.compose.material.TextField -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember +import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel @@ -41,7 +42,11 @@ fun CSVScreen( val onboardingViewModel: OnboardingViewModel = viewModel() when (val ui = state.uiState) { - UIState.Idle -> ImportUI(state = state, onEvent = viewModel::onEvent) + UIState.Idle -> ImportUI( + state = state, + launchedFromOnboarding = screen.launchedFromOnboarding, + onEvent = viewModel::onEvent + ) is UIState.Processing -> ImportProcessing(progressPercent = ui.percent) is UIState.Result -> ImportResultUI( result = ui.importResult, @@ -63,6 +68,7 @@ fun CSVScreen( @Composable private fun ImportUI( state: CSVState, + launchedFromOnboarding: Boolean, onEvent: (CSVEvent) -> Unit, ) { LazyColumn( @@ -80,17 +86,26 @@ private fun ImportUI( onEvent(CSVEvent.FilePicked(it)) } ) - Spacer8() - Text( - text = """ + if (!launchedFromOnboarding) { + Spacer8() + Text( + text = """ !!!⚠️WARNING: Importing may duplicate transactions!!! Duplicate transactions can NOT be easily deleted and you'll need to remove manually each one of them! Reason: We can't parse transaction ids because Ivy Wallet works only with UUID and other apps don't. If you're starting fresh, no worries - kindly ignore this message. """.trimIndent(), - style = UI.typo.c.colorAs(UI.colors.red), - fontWeight = FontWeight.Bold, - ) + style = UI.typo.c.colorAs(UI.colors.red), + fontWeight = FontWeight.Bold, + ) + } else { + Spacer8() + Text( + text = "Import a CSV file to continue.", + style = UI.typo.b2, + fontWeight = FontWeight.SemiBold, + ) + } } if (state.csv != null) { spacer8() @@ -424,7 +439,18 @@ fun LabelContainsField( Text(text = label, color = UI.colors.primary, style = UI.typo.nB1) Text(text = " contains ", style = UI.typo.c) Spacer8(horizontal = true) - TextField(value = value, onValueChange = onValueChange, singleLine = true) + var textField by remember { + // move the cursor at the end of the text + mutableStateOf(TextFieldValue(value, TextRange(value.length))) + } + TextField( + value = textField, + onValueChange = { + textField = it + onValueChange(it.text) + }, + singleLine = true + ) } } // endregion 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 802ef01a09..25e7c5c7c9 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 @@ -513,6 +513,7 @@ class CSVViewModel @Inject constructor( event.onboardingViewModel.importFinished( success = importSuccess ) + nav.back() } nav.back()