Skip to content

Commit

Permalink
Merge pull request #2314 from HedvigInsurance/new-design/payments
Browse files Browse the repository at this point in the history
GEN-2544 New design/payments
  • Loading branch information
panasetskaya authored Nov 20, 2024
2 parents 7d62796 + 32ae51c commit c61d221
Show file tree
Hide file tree
Showing 25 changed files with 718 additions and 594 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.hedvig.android.design.system.hedvig

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.hedvig.android.design.system.hedvig.EmptyStateDefaults.EmptyStateButtonStyle.NoButton
import hedvig.resources.R

@Composable
fun HedvigInformationSection(
title: String,
modifier: Modifier = Modifier,
subTitle: String? = null,
onButtonClick: (() -> Unit)? = null,
buttonText: String = stringResource(id = R.string.ALERT_OK),
windowInsets: WindowInsets = WindowInsets.safeDrawing,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = modifier
.windowInsetsPadding(windowInsets)
.padding(horizontal = 16.dp),
) {
val buttonStyle = if (onButtonClick != null) {
EmptyStateDefaults.EmptyStateButtonStyle.Button(
buttonText = buttonText,
onButtonClick = onButtonClick,
)
} else {
NoButton
}
EmptyState(
text = title,
description = subTitle,
iconStyle = EmptyStateDefaults.EmptyStateIconStyle.INFO,
buttonStyle = buttonStyle,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fun HedvigScaffold(
topAppBarActionType: TopAppBarActionType = TopAppBarActionType.BACK,
itemsColumnHorizontalAlignment: Alignment.Horizontal = Alignment.Start,
topAppBarActions: @Composable RowScope.() -> Unit = {},
customTopAppBarColors: TopAppBarColors? = null,
content: @Composable ColumnScope.() -> Unit,
) {
Surface(
Expand All @@ -42,6 +43,7 @@ fun HedvigScaffold(
onActionClick = dropUnlessResumed(block = navigateUp),
topAppBarActions = topAppBarActions,
windowInsets = topAppbarInsets,
customTopAppBarColors = customTopAppBarColors,
)
Column(
horizontalAlignment = itemsColumnHorizontalAlignment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.hedvig.android.design.system.hedvig.TopAppBarDefaults.windowInsets
Expand Down Expand Up @@ -87,10 +88,23 @@ fun TopAppBar(
modifier: Modifier = Modifier,
topAppBarActions: @Composable (RowScope.() -> Unit)? = null,
windowInsets: WindowInsets = TopAppBarDefaults.windowInsets,
customTopAppBarColors: TopAppBarColors? = null,
) {
Surface(
color = TopAppBarTokens.ContainerColor.value,
contentColor = TopAppBarTokens.ContentColor.value,
color = if (customTopAppBarColors !=
null
) {
customTopAppBarColors.containerColor
} else {
TopAppBarTokens.ContainerColor.value
},
contentColor = if (customTopAppBarColors !=
null
) {
customTopAppBarColors.contentColor
} else {
TopAppBarTokens.ContentColor.value
},
modifier = modifier
.windowInsetsPadding(windowInsets)
.fillMaxWidth()
Expand All @@ -117,6 +131,7 @@ fun TopAppBar(
TopAppBarActionType.CLOSE -> HedvigIcons.Close
},
contentDescription = null,
tint = TopAppBarTokens.ContentColor.value,
)
},
)
Expand Down Expand Up @@ -197,3 +212,8 @@ internal object TopAppBarDefaults {
.union(WindowInsets.displayCutout)
.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top)
}

data class TopAppBarColors(
val containerColor: Color,
val contentColor: Color,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.hedvig.android.design.system.hedvig.HedvigTheme

// Icons.Hedvig.Waiting in the old DS
@Suppress("UnusedReceiverParameter")
val HedvigIcons.Clock: ImageVector
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ private fun PreviewHomeLayoutCenteredContent() {
Surface(color = HedvigTheme.colorScheme.backgroundPrimary, modifier = Modifier.fillMaxSize()) {
BoxWithConstraints {
PreviewHomeLayout(
maxWidth = constraints.maxWidth,
maxHeight = constraints.maxHeight,
maxWidth = this.constraints.maxWidth,
maxHeight = this.constraints.maxHeight,
claimStatusCards = {
Column(Modifier.padding(horizontal = 16.dp), Arrangement.spacedBy(8.dp)) {
PreviewBox { HedvigText("claim status card") }
Expand All @@ -228,8 +228,8 @@ private fun PreviewHomeLayoutCenteredContentWithSomeBottomAttachedContent() {
Surface(color = HedvigTheme.colorScheme.backgroundPrimary, modifier = Modifier.fillMaxSize()) {
BoxWithConstraints {
PreviewHomeLayout(
maxWidth = constraints.maxWidth,
maxHeight = constraints.maxHeight,
maxWidth = this.constraints.maxWidth,
maxHeight = this.constraints.maxHeight,
memberReminderCards = {
Column(Modifier.padding(horizontal = 16.dp), Arrangement.spacedBy(8.dp)) {
repeat(1) { index ->
Expand All @@ -250,8 +250,8 @@ private fun PreviewHomeLayoutNonCenteredNonScrollableContent() {
Surface(color = HedvigTheme.colorScheme.backgroundPrimary, modifier = Modifier.fillMaxSize()) {
BoxWithConstraints {
PreviewHomeLayout(
maxWidth = constraints.maxWidth,
maxHeight = constraints.maxHeight,
maxWidth = this.constraints.maxWidth,
maxHeight = this.constraints.maxHeight,
veryImportantMessages = {
Column(Modifier.padding(horizontal = 16.dp), Arrangement.spacedBy(8.dp)) {
PreviewBox(0) { HedvigText("Important message") }
Expand All @@ -277,8 +277,8 @@ private fun PreviewHomeLayoutScrollingContent() {
Surface(color = HedvigTheme.colorScheme.backgroundPrimary, modifier = Modifier.fillMaxSize()) {
BoxWithConstraints {
PreviewHomeLayout(
maxWidth = constraints.maxWidth,
maxHeight = constraints.maxHeight,
maxWidth = this.constraints.maxWidth,
maxHeight = this.constraints.maxHeight,
claimStatusCards = {
Column(Modifier.padding(horizontal = 16.dp), Arrangement.spacedBy(8.dp)) {
PreviewBox { HedvigText("claim status card") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,21 @@ private fun InsuranceScreen(
}
AnimatedContent(
targetState = uiState,
Modifier.weight(1f),
transitionSpec = {
fadeIn() togetherWith fadeOut()
},
label = "uiState",
) { state ->
if (state.hasError) {
HedvigErrorSection(
onButtonClick = reload,
modifier = Modifier.fillMaxSize(),
)
Column {
Spacer(Modifier.weight(1f))
HedvigErrorSection(
onButtonClick = reload,
modifier = Modifier.fillMaxSize().padding(horizontal = 16.dp),
)
Spacer(Modifier.weight(1f))
}
} else {
InsuranceScreenContent(
uiState = state,
Expand Down Expand Up @@ -394,6 +399,16 @@ private fun PreviewInsuranceDestinationAnimation() {

private class InsuranceUiStateProvider : CollectionPreviewParameterProvider<InsuranceUiState>(
listOf(
InsuranceUiState(
contracts = listOf(),
crossSells = listOf(),
hasError = true,
isLoading = false,
isRetrying = false,
quantityOfCancelledInsurances = 0,
showNotificationBadge = false,
shouldSuggestMovingFlow = true,
),
InsuranceUiState(
contracts = listOf(),
crossSells = listOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ private fun ChoseCoverageLevelAndDeductibleScreen(
Spacer(Modifier.height(8.dp))
CoverageCard(content.tiersInfo, onSelectCoverageOption, onSelectDeductibleOption)
Spacer(Modifier.height(8.dp))
// todo Add comparison API results here
if (content.tiersInfo.coverageOptions.isNotEmpty()) {
HedvigTextButton(
text = stringResource(R.string.TIER_FLOW_COMPARE_BUTTON),
Expand Down
5 changes: 1 addition & 4 deletions app/feature/feature-payments/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ android {

dependencies {
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.lifecycle.compose)
implementation(libs.apollo.normalizedCache)
implementation(libs.apollo.runtime)
Expand All @@ -33,10 +34,7 @@ dependencies {
implementation(projects.coreCommonPublic)
implementation(projects.coreDatastorePublic)
implementation(projects.coreDemoMode)
implementation(projects.coreDesignSystem)
implementation(projects.coreIcons)
implementation(projects.coreResources)
implementation(projects.coreUi)
implementation(projects.coreUiData)
implementation(projects.dataContractAndroid)
implementation(projects.dataContractPublic)
Expand All @@ -57,7 +55,6 @@ dependencies {
implementation(projects.navigationComposeTyped)
implementation(projects.navigationCore)
implementation(projects.notificationPermission)
implementation(projects.placeholder)
implementation(projects.pullrefresh)
implementation(projects.theme)
testImplementation(libs.coroutines.test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ internal class GetChargeDetailsUseCaseImpl(
result.currentMember.redeemedCampaigns,
result.currentMember.referralInformation,
clock,
).takeIf { it?.id == id }
)
val futureMemberChargeWithThisId = futureMemberCharge.takeIf { it?.id == id }

val pastMemberCharge = pastCharges.firstOrNull { it.id == id }
PaymentDetails(
memberCharge = futureMemberCharge ?: pastMemberCharge ?: raise(ErrorMessage()),
memberCharge = futureMemberChargeWithThisId ?: pastMemberCharge ?: raise(ErrorMessage()),
pastCharges = pastCharges,
upComingCharge = futureMemberCharge,
paymentConnection = run {
val paymentInformation = result.currentMember.paymentInformation
when (paymentInformation.status) {
Expand Down Expand Up @@ -73,11 +76,12 @@ internal data class PaymentDetails(
val memberCharge: MemberCharge,
val pastCharges: List<MemberCharge>?,
val paymentConnection: PaymentConnection?,
val upComingCharge: MemberCharge?,
) {
fun getNextCharge(selectedMemberCharge: MemberCharge): MemberCharge? {
val index = (pastCharges?.indexOf(selectedMemberCharge) ?: 0) + 1
return if (pastCharges != null && index > pastCharges.size - 1) {
memberCharge
null
} else {
pastCharges?.get(index)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import com.hedvig.android.feature.payments.data.GetDiscountsUseCase
import com.hedvig.android.feature.payments.data.GetDiscountsUseCaseImpl
import com.hedvig.android.feature.payments.data.GetPaymentsHistoryUseCase
import com.hedvig.android.feature.payments.data.GetPaymentsHistoryUseCaseImpl
import com.hedvig.android.feature.payments.details.PaymentDetailsViewModel
import com.hedvig.android.feature.payments.discounts.DiscountsViewModel
import com.hedvig.android.feature.payments.history.PaymentHistoryViewModel
import com.hedvig.android.feature.payments.overview.data.AddDiscountUseCase
import com.hedvig.android.feature.payments.overview.data.AddDiscountUseCaseImpl
import com.hedvig.android.feature.payments.overview.data.GetForeverInformationUseCase
Expand All @@ -23,7 +20,10 @@ import com.hedvig.android.feature.payments.overview.data.GetUpcomingPaymentUseCa
import com.hedvig.android.feature.payments.overview.data.GetUpcomingPaymentUseCaseDemo
import com.hedvig.android.feature.payments.overview.data.GetUpcomingPaymentUseCaseImpl
import com.hedvig.android.feature.payments.overview.data.GetUpcomingPaymentUseCaseProvider
import com.hedvig.android.feature.payments.payments.PaymentsViewModel
import com.hedvig.android.feature.payments.ui.details.PaymentDetailsViewModel
import com.hedvig.android.feature.payments.ui.discounts.DiscountsViewModel
import com.hedvig.android.feature.payments.ui.history.PaymentHistoryViewModel
import com.hedvig.android.feature.payments.ui.payments.PaymentsViewModel
import com.hedvig.android.market.MarketManager
import kotlinx.datetime.Clock
import org.koin.core.module.dsl.viewModel
Expand Down

This file was deleted.

Loading

0 comments on commit c61d221

Please sign in to comment.