diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 7f41d7c9ab..44ca2d9b03 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -7,6 +7,7 @@
+
@@ -14,6 +15,7 @@
+
@@ -29,9 +31,11 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt b/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt
index dedca657b5..2cf15ea4b0 100644
--- a/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt
+++ b/app/src/main/java/com/ivy/wallet/ui/RootActivity.kt
@@ -219,7 +219,7 @@ class RootActivity : AppCompatActivity() {
is ImagesScreen -> ImagesScreen(screen = screen)
is ExperimentalScreen -> ExperimentalScreen(screen = screen)
is DonateScreen -> DonateScreen(screen = screen)
- is CSVScreen -> CSVScreen()
+ is CSVScreen -> CSVScreen(screen = screen)
null -> {
}
}
diff --git a/app/src/main/java/com/ivy/wallet/ui/Screens.kt b/app/src/main/java/com/ivy/wallet/ui/Screens.kt
index 72df56bd2d..66869a067c 100644
--- a/app/src/main/java/com/ivy/wallet/ui/Screens.kt
+++ b/app/src/main/java/com/ivy/wallet/ui/Screens.kt
@@ -12,7 +12,9 @@ object Onboarding : Screen
object ServerStop : Screen
-object CSVScreen : Screen
+data class CSVScreen(
+ val launchedFromOnboarding: Boolean
+) : Screen
data class EditTransaction(
val initialTransactionId: UUID?,
diff --git a/app/src/main/java/com/ivy/wallet/ui/csv/CSVEvent.kt b/app/src/main/java/com/ivy/wallet/ui/csv/CSVEvent.kt
index e210373cc3..9b84b1f9d8 100644
--- a/app/src/main/java/com/ivy/wallet/ui/csv/CSVEvent.kt
+++ b/app/src/main/java/com/ivy/wallet/ui/csv/CSVEvent.kt
@@ -1,6 +1,7 @@
package com.ivy.wallet.ui.csv
import android.net.Uri
+import com.ivy.wallet.ui.onboarding.viewmodel.OnboardingViewModel
sealed interface CSVEvent {
data class FilePicked(val uri: Uri) : CSVEvent
@@ -26,4 +27,8 @@ sealed interface CSVEvent {
object Continue : CSVEvent
object ResetState : CSVEvent
+ data class FinishImport(
+ val launchedFromOnboarding: Boolean,
+ val onboardingViewModel: OnboardingViewModel
+ ) : CSVEvent
}
\ No newline at end of file
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 4175943f00..58ab72e720 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
@@ -24,27 +24,37 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.insets.systemBarsPadding
import com.ivy.design.l0_system.UI
import com.ivy.design.l0_system.colorAs
-import com.ivy.frp.view.navigation.navigation
+import com.ivy.wallet.ui.CSVScreen
import com.ivy.wallet.ui.csvimport.flow.ImportProcessing
import com.ivy.wallet.ui.csvimport.flow.ImportResultUI
import com.ivy.wallet.ui.ivyWalletCtx
+import com.ivy.wallet.ui.onboarding.viewmodel.OnboardingViewModel
import com.ivy.wallet.utils.thenIf
import kotlin.math.abs
@Composable
-fun CSVScreen() {
+fun CSVScreen(
+ screen: CSVScreen
+) {
val viewModel: CSVViewModel = viewModel()
val state = viewModel.uiState()
- val nav = navigation()
+ val onboardingViewModel: OnboardingViewModel = viewModel()
+
when (val ui = state.uiState) {
UIState.Idle -> ImportUI(state = state, onEvent = viewModel::onEvent)
is UIState.Processing -> ImportProcessing(progressPercent = ui.percent)
is UIState.Result -> ImportResultUI(
result = ui.importResult,
isManualCsvImport = true,
+ launchedFromOnboarding = screen.launchedFromOnboarding,
onTryAgain = null,
onFinish = {
- nav.back()
+ viewModel.onEvent(
+ CSVEvent.FinishImport(
+ launchedFromOnboarding = screen.launchedFromOnboarding,
+ onboardingViewModel = onboardingViewModel,
+ )
+ )
}
)
}
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 4c2f48a995..802ef01a09 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
@@ -4,6 +4,7 @@ import android.net.Uri
import androidx.compose.runtime.*
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
+import com.ivy.frp.view.navigation.Navigation
import com.ivy.wallet.domain.deprecated.logic.csv.IvyFileReader
import com.ivy.wallet.ui.csv.domain.*
import com.ivy.wallet.utils.uiThread
@@ -24,6 +25,7 @@ import kotlin.math.roundToInt
class CSVViewModel @Inject constructor(
private val fileReader: IvyFileReader,
private val csvImporter: CSVImporterV2,
+ private val nav: Navigation,
) : ViewModel() {
private var columns by mutableStateOf(null)
@@ -381,6 +383,9 @@ class CSVViewModel @Inject constructor(
CSVEvent.ResetState -> {
uiState = UIState.Idle
}
+ is CSVEvent.FinishImport -> {
+ handleFinishImport(event)
+ }
}
}
@@ -501,6 +506,25 @@ class CSVViewModel @Inject constructor(
}
}
+ private fun handleFinishImport(event: CSVEvent.FinishImport) {
+ if (event.launchedFromOnboarding) {
+ val importSuccess = (uiState as? UIState.Result)?.importResult
+ ?.transactionsImported?.let { it > 0 } ?: false
+ event.onboardingViewModel.importFinished(
+ success = importSuccess
+ )
+ }
+
+ nav.back()
+ resetState()
+ }
+
+ private fun resetState() {
+ uiState = UIState.Idle
+ csv = null
+ columns = null
+ }
+
// region Boiler-plate
private val events = MutableSharedFlow(replay = 0)
diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt
index fa7a30423e..7729efb082 100644
--- a/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt
+++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/ImportScreen.kt
@@ -80,6 +80,7 @@ private fun BoxWithConstraintsScope.UI(
ImportStep.IMPORT_FROM -> {
ImportFrom(
hasSkip = screen.launchedFromOnboarding,
+ launchedFromOnboarding = screen.launchedFromOnboarding,
onSkip = onSkip,
onImportFrom = onChooseImportType
)
@@ -99,7 +100,8 @@ private fun BoxWithConstraintsScope.UI(
}
ImportStep.RESULT -> {
ImportResultUI(
- result = importResult!!
+ result = importResult!!,
+ launchedFromOnboarding = screen.launchedFromOnboarding,
) {
onFinish()
}
diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt
index de73611c5e..0fe55b1f47 100644
--- a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt
+++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportFrom.kt
@@ -27,7 +27,6 @@ import com.ivy.wallet.R
import com.ivy.wallet.domain.deprecated.logic.csv.model.ImportType
import com.ivy.wallet.ui.CSVScreen
import com.ivy.wallet.ui.IvyWalletPreview
-import com.ivy.wallet.ui.ivyWalletCtx
import com.ivy.wallet.ui.onboarding.components.OnboardingToolbar
import com.ivy.wallet.ui.theme.components.GradientCutBottom
import com.ivy.wallet.ui.theme.components.IvyIcon
@@ -36,6 +35,7 @@ import com.ivy.wallet.ui.theme.components.IvyIcon
@Composable
fun BoxWithConstraintsScope.ImportFrom(
hasSkip: Boolean,
+ launchedFromOnboarding: Boolean,
onSkip: () -> Unit = {},
onImportFrom: (ImportType) -> Unit = {},
@@ -67,7 +67,7 @@ fun BoxWithConstraintsScope.ImportFrom(
.height(64.dp)
.padding(horizontal = 16.dp),
onClick = {
- nav.navigateTo(CSVScreen)
+ nav.navigateTo(CSVScreen(launchedFromOnboarding))
}
) {
Text(text = "Manual CSV import")
@@ -151,6 +151,7 @@ private fun Preview() {
IvyWalletPreview {
ImportFrom(
hasSkip = true,
+ launchedFromOnboarding = false,
)
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt
index 9eb0f366dc..b8382c268e 100644
--- a/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt
+++ b/app/src/main/java/com/ivy/wallet/ui/csvimport/flow/ImportResultUI.kt
@@ -26,6 +26,7 @@ import com.ivy.wallet.utils.format
@Composable
fun ImportResultUI(
result: ImportResult,
+ launchedFromOnboarding: Boolean,
isManualCsvImport: Boolean = false,
onTryAgain: (() -> Unit)? = null,
@@ -161,7 +162,7 @@ fun ImportResultUI(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
- text = "If this didn't work, Try manual CSV import.",
+ text = "If this didn't work, try manual CSV import.",
color = UI.colors.pureInverse,
)
Spacer(modifier = Modifier.height(8.dp))
@@ -171,7 +172,7 @@ fun ImportResultUI(
.height(52.dp)
.padding(horizontal = 16.dp),
onClick = {
- nav.navigateTo(CSVScreen)
+ nav.navigateTo(CSVScreen(launchedFromOnboarding = launchedFromOnboarding))
}
) {
Text(text = "Manual CSV import")
@@ -223,7 +224,8 @@ private fun Preview() {
accountsImported = 4,
categoriesImported = 13,
failedRows = emptyList()
- )
+ ),
+ launchedFromOnboarding = false,
) {
}