From 5a94bf95d0529607f0a543abcf79ac7750bf4b0a Mon Sep 17 00:00:00 2001 From: stylianosgakis Date: Mon, 4 Nov 2024 13:34:05 +0100 Subject: [PATCH 1/8] Improve QuoteCard preview --- .../tiersandaddons/QuoteDisplayItem.kt | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteDisplayItem.kt b/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteDisplayItem.kt index d80aeb6e82..7bc529a3b2 100644 --- a/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteDisplayItem.kt +++ b/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteDisplayItem.kt @@ -33,7 +33,12 @@ import com.hedvig.android.compose.ui.preview.BooleanCollectionPreviewParameterPr import com.hedvig.android.data.contract.ContractGroup.DOG import com.hedvig.android.data.contract.ContractType.SE_HOUSE import com.hedvig.android.data.contract.android.toPillow +import com.hedvig.android.data.productvariant.InsurableLimit +import com.hedvig.android.data.productvariant.InsurableLimit.InsurableLimitType.BIKE +import com.hedvig.android.data.productvariant.InsuranceVariantDocument +import com.hedvig.android.data.productvariant.InsuranceVariantDocument.InsuranceDocumentType.GENERAL_TERMS import com.hedvig.android.data.productvariant.ProductVariant +import com.hedvig.android.data.productvariant.ProductVariantPeril import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonSize.Medium import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonStyle.Secondary import com.hedvig.android.design.system.hedvig.HedvigButton @@ -237,9 +242,31 @@ private fun PreviewQuoteCard( contractGroup = DOG, contractType = SE_HOUSE, partner = "partner", - perils = emptyList(), - insurableLimits = emptyList(), - documents = emptyList(), + perils = List(3) { + ProductVariantPeril( + id = it.toString(), + title = "title#$it", + description = "description#$it", + covered = emptyList(), + exceptions = emptyList(), + colorCode = "colorCode#$it", + ) + }, + insurableLimits = List(3) { + InsurableLimit( + label = "label#$it", + limit = "limit#$it", + description = "description#$it", + type = BIKE, + ) + }, + documents = List(3) { + InsuranceVariantDocument( + displayName = "displayName#$it", + url = "url#$it", + type = GENERAL_TERMS, + ) + }, displayTierName = "displayTierName", tierDescription = "tierDescription", ), From dcc72598dab93df5e1bf84200640bcadd6235c5e Mon Sep 17 00:00:00 2001 From: stylianosgakis Date: Mon, 4 Nov 2024 13:34:17 +0100 Subject: [PATCH 2/8] Rename file to the appropriate name --- .../android/tiersandaddons/{QuoteDisplayItem.kt => QuoteCard.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/{QuoteDisplayItem.kt => QuoteCard.kt} (100%) diff --git a/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteDisplayItem.kt b/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteCard.kt similarity index 100% rename from app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteDisplayItem.kt rename to app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteCard.kt From 2da2e8b5596d89b2229490feba824157c70efa97 Mon Sep 17 00:00:00 2001 From: stylianosgakis Date: Mon, 4 Nov 2024 13:59:05 +0100 Subject: [PATCH 3/8] Use shared `QuoteCard` in tier flow summary screen --- .../feature-choose-tier/build.gradle.kts | 1 + .../tier/ui/stepsummary/SummaryDestination.kt | 189 ++---------------- .../tier/ui/stepsummary/SummaryViewModel.kt | 2 +- .../android/tiersandaddons/QuoteCard.kt | 4 + 4 files changed, 22 insertions(+), 174 deletions(-) diff --git a/app/feature/feature-choose-tier/build.gradle.kts b/app/feature/feature-choose-tier/build.gradle.kts index 07cdb1cfb3..5b462da464 100644 --- a/app/feature/feature-choose-tier/build.gradle.kts +++ b/app/feature/feature-choose-tier/build.gradle.kts @@ -46,6 +46,7 @@ dependencies { implementation(projects.navigationCompose) implementation(projects.navigationComposeTyped) implementation(projects.navigationCore) + implementation(projects.uiTiersAndAddons) testImplementation(libs.apollo.testingSupport) testImplementation(libs.assertK) diff --git a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryDestination.kt b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryDestination.kt index 996191022a..e63a7f67cc 100644 --- a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryDestination.kt +++ b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryDestination.kt @@ -1,24 +1,17 @@ package com.hedvig.android.feature.change.tier.ui.stepsummary -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign @@ -26,7 +19,6 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.hedvig.android.compose.ui.stringWithShiftedLabel import com.hedvig.android.core.uidata.UiCurrencyCode.SEK import com.hedvig.android.core.uidata.UiMoney import com.hedvig.android.data.changetier.data.Deductible @@ -35,10 +27,8 @@ import com.hedvig.android.data.changetier.data.TierDeductibleQuote import com.hedvig.android.data.contract.ContractGroup import com.hedvig.android.data.contract.ContractType import com.hedvig.android.data.productvariant.ProductVariant -import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonSize import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonSize.Large import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonStyle.Primary -import com.hedvig.android.design.system.hedvig.ButtonDefaults.ButtonStyle.Secondary import com.hedvig.android.design.system.hedvig.HedvigAlertDialog import com.hedvig.android.design.system.hedvig.HedvigButton import com.hedvig.android.design.system.hedvig.HedvigErrorSection @@ -48,20 +38,15 @@ import com.hedvig.android.design.system.hedvig.HedvigMultiScreenPreview import com.hedvig.android.design.system.hedvig.HedvigScaffold import com.hedvig.android.design.system.hedvig.HedvigText import com.hedvig.android.design.system.hedvig.HedvigTheme -import com.hedvig.android.design.system.hedvig.HedvigThreeDotsProgressIndicator -import com.hedvig.android.design.system.hedvig.HorizontalDivider import com.hedvig.android.design.system.hedvig.HorizontalItemsWithMaximumSpaceTaken -import com.hedvig.android.design.system.hedvig.Icon -import com.hedvig.android.design.system.hedvig.IconButton import com.hedvig.android.design.system.hedvig.Surface -import com.hedvig.android.design.system.hedvig.icon.ArrowNorthEast -import com.hedvig.android.design.system.hedvig.icon.HedvigIcons import com.hedvig.android.feature.change.tier.ui.stepcustomize.ContractData -import com.hedvig.android.feature.change.tier.ui.stepcustomize.PillAndBasicInfo import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Failure import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Loading import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.MakingChanges import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Success +import com.hedvig.android.tiersandaddons.QuoteCard +import com.hedvig.android.tiersandaddons.QuoteDisplayItem import hedvig.resources.R import java.io.File @@ -95,9 +80,6 @@ internal fun ChangeTierSummaryDestination( onSubmitQuoteClick = { viewModel.emit(SummaryEvent.SubmitQuote) }, - downloadFromUrl = { url -> - viewModel.emit(SummaryEvent.DownLoadFromUrl(url)) - }, ) } @@ -110,7 +92,6 @@ private fun SummaryScreen( onFailure: () -> Unit, sharePdf: (File) -> Unit, onSubmitQuoteClick: () -> Unit, - downloadFromUrl: (url: String) -> Unit, ) { when (uiState) { Failure -> HedvigScaffold(navigateUp) { @@ -146,7 +127,6 @@ private fun SummaryScreen( uiState = uiState, navigateUp = navigateUp, onConfirmClick = onSubmitQuoteClick, - downloadFromUrl = downloadFromUrl, sharePdf = { file -> sharePdf(file) }, @@ -167,7 +147,6 @@ private fun MakingChangesScreen() { private fun SummarySuccessScreen( uiState: Success, onConfirmClick: () -> Unit, - downloadFromUrl: (String) -> Unit, sharePdf: (File) -> Unit, navigateUp: () -> Unit, ) { @@ -196,7 +175,6 @@ private fun SummarySuccessScreen( modifier = Modifier .fillMaxWidth() .padding(16.dp), - downloadFromUrl = downloadFromUrl, ) Spacer(Modifier.weight(1f)) Spacer(Modifier.height(16.dp)) @@ -237,37 +215,21 @@ private fun SummarySuccessScreen( } @Composable -private fun SummaryCard(uiState: Success, downloadFromUrl: (url: String) -> Unit, modifier: Modifier = Modifier) { - var showExpanded by remember { mutableStateOf(false) } - Surface( - modifier = modifier, - shape = HedvigTheme.shapes.cornerXLarge, - ) { - Column(Modifier.padding(16.dp)) { - PillAndBasicInfo( - contractGroup = uiState.currentContractData.contractGroup, - displayName = uiState.quote.productVariant.displayName, - displaySubtitle = uiState.currentContractData.contractDisplaySubtitle, - ) - Spacer(Modifier.height(16.dp)) - HorizontalItemsWithMaximumSpaceTaken( - startSlot = { - HedvigText( - stringResource(R.string.TIER_FLOW_TOTAL), - style = HedvigTheme.typography.bodySmall, - ) - }, - spaceBetween = 8.dp, - endSlot = { - HedvigText( - text = stringResource(R.string.TERMINATION_FLOW_PAYMENT_PER_MONTH, uiState.quote.premium.amount.toInt()), - textAlign = TextAlign.End, - style = HedvigTheme.typography.bodySmall, - ) - }, +private fun SummaryCard(uiState: Success, modifier: Modifier = Modifier) { + QuoteCard( + productVariant = uiState.quote.productVariant, + subtitle = uiState.currentContractData.contractDisplaySubtitle, + premium = stringResource(R.string.TERMINATION_FLOW_PAYMENT_PER_MONTH, uiState.quote.premium.amount.toInt()), + displayItems = uiState.quote.displayItems.map { + QuoteDisplayItem( + it.displayTitle, + null, + it.displayValue, ) + }, + underTitleContent = { HedvigText( - modifier = Modifier.fillMaxWidth(), + modifier = Modifier.fillMaxWidth().padding(top = 2.dp), textAlign = TextAlign.End, text = stringResource( R.string.TIER_FLOW_PREVIOUS_PRICE, @@ -276,129 +238,11 @@ private fun SummaryCard(uiState: Success, downloadFromUrl: (url: String) -> Unit style = HedvigTheme.typography.label, color = HedvigTheme.colorScheme.textSecondary, ) - AnimatedVisibility(showExpanded) { - ExtendedCardContent( - quote = uiState.quote, - downloadFromUrl = downloadFromUrl, - isPDFLoading = uiState.isLoadingPdf, - ) - } - Spacer(Modifier.height(16.dp)) - HedvigButton( - modifier = Modifier.fillMaxWidth(), - text = if (showExpanded) { - stringResource(R.string.TIER_FLOW_SUMMARY_HIDE_DETAILS_BUTTON) - } else { - stringResource(R.string.TIER_FLOW_SUMMARY_SHOW_DETAILS) - }, - onClick = { showExpanded = !showExpanded }, - enabled = true, - buttonStyle = Secondary, - buttonSize = ButtonSize.Medium, - ) - } - } -} - -@Composable -fun DisplayItemRowSecondaryColor(leftText: String, rightText: String) { - HorizontalItemsWithMaximumSpaceTaken( - startSlot = { - HedvigText(leftText, color = HedvigTheme.colorScheme.textSecondary) - }, - endSlot = { - Row( - horizontalArrangement = Arrangement.End, - verticalAlignment = Alignment.CenterVertically, - ) { - HedvigText( - rightText, - color = HedvigTheme.colorScheme.textSecondary, - textAlign = TextAlign.End, - ) - } }, - spaceBetween = 8.dp, + modifier = modifier, ) } -@Composable -private fun ExtendedCardContent( - isPDFLoading: Boolean, - quote: TierDeductibleQuote, - downloadFromUrl: (url: String) -> Unit, -) { - Column { - Spacer(Modifier.height(16.dp)) - HorizontalDivider() - Spacer(Modifier.height(16.dp)) - HedvigText(stringResource(R.string.TIER_FLOW_SUMMARY_OVERVIEW_SUBTITLE)) - quote.displayItems.forEachIndexed { _, item -> - DisplayItemRowSecondaryColor(item.displayTitle, item.displayValue) - } - Spacer(Modifier.height(16.dp)) - HedvigText(stringResource(R.string.TIER_FLOW_SUMMARY_COVERAGE_SUBTITLE)) - quote.productVariant.insurableLimits.forEach { insurableLimit -> - DisplayItemRowSecondaryColor(insurableLimit.label, insurableLimit.limit) - } - Spacer(Modifier.height(16.dp)) - Row(verticalAlignment = Alignment.CenterVertically) { - HedvigText(stringResource(R.string.TIER_FLOW_SUMMARY_DOCUMENTS_SUBTITLE)) - Spacer(Modifier.width(16.dp)) - AnimatedVisibility(isPDFLoading) { HedvigThreeDotsProgressIndicator() } - } - quote.productVariant.documents.forEach { document -> - DocumentRow( - name = document.displayName, - downloadFromUrl = { - downloadFromUrl(document.url) - }, - ) - } - } -} - -@Composable -private fun DocumentRow(name: String, downloadFromUrl: () -> Unit) { - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.clickable { downloadFromUrl() }, - ) { - HorizontalItemsWithMaximumSpaceTaken( - startSlot = { - Row(verticalAlignment = Alignment.CenterVertically) { - HedvigText( - color = HedvigTheme.colorScheme.textSecondary, - text = stringWithShiftedLabel( - text = name, - labelText = "PDF", - textColor = HedvigTheme.colorScheme.textSecondary, - textFontSize = HedvigTheme.typography.bodySmall.fontSize, - labelFontSize = HedvigTheme.typography.label.fontSize, - ), - ) - } - }, - endSlot = { - Row( - horizontalArrangement = Arrangement.End, - verticalAlignment = Alignment.CenterVertically, - ) { - IconButton( - modifier = Modifier.size(24.dp), - onClick = { - downloadFromUrl() - }, - ) { - Icon(HedvigIcons.ArrowNorthEast, null) - } - } - }, - spaceBetween = 8.dp, - ) - } -} - @HedvigMultiScreenPreview @Composable private fun PreviewChooseInsuranceScreen( @@ -416,7 +260,6 @@ private fun PreviewChooseInsuranceScreen( {}, {}, {}, - {}, ) } } diff --git a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryViewModel.kt b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryViewModel.kt index af956289f8..82ad639b30 100644 --- a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryViewModel.kt +++ b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryViewModel.kt @@ -207,5 +207,5 @@ internal sealed interface SummaryEvent { data object HandledSharingPdfFile : SummaryEvent - data class DownLoadFromUrl(val url: String) : SummaryEvent + data class DownLoadFromUrl(val url: String) : SummaryEvent // todo remove } diff --git a/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteCard.kt b/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteCard.kt index 7bc529a3b2..5956f4d88f 100644 --- a/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteCard.kt +++ b/app/ui/ui-tiers-and-addons/src/main/kotlin/com/hedvig/android/tiersandaddons/QuoteCard.kt @@ -68,6 +68,7 @@ fun QuoteCard( premium: String, displayItems: List, modifier: Modifier = Modifier, + underTitleContent: @Composable () -> Unit = {}, ) { var showDetails by rememberSaveable { mutableStateOf(false) } QuoteCard( @@ -77,6 +78,7 @@ fun QuoteCard( subtitle = subtitle, premium = premium, displayItems = displayItems, + underTitleContent = underTitleContent, modifier = modifier, ) } @@ -90,6 +92,7 @@ private fun QuoteCard( premium: String, displayItems: List, modifier: Modifier = Modifier, + underTitleContent: @Composable () -> Unit = {}, ) { HedvigCard( modifier = modifier, @@ -131,6 +134,7 @@ private fun QuoteCard( ) }, ) + underTitleContent() AnimatedVisibility( visible = showDetails, enter = expandVertically(expandFrom = Alignment.Top), From b8a37fdfad5aaa70be1cb691429df4c271ae3ba6 Mon Sep 17 00:00:00 2001 From: stylianosgakis Date: Mon, 4 Nov 2024 14:02:05 +0100 Subject: [PATCH 4/8] Remove pdf downloading logic from tier flow summary Let the UriHandler open the PDFs in a browser in a common way between moving and tier flow --- .../feature-choose-tier/build.gradle.kts | 1 - .../change/tier/di/ChooseTierModule.kt | 2 - .../tier/ui/stepsummary/SummaryViewModel.kt | 56 ------------------- 3 files changed, 59 deletions(-) diff --git a/app/feature/feature-choose-tier/build.gradle.kts b/app/feature/feature-choose-tier/build.gradle.kts index 5b462da464..783039d1f2 100644 --- a/app/feature/feature-choose-tier/build.gradle.kts +++ b/app/feature/feature-choose-tier/build.gradle.kts @@ -30,7 +30,6 @@ dependencies { implementation(projects.composeUi) implementation(projects.coreCommonAndroidPublic) implementation(projects.coreCommonPublic) - implementation(projects.coreFileUpload) implementation(projects.coreResources) implementation(projects.coreUiData) implementation(projects.dataChangetier) diff --git a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/di/ChooseTierModule.kt b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/di/ChooseTierModule.kt index 44dae02f27..1b4a3457d2 100644 --- a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/di/ChooseTierModule.kt +++ b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/di/ChooseTierModule.kt @@ -1,7 +1,6 @@ package com.hedvig.android.feature.change.tier.di import com.apollographql.apollo.ApolloClient -import com.hedvig.android.core.fileupload.DownloadPdfUseCase import com.hedvig.android.data.changetier.data.ChangeTierRepository import com.hedvig.android.feature.change.tier.data.GetCurrentContractDataUseCase import com.hedvig.android.feature.change.tier.data.GetCurrentContractDataUseCaseImpl @@ -60,7 +59,6 @@ val chooseTierModule = module { params = params.get(), tierRepository = get(), getCurrentContractDataUseCase = get(), - downloadPdfUseCase = get(), ) } diff --git a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryViewModel.kt b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryViewModel.kt index 82ad639b30..f1efe39c76 100644 --- a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryViewModel.kt +++ b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryViewModel.kt @@ -7,33 +7,27 @@ import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import com.hedvig.android.core.fileupload.DownloadPdfUseCase import com.hedvig.android.data.changetier.data.ChangeTierRepository import com.hedvig.android.data.changetier.data.TierDeductibleQuote import com.hedvig.android.feature.change.tier.data.GetCurrentContractDataUseCase import com.hedvig.android.feature.change.tier.navigation.SummaryParameters import com.hedvig.android.feature.change.tier.ui.stepcustomize.ContractData import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryEvent.ClearNavigation -import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryEvent.DownLoadFromUrl -import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryEvent.HandledSharingPdfFile import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryEvent.Reload import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryEvent.SubmitQuote import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Failure import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Loading import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.MakingChanges import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Success -import com.hedvig.android.logger.LogPriority import com.hedvig.android.logger.LogPriority.ERROR import com.hedvig.android.logger.logcat import com.hedvig.android.molecule.android.MoleculeViewModel import com.hedvig.android.molecule.public.MoleculePresenter import com.hedvig.android.molecule.public.MoleculePresenterScope -import java.io.File internal class SummaryViewModel( params: SummaryParameters, tierRepository: ChangeTierRepository, - downloadPdfUseCase: DownloadPdfUseCase, getCurrentContractDataUseCase: GetCurrentContractDataUseCase, ) : MoleculeViewModel( initialState = Loading, @@ -41,14 +35,12 @@ internal class SummaryViewModel( params = params, tierRepository = tierRepository, getCurrentContractDataUseCase = getCurrentContractDataUseCase, - downloadPdfUseCase = downloadPdfUseCase, ), ) private class SummaryPresenter( private val params: SummaryParameters, private val tierRepository: ChangeTierRepository, - private val downloadPdfUseCase: DownloadPdfUseCase, private val getCurrentContractDataUseCase: GetCurrentContractDataUseCase, ) : MoleculePresenter { @Composable @@ -56,9 +48,6 @@ private class SummaryPresenter( var submitIteration by remember { mutableIntStateOf(0) } var loadDataIteration by remember { mutableIntStateOf(0) } var currentState by remember { mutableStateOf(lastState) } - var downloadingUrl by remember { - mutableStateOf(null) - } CollectEvents { event -> when (event) { @@ -77,19 +66,6 @@ private class SummaryPresenter( return@CollectEvents } } - - is DownLoadFromUrl -> { - if (currentState !is Success) return@CollectEvents - currentState = (currentState as Success).copy(isLoadingPdf = true) - downloadingUrl = event.url - } - - HandledSharingPdfFile -> { - if (currentState !is Success) return@CollectEvents - currentState = (currentState as Success).copy( - savedFileUri = null, - ) - } } } @@ -150,32 +126,6 @@ private class SummaryPresenter( }, ) } - - LaunchedEffect(downloadingUrl) { - val downloadingUrlValue = downloadingUrl ?: return@LaunchedEffect - logcat(LogPriority.INFO) { "Downloading terms and conditions with url:$downloadingUrl" } - downloadPdfUseCase.invoke(downloadingUrlValue) - .fold( - ifLeft = { errorMessage -> - logcat(LogPriority.ERROR) { "Downloading terms and conditions failed:$errorMessage" } - // we only putting log on this, but no error state in the UI - val state = currentState - if (state !is Success) return@LaunchedEffect - currentState = state.copy(isLoadingPdf = false) - downloadingUrl = null - }, - ifRight = { uri -> - logcat( - LogPriority.INFO, - ) { "Downloading terms and conditions succeeded. Result uri:${uri.absolutePath}" } - val state = currentState - if (state !is Success) return@LaunchedEffect - currentState = state.copy(isLoadingPdf = false, savedFileUri = uri) - downloadingUrl = null - }, - ) - } - return currentState } } @@ -190,8 +140,6 @@ internal sealed interface SummaryState { data class Success( val quote: TierDeductibleQuote, val currentContractData: ContractData, - val savedFileUri: File? = null, - val isLoadingPdf: Boolean = false, val navigateToFail: Boolean = false, ) : SummaryState @@ -204,8 +152,4 @@ internal sealed interface SummaryEvent { data object Reload : SummaryEvent data object ClearNavigation : SummaryEvent - - data object HandledSharingPdfFile : SummaryEvent - - data class DownLoadFromUrl(val url: String) : SummaryEvent // todo remove } From 34317a9c0d44606db4df55b9d16f7454415b7eb7 Mon Sep 17 00:00:00 2001 From: stylianosgakis Date: Mon, 4 Nov 2024 14:08:28 +0100 Subject: [PATCH 5/8] Better name the animation dependency --- app/app/build.gradle.kts | 2 +- app/audio-player-ui/build.gradle.kts | 2 +- app/ui/placeholder/build.gradle.kts | 2 +- app/ui/pullrefresh/build.gradle.kts | 2 +- gradle/libs.versions.toml | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/app/build.gradle.kts b/app/app/build.gradle.kts index 1ac4278653..5fca68203d 100644 --- a/app/app/build.gradle.kts +++ b/app/app/build.gradle.kts @@ -107,7 +107,7 @@ android { dependencies { implementation(platform(libs.firebase.bom)) implementation(libs.androidx.activity.compose) - implementation(libs.androidx.compose.animation) + implementation(libs.androidx.compose.animationCore) implementation(libs.androidx.compose.foundation) implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.material3.windowSizeClass) diff --git a/app/audio-player-ui/build.gradle.kts b/app/audio-player-ui/build.gradle.kts index 82c962dac6..fc93958d88 100644 --- a/app/audio-player-ui/build.gradle.kts +++ b/app/audio-player-ui/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } dependencies { - implementation(libs.androidx.compose.animation) + implementation(libs.androidx.compose.animationCore) implementation(libs.androidx.compose.foundation) implementation(libs.androidx.compose.uiUtil) implementation(libs.androidx.lifecycle.compose) diff --git a/app/ui/placeholder/build.gradle.kts b/app/ui/placeholder/build.gradle.kts index 227f91670d..cba8395e4c 100644 --- a/app/ui/placeholder/build.gradle.kts +++ b/app/ui/placeholder/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } dependencies { - implementation(libs.androidx.compose.animation) + implementation(libs.androidx.compose.animationCore) implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.runtime) implementation(libs.androidx.compose.uiUtil) diff --git a/app/ui/pullrefresh/build.gradle.kts b/app/ui/pullrefresh/build.gradle.kts index d00c0d3385..d79d558748 100644 --- a/app/ui/pullrefresh/build.gradle.kts +++ b/app/ui/pullrefresh/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } dependencies { - implementation(libs.androidx.compose.animation) + implementation(libs.androidx.compose.animationCore) implementation(libs.androidx.compose.material3) implementation(libs.androidx.compose.runtime) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 33771cb4ed..d36f0a04b4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -88,6 +88,7 @@ androidx-activity-compose = { module = "androidx.activity:activity-compose", ver androidx-activity-core = { module = "androidx.activity:activity", version.ref = "androidx-activity-core" } androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" } androidx-compose-animation = { module = "androidx.compose.animation:animation-core" } +androidx-compose-animationCore = { module = "androidx.compose.animation:animation-core" } androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-composeBom" } androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" } androidx-compose-foundationLayout = { module = "androidx.compose.foundation:foundation-layout" } From 51f44b1ecff4c566bdb78fce0a7b065ba7d12847 Mon Sep 17 00:00:00 2001 From: stylianosgakis Date: Mon, 4 Nov 2024 14:21:32 +0100 Subject: [PATCH 6/8] Remove pdf sharing glue code --- .../android/app/navigation/HedvigNavHost.kt | 1 - .../change/tier/navigation/ChooseTierGraph.kt | 6 +---- .../tier/ui/stepsummary/SummaryDestination.kt | 23 +------------------ 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/app/app/src/main/kotlin/com/hedvig/android/app/navigation/HedvigNavHost.kt b/app/app/src/main/kotlin/com/hedvig/android/app/navigation/HedvigNavHost.kt index 545572ab1d..54a67e31f6 100644 --- a/app/app/src/main/kotlin/com/hedvig/android/app/navigation/HedvigNavHost.kt +++ b/app/app/src/main/kotlin/com/hedvig/android/app/navigation/HedvigNavHost.kt @@ -327,7 +327,6 @@ internal fun HedvigNavHost( changeTierGraph( navigator = navigator, navController = hedvigAppState.navController, - applicationId = hedvigBuildConstants.appId, ) movingFlowGraph( navController = hedvigAppState.navController, diff --git a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/navigation/ChooseTierGraph.kt b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/navigation/ChooseTierGraph.kt index a83de1bdf5..06c74880d2 100644 --- a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/navigation/ChooseTierGraph.kt +++ b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/navigation/ChooseTierGraph.kt @@ -3,7 +3,6 @@ package com.hedvig.android.feature.change.tier.navigation import androidx.compose.ui.platform.LocalContext import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder -import com.hedvig.android.core.common.android.sharePDF import com.hedvig.android.feature.change.tier.ui.chooseinsurance.ChooseInsuranceToChangeTierDestination import com.hedvig.android.feature.change.tier.ui.chooseinsurance.ChooseInsuranceViewModel import com.hedvig.android.feature.change.tier.ui.comparison.ComparisonDestination @@ -24,7 +23,7 @@ import com.hedvig.android.navigation.core.Navigator import org.koin.androidx.compose.koinViewModel import org.koin.core.parameter.parametersOf -fun NavGraphBuilder.changeTierGraph(navigator: Navigator, navController: NavController, applicationId: String) { +fun NavGraphBuilder.changeTierGraph(navigator: Navigator, navController: NavController) { navdestination { _ -> val viewModel: StartTierFlowViewModel = koinViewModel { parametersOf(this.insuranceId) @@ -115,9 +114,6 @@ fun NavGraphBuilder.changeTierGraph(navigator: Navigator, navController: NavCont onFailure = { navigator.navigateUnsafe(ChooseTierDestination.SubmitFailure) }, - sharePdf = { - context.sharePDF(it, applicationId) - }, onSuccess = { navigator.navigateUnsafe(ChooseTierDestination.SubmitSuccess(this.params.activationDate)) { typedPopUpTo { diff --git a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryDestination.kt b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryDestination.kt index e63a7f67cc..66b5478450 100644 --- a/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryDestination.kt +++ b/app/feature/feature-choose-tier/src/main/kotlin/com/hedvig/android/feature/change/tier/ui/stepsummary/SummaryDestination.kt @@ -48,7 +48,6 @@ import com.hedvig.android.feature.change.tier.ui.stepsummary.SummaryState.Succes import com.hedvig.android.tiersandaddons.QuoteCard import com.hedvig.android.tiersandaddons.QuoteDisplayItem import hedvig.resources.R -import java.io.File @Composable internal fun ChangeTierSummaryDestination( @@ -56,7 +55,6 @@ internal fun ChangeTierSummaryDestination( navigateUp: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit, - sharePdf: (File) -> Unit, ) { val uiState: SummaryState by viewModel.uiState.collectAsStateWithLifecycle() SummaryScreen( @@ -72,10 +70,6 @@ internal fun ChangeTierSummaryDestination( viewModel.emit(SummaryEvent.ClearNavigation) onFailure() }, - sharePdf = { file -> - viewModel.emit(SummaryEvent.HandledSharingPdfFile) - sharePdf(file) - }, navigateUp = navigateUp, onSubmitQuoteClick = { viewModel.emit(SummaryEvent.SubmitQuote) @@ -90,7 +84,6 @@ private fun SummaryScreen( onSuccess: () -> Unit, navigateUp: () -> Unit, onFailure: () -> Unit, - sharePdf: (File) -> Unit, onSubmitQuoteClick: () -> Unit, ) { when (uiState) { @@ -127,9 +120,6 @@ private fun SummaryScreen( uiState = uiState, navigateUp = navigateUp, onConfirmClick = onSubmitQuoteClick, - sharePdf = { file -> - sharePdf(file) - }, ) } } @@ -144,17 +134,7 @@ private fun MakingChangesScreen() { } @Composable -private fun SummarySuccessScreen( - uiState: Success, - onConfirmClick: () -> Unit, - sharePdf: (File) -> Unit, - navigateUp: () -> Unit, -) { - if (uiState.savedFileUri != null) { - LaunchedEffect(uiState.savedFileUri) { - sharePdf(uiState.savedFileUri) - } - } +private fun SummarySuccessScreen(uiState: Success, onConfirmClick: () -> Unit, navigateUp: () -> Unit) { HedvigScaffold( navigateUp, topAppBarText = stringResource(R.string.TIER_FLOW_SUMMARY_TITLE), @@ -259,7 +239,6 @@ private fun PreviewChooseInsuranceScreen( {}, {}, {}, - {}, ) } } From fb044d073b3ef9f39ed6ff79d2b716b4496b3806 Mon Sep 17 00:00:00 2001 From: stylianosgakis Date: Mon, 4 Nov 2024 14:21:45 +0100 Subject: [PATCH 7/8] Remove duplicate call of `changeTierGraph` --- .../com/hedvig/android/app/navigation/HedvigNavHost.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/app/src/main/kotlin/com/hedvig/android/app/navigation/HedvigNavHost.kt b/app/app/src/main/kotlin/com/hedvig/android/app/navigation/HedvigNavHost.kt index 54a67e31f6..a9f9c043c0 100644 --- a/app/app/src/main/kotlin/com/hedvig/android/app/navigation/HedvigNavHost.kt +++ b/app/app/src/main/kotlin/com/hedvig/android/app/navigation/HedvigNavHost.kt @@ -183,11 +183,6 @@ internal fun HedvigNavHost( openUrl = openUrl, navigator = navigator, ) - changeTierGraph( - navigator = navigator, - navController = hedvigAppState.navController, - applicationId = hedvigBuildConstants.appId, - ) insuranceGraph( nestedGraphs = { terminateInsuranceGraph( From 37cfe8e53208578a948351855881053af6a61287 Mon Sep 17 00:00:00 2001 From: stylianosgakis Date: Mon, 4 Nov 2024 14:23:00 +0100 Subject: [PATCH 8/8] Fix ui-tiers-and-addons dependencies --- app/feature/feature-movingflow/build.gradle.kts | 2 +- app/ui/ui-tiers-and-addons/build.gradle.kts | 12 ++++++++++++ gradle/libs.versions.toml | 4 +++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/feature/feature-movingflow/build.gradle.kts b/app/feature/feature-movingflow/build.gradle.kts index 98f81438c0..0dd1c4e197 100644 --- a/app/feature/feature-movingflow/build.gradle.kts +++ b/app/feature/feature-movingflow/build.gradle.kts @@ -28,12 +28,12 @@ dependencies { implementation(projects.coreUiData) implementation(projects.dataContractAndroid) implementation(projects.dataProductVariantAndroid) - implementation(projects.uiTiersAndAddons) implementation(projects.dataProductVariantPublic) implementation(projects.designSystemHedvig) implementation(projects.moleculeAndroid) implementation(projects.moleculePublic) implementation(projects.navigationCompose) + implementation(projects.uiTiersAndAddons) } apollo { diff --git a/app/ui/ui-tiers-and-addons/build.gradle.kts b/app/ui/ui-tiers-and-addons/build.gradle.kts index 67df7e75a6..6defb52a1c 100644 --- a/app/ui/ui-tiers-and-addons/build.gradle.kts +++ b/app/ui/ui-tiers-and-addons/build.gradle.kts @@ -7,9 +7,21 @@ plugins { } dependencies { + api(libs.androidx.compose.runtime) + api(libs.androidx.compose.uiCore) + + implementation(libs.androidx.compose.animation) + implementation(libs.androidx.compose.animationCore) + implementation(libs.androidx.compose.foundation) + implementation(libs.androidx.compose.foundationLayout) + implementation(libs.androidx.compose.runtimeSaveable) + implementation(libs.androidx.compose.uiGraphics) + implementation(libs.androidx.compose.uiText) + implementation(libs.androidx.compose.uiUnit) implementation(projects.composeUi) implementation(projects.coreResources) implementation(projects.dataContractAndroid) + implementation(projects.dataContractPublic) implementation(projects.dataProductVariantPublic) implementation(projects.designSystemHedvig) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d36f0a04b4..7a3cc2f3b4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -87,7 +87,7 @@ accompanist-permissions = { module = "com.google.accompanist:accompanist-permiss androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" } androidx-activity-core = { module = "androidx.activity:activity", version.ref = "androidx-activity-core" } androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "androidx-annotation" } -androidx-compose-animation = { module = "androidx.compose.animation:animation-core" } +androidx-compose-animation = { module = "androidx.compose.animation:animation" } androidx-compose-animationCore = { module = "androidx.compose.animation:animation-core" } androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-composeBom" } androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" } @@ -97,7 +97,9 @@ androidx-compose-material3-windowSizeClass = { module = "androidx.compose.materi androidx-compose-materialIconsCore = { module = "androidx.compose.material:material-icons-core" } androidx-compose-materialRipple = { module = "androidx.compose.material:material-ripple" } androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" } +androidx-compose-runtimeSaveable = { module = "androidx.compose.runtime:runtime-saveable" } androidx-compose-uiCore = { module = "androidx.compose.ui:ui" } +androidx-compose-uiText = { module = "androidx.compose.ui:ui-text" } androidx-compose-uiGraphics = { module = "androidx.compose.ui:ui-graphics" } androidx-compose-uiTestManifest = { module = "androidx.compose.ui:ui-test-manifest" } androidx-compose-uiTooling = { module = "androidx.compose.ui:ui-tooling" }