Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Excluded addons should stay shrinked and non-interactive #2390

Merged
merged 10 commits into from
Jan 24, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ fragment AddonVariantFragment on AddonVariant {
exceptions
colorCode
}
insurableLimits {
label
limit
description
}
documents {
displayName
url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment.Companion.Center
import androidx.compose.ui.Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ data class AddonVariant(
val displayName: String,
val product: String,
val documents: List<InsuranceVariantDocument>,
val perils: List<ProductVariantPeril>,
val insurableLimits: List<InsurableLimit>,
val perils: List<ProductVariantPeril>
)

fun AddonVariantFragment.toAddonVariant() = AddonVariant(
Expand All @@ -33,12 +32,5 @@ fun AddonVariantFragment.toAddonVariant() = AddonVariant(
exceptions = peril.exceptions,
colorCode = peril.colorCode,
)
},
insurableLimits = this.insurableLimits.map { insurableLimit ->
InsurableLimit(
label = insurableLimit.label,
limit = insurableLimit.limit,
description = insurableLimit.description,
)
},
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ private val fakeTravelAddonQuote1 = TravelAddonQuote(
perils = listOf(),
displayName = "45 days",
product = "",
insurableLimits = listOf(),
),
price = UiMoney(
49.0,
Expand All @@ -564,7 +563,6 @@ private val fakeTravelAddonQuote2 = TravelAddonQuote(
perils = listOf(),
displayName = "60 days",
product = "",
insurableLimits = listOf(),
),
price = UiMoney(
60.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ private class ChooseInsuranceForAddonUiStateProvider :
documents = listOf(),
perils = listOf(),
displayName = "45 days",
product = "",
insurableLimits = listOf(),
product = ""
),
price = UiMoney(
60.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Making
import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Success
import com.hedvig.android.tiersandaddons.QuoteCard
import com.hedvig.android.tiersandaddons.QuoteDisplayItem
import com.hedvig.android.tiersandaddons.rememberQuoteCardState
import hedvig.resources.R
import kotlinx.datetime.LocalDate
import kotlinx.datetime.toJavaLocalDate
Expand Down Expand Up @@ -320,6 +321,7 @@ private fun AddonCard(
val startDate = formatStartDate(activationDate)
val subtitle = stringResource(R.string.CHANGE_ADDRESS_ACTIVATION_DATE, startDate)
QuoteCard(
quoteCardState = rememberQuoteCardState(),
displayName = addonQuote.addonVariant.displayName,
contractGroup = null,
insurableLimits = emptyList(),
Expand Down Expand Up @@ -440,7 +442,6 @@ private class ChooseInsuranceUiStateProvider :
addonVariant = AddonVariant(
displayName = "Addon Name",
perils = listOf(),
insurableLimits = listOf(),
documents = listOf(
InsuranceVariantDocument(
"Document name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ private fun PreviewContractDetailScreen() {
),
),
perils = listOf(),
insurableLimits = listOf(),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ private val fakeAddonVariant = AddonVariant(
),
),
displayName = "Travel Insurance Plus",
product = "",
insurableLimits = listOf(),
product = ""
)

private val previewInsurableLimits: List<InsurableLimit> = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ private fun PreviewDocumentsScreen() {
InsuranceVariantDocument.InsuranceDocumentType.GENERAL_TERMS,
),
),
insurableLimits = listOf(),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ import com.hedvig.android.tiersandaddons.QuoteCard
import com.hedvig.android.tiersandaddons.QuoteCardDefaults
import com.hedvig.android.tiersandaddons.QuoteCardState
import com.hedvig.android.tiersandaddons.QuoteDisplayItem
import com.hedvig.android.tiersandaddons.rememberQuoteCardState
import hedvig.resources.R
import kotlinx.datetime.LocalDate
import kotlinx.datetime.toJavaLocalDate
Expand Down Expand Up @@ -359,7 +360,7 @@ private fun AddonQuoteCard(
visible = canExcludeAddons && state.showDetails && !quote.isExcludedByUser,
enter = expandVertically(expandFrom = Alignment.Top),
exit = shrinkVertically(shrinkTowards = Alignment.Top),
modifier = Modifier.padding(bottom = 8.dp),
modifier = Modifier.padding(top = 8.dp),
) {
HedvigButton(
text = stringResource(R.string.GENERAL_REMOVE),
Expand All @@ -378,7 +379,9 @@ private fun AddonQuoteCard(
enabled = true,
buttonStyle = Secondary,
buttonSize = Medium,
modifier = Modifier.fillMaxWidth().padding(top = 16.dp),
modifier = Modifier
.fillMaxWidth()
.padding(top = 16.dp),
)
} else {
QuoteCardDefaults.UnderDetailsContent(state)
Expand Down Expand Up @@ -409,11 +412,21 @@ private fun AddonQuoteCard(
} else {
stringResource(R.string.CHANGE_ADDRESS_ACTIVATION_DATE, startDate)
}
val quoteCardState = rememberQuoteCardState()
QuoteCard(
quoteCardState = object : QuoteCardState {
override var showDetails: Boolean
get() = if (quote is HomeAddonQuote && quote.isExcludedByUser) false else quoteCardState.showDetails
set(value) {
if (quote is HomeAddonQuote && quote.isExcludedByUser) return
quoteCardState.showDetails = value
}
override val isEnabled: Boolean
get() = if (quote is HomeAddonQuote && quote.isExcludedByUser) false else quoteCardState.isEnabled
},
displayName = quote.addonVariant.displayName,
contractGroup = null,
insurableLimits = emptyList(),
// todo: here we don't want to show insurable limits for addons, that may change later
documents = quote.addonVariant.documents,
subtitle = subtitle,
premium = quote.premium.toString(),
Expand Down Expand Up @@ -537,8 +550,7 @@ private class SummaryUiStateProvider : PreviewParameterProvider<SummaryUiState>
type = CERTIFICATE,
),
),
perils = listOf(),
insurableLimits = listOf(),
perils = listOf()
)
val startDate = LocalDate.parse("2025-01-01")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.hedvig.android.data.claimflow.ClaimFlowStep
import com.hedvig.android.data.claimflow.LocalContractContractOption
import com.hedvig.android.design.system.hedvig.ChosenState
import com.hedvig.android.design.system.hedvig.ErrorSnackbarState
import com.hedvig.android.design.system.hedvig.HedvigButton
import com.hedvig.android.design.system.hedvig.HedvigPreview
import com.hedvig.android.design.system.hedvig.HedvigMultiScreenPreview
import com.hedvig.android.design.system.hedvig.HedvigText
import com.hedvig.android.design.system.hedvig.HedvigTheme
import com.hedvig.android.design.system.hedvig.LockedState.NotLocked
import com.hedvig.android.design.system.hedvig.RadioGroup
import com.hedvig.android.design.system.hedvig.RadioGroupDefaults
import com.hedvig.android.design.system.hedvig.RadioOptionData
import com.hedvig.android.design.system.hedvig.RadioOptionGroupData
import com.hedvig.android.design.system.hedvig.Surface
import com.hedvig.android.design.system.hedvig.calculateForPreview
import com.hedvig.android.feature.odyssey.ui.ContractOptionWithDialog
import com.hedvig.android.ui.claimflow.ClaimFlowScaffold
import hedvig.resources.R

Expand Down Expand Up @@ -59,7 +64,7 @@ internal fun SelectContractDestination(
private fun SelectContractScreen(
uiState: SelectContractUiState,
windowSizeClass: WindowSizeClass,
selectLocation: (LocalContractContractOption) -> Unit,
selectLocation: (String) -> Unit,
submitLocation: () -> Unit,
showedError: () -> Unit,
navigateUp: () -> Unit,
Expand All @@ -82,12 +87,24 @@ private fun SelectContractScreen(
)
Spacer(Modifier.height(32.dp))
Spacer(Modifier.weight(1f))
ContractOptionWithDialog(
locationOptions = uiState.contractOptions,
selectedLocation = uiState.selectedContract,
selectLocationOption = selectLocation,
enabled = !uiState.isLoading,
RadioGroup(
radioGroupSize = RadioGroupDefaults.RadioGroupSize.Medium,
radioGroupStyle = RadioGroupDefaults.RadioGroupStyle.Vertical.Default(
dataList = uiState.contractOptions.map { option ->
RadioOptionGroupData.RadioOptionGroupDataSimple(
RadioOptionData(
id = option.id,
optionText = option.displayName,
chosenState = if (option == uiState.selectedContract) ChosenState.Chosen else ChosenState.NotChosen,
),
)
},
),
onOptionClick = { id ->
selectLocation(id)
},
modifier = sideSpacingModifier.fillMaxWidth(),
groupLockedState = NotLocked,
)
Spacer(Modifier.height(16.dp))
HedvigButton(
Expand All @@ -102,7 +119,7 @@ private fun SelectContractScreen(
}
}

@HedvigPreview
@HedvigMultiScreenPreview
@Composable
private fun PreviewLocationScreen() {
HedvigTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch

internal class SelectContractViewModel(
private val selectContract: ClaimFlowDestination.SelectContract,
selectContract: ClaimFlowDestination.SelectContract,
private val claimFlowRepository: ClaimFlowRepository,
) : ViewModel() {
private val _uiState = MutableStateFlow(SelectContractUiState.fromInitialSelection(selectContract.options))
val uiState: StateFlow<SelectContractUiState> = _uiState.asStateFlow()

fun selectContractOption(selectedContract: LocalContractContractOption) {
fun selectContractOption(selectedContractId: String) {
_uiState.update { oldUiState ->
oldUiState.copy(selectedContract = selectedContract)
val selected = oldUiState.contractOptions.first { it.id == selectedContractId }
oldUiState.copy(selectedContract = selected)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ fun QuoteCard(

@Composable
fun QuoteCard(
quoteCardState: QuoteCardState,
displayName: String,
contractGroup: ContractGroup?,
insurableLimits: List<InsurableLimit>,
Expand All @@ -171,9 +172,9 @@ fun QuoteCard(
underDetailsContent: @Composable (QuoteCardState) -> Unit = { state ->
QuoteCardDefaults.UnderDetailsContent(state)
},
) {
) {
QuoteCard(
quoteCardState = rememberQuoteCardState(),
quoteCardState = quoteCardState,
subtitle = subtitle,
premium = premium,
isExcluded = isExcluded,
Expand Down Expand Up @@ -349,6 +350,7 @@ private fun QuoteCard(
HedvigCard(
modifier = modifier,
onClick = quoteCardState::toggleState,
enabled = quoteCardState.isEnabled,
interactionSource = null,
indication = ripple(bounded = true, radius = 1000.dp),
) {
Expand Down
Loading