diff --git a/app/feature/feature-movingflow-navigation/src/commonMain/kotlin/com/hedvig/android/feature/movingflow/SelectContractForMovingKey.kt b/app/feature/feature-movingflow-navigation/src/commonMain/kotlin/com/hedvig/android/feature/movingflow/SelectContractForMovingKey.kt index 7cedef2eda..1062ecefce 100644 --- a/app/feature/feature-movingflow-navigation/src/commonMain/kotlin/com/hedvig/android/feature/movingflow/SelectContractForMovingKey.kt +++ b/app/feature/feature-movingflow-navigation/src/commonMain/kotlin/com/hedvig/android/feature/movingflow/SelectContractForMovingKey.kt @@ -10,6 +10,10 @@ data class SelectContractForMovingKey( /** * Where the user entered the moving flow from. Reported to the backend when the move quotes are requested. + * + * [TERMINATION] is the only entry point the backend treats differently; [INSURANCE] and [OTHER] both end up recorded + * as an insurance-initiated move. Pick [OTHER] for an entry point that is neither the insurance screens nor the + * termination flow, so that the distinction stays available if the backend starts modelling it. */ @Serializable enum class MovingSource { diff --git a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/data/MovingFlowState.kt b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/data/MovingFlowState.kt index 711a8ba38f..f3bfb205aa 100644 --- a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/data/MovingFlowState.kt +++ b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/data/MovingFlowState.kt @@ -22,7 +22,7 @@ internal data class MovingFlowState( // back to that step again val lastSelectedHomeQuoteId: String?, val mapOfPropertyStates: Map, - // Defaulted so that a flow which was persisted before this was tracked still deserializes + // Absent for a persisted flow whose entry point was not recorded val movingSource: MovingSource = MovingSource.OTHER, ) { @Serializable diff --git a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/storage/MovingFlowRepository.kt b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/storage/MovingFlowRepository.kt index af9578f2c4..68285fa8d6 100644 --- a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/storage/MovingFlowRepository.kt +++ b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/storage/MovingFlowRepository.kt @@ -63,8 +63,8 @@ internal class MovingFlowRepository( squareMeters: Int, numberCoInsured: Int, isStudent: Boolean, - ) { - movingFlowStorage.editMovingFlowState { existingState -> + ): MovingFlowState? { + return movingFlowStorage.editMovingFlowState { existingState -> val updatedState = existingState.copy( addressInfo = existingState.addressInfo.copy( street = address, diff --git a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/addhouseinformation/AddHouseInformationViewModel.kt b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/addhouseinformation/AddHouseInformationViewModel.kt index 9a01e1dd6e..639c98633a 100644 --- a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/addhouseinformation/AddHouseInformationViewModel.kt +++ b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/addhouseinformation/AddHouseInformationViewModel.kt @@ -58,14 +58,14 @@ internal class AddHouseInformationViewModel( apolloClient: ApolloClient, backstack: Backstack, ) : MoleculeViewModel( - Loading, - AddHouseInformationPresenter( - moveIntentId, - movingFlowRepository, - apolloClient, - backstack, - ), -) + Loading, + AddHouseInformationPresenter( + moveIntentId, + movingFlowRepository, + apolloClient, + backstack, + ), + ) internal class AddHouseInformationPresenter( private val moveIntentId: String, diff --git a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/enternewaddress/EnterNewAddressDestination.kt b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/enternewaddress/EnterNewAddressDestination.kt index a795006c01..6c867cc065 100644 --- a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/enternewaddress/EnterNewAddressDestination.kt +++ b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/enternewaddress/EnterNewAddressDestination.kt @@ -55,7 +55,6 @@ import com.hedvig.android.design.system.hedvig.clearFocusOnTap import com.hedvig.android.design.system.hedvig.datepicker.HedvigDatePicker import com.hedvig.android.design.system.hedvig.datepicker.HedvigDatePickerImmutableState import com.hedvig.android.design.system.hedvig.datepicker.getLocale -import com.hedvig.android.feature.movingflow.MovingSource import com.hedvig.android.feature.movingflow.compose.ConstrainedNumberInput import com.hedvig.android.feature.movingflow.compose.NoopValidator import com.hedvig.android.feature.movingflow.compose.ValidatedInput @@ -423,7 +422,6 @@ fun PreviewEnterNewAddressScreen() { EnterNewAddressScreen( uiState = Content( moveFromAddressId = "moveFromAddressId", - movingSource = MovingSource.INSURANCE, movingDate = ValidatedInput( Clock.System.now().toLocalDateTime(TimeZone.UTC).date, NoopValidator(), diff --git a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/enternewaddress/EnterNewAddressViewModel.kt b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/enternewaddress/EnterNewAddressViewModel.kt index 95516c56be..409148df99 100644 --- a/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/enternewaddress/EnterNewAddressViewModel.kt +++ b/app/feature/feature-movingflow/src/main/kotlin/com/hedvig/android/feature/movingflow/ui/enternewaddress/EnterNewAddressViewModel.kt @@ -78,14 +78,14 @@ internal class EnterNewAddressViewModel( apolloClient: ApolloClient, backstack: Backstack, ) : MoleculeViewModel( - Loading, - EnterNewAddressPresenter( - moveIntentId, - movingFlowRepository, - apolloClient, - backstack, - ), -) + Loading, + EnterNewAddressPresenter( + moveIntentId, + movingFlowRepository, + apolloClient, + backstack, + ), + ) private class EnterNewAddressPresenter( private val moveIntentId: String, @@ -130,7 +130,7 @@ private class EnterNewAddressPresenter( val validContent = content.validate() if (validContent == null) return@CollectEvents coroutineScope.launch { - movingFlowRepository.updateWithPropertyInput( + val movingFlowState = movingFlowRepository.updateWithPropertyInput( movingDate = validContent.movingDate, address = validContent.address, postalCode = validContent.postalCode, @@ -144,7 +144,11 @@ private class EnterNewAddressPresenter( } is Apartment -> { - inputForSubmission = validContent.toInputForSubmission() + if (movingFlowState != null) { + inputForSubmission = validContent.toInputForSubmission(movingFlowState.movingSource) + } else { + submittingInfoFailure = SubmittingInfoFailure.NetworkFailure + } } } } @@ -209,7 +213,7 @@ private class EnterNewAddressPresenter( } } -private fun ValidContent.toInputForSubmission(): InputForSubmission { +private fun ValidContent.toInputForSubmission(movingSource: MovingSource): InputForSubmission { return InputForSubmission( moveIntentRequestInput = MoveIntentRequestInput( moveToAddress = MoveToAddressInput( @@ -266,7 +270,6 @@ internal sealed interface EnterNewAddressUiState { data class Content( val moveFromAddressId: String, - val movingSource: MovingSource, val movingDate: ValidatedInput, val allowedMovingDateRange: ClosedRange, val address: ValidatedInput, @@ -311,7 +314,6 @@ internal sealed interface EnterNewAddressUiState { private class ValidContent( val moveFromAddressId: String, - val movingSource: MovingSource, val movingDate: LocalDate, val address: String, val postalCode: String, @@ -338,7 +340,6 @@ private fun Content.validate(): ValidContent? { return either { ValidContent( moveFromAddressId = moveFromAddressId, - movingSource = movingSource, movingDate = movingDate.bind(), address = address.bind(), postalCode = postalCode.bind(), @@ -364,7 +365,6 @@ private fun Content.validate(): ValidContent? { private fun MovingFlowState.toContent(): Content { return Content( moveFromAddressId = moveFromAddressId, - movingSource = movingSource, movingDate = ValidatedInput( initialValue = movingDateState.selectedMovingDate, validator = { movingDate ->