Skip to content

Commit

Permalink
Merge pull request #1919 from HedvigInsurance/feature/payments
Browse files Browse the repository at this point in the history
Updated payments screens
  • Loading branch information
hugokallstrom authored Dec 11, 2023
2 parents 61c6b61 + d57dac4 commit 0d7459e
Show file tree
Hide file tree
Showing 39 changed files with 2,571 additions and 1,343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,30 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.hedvig.android.core.designsystem.component.button.HedvigContainedSmallButton
import com.hedvig.android.core.designsystem.material3.infoElement
import com.hedvig.android.core.designsystem.preview.HedvigPreview
import com.hedvig.android.core.designsystem.theme.HedvigTheme
import com.hedvig.android.core.icons.Hedvig
import com.hedvig.android.core.icons.hedvig.normal.InfoFilled
import hedvig.resources.R

@Composable
fun HedvigInformationSection(
title: String,
buttonText: String,
onButtonClick: () -> Unit,
modifier: Modifier = Modifier,
buttonText: String = stringResource(id = R.string.ALERT_OK),
onButtonClick: (() -> Unit)? = null,
subTitle: String? = null,
contentPadding: PaddingValues = WindowInsets.safeDrawing.asPaddingValues(),
withDefaultVerticalSpacing: Boolean = true,
Expand Down Expand Up @@ -73,12 +78,28 @@ fun HedvigInformationSection(
}
}
Spacer(Modifier.height(24.dp))
HedvigContainedSmallButton(
text = buttonText,
onClick = onButtonClick,
)
if (onButtonClick != null) {
HedvigContainedSmallButton(
text = buttonText,
onClick = onButtonClick,
)
}
if (withDefaultVerticalSpacing) {
Spacer(Modifier.height(32.dp))
}
}
}

@HedvigPreview
@Composable
fun HedvigInformationSectionPreview() {
HedvigTheme {
Surface {
HedvigInformationSection(
title = "Test",
buttonText = "Click",
onButtonClick = { /*TODO*/ },
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ fun hedvigDateTimeFormatter(locale: Locale): DateTimeFormatter {
return DateTimeFormatter.ofPattern("d MMM yyyy", locale)
}

/**
* Example output: "May 26 2023"
*/
fun hedvigSecondaryDateTimeFormatter(locale: Locale): DateTimeFormatter {
return DateTimeFormatter.ofPattern("MMMM d yyyy", locale)
fun hedvigMonthDateTimeFormatter(locale: Locale): DateTimeFormatter {
return DateTimeFormatter.ofPattern("d MMM", locale)
}

/**
Expand All @@ -35,6 +32,12 @@ fun rememberHedvigDateTimeFormatter(): DateTimeFormatter {
return remember(locale) { hedvigDateTimeFormatter(locale) }
}

@Composable
fun rememberHedvigMonthDateTimeFormatter(): DateTimeFormatter {
val locale = getLocale()
return remember(locale) { hedvigMonthDateTimeFormatter(locale) }
}

@Composable
fun rememberHedvigBirthDateDateTimeFormatter(): DateTimeFormatter {
val locale = getLocale()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.hedvig.android.core.ui.infocard

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
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.material.icons.Icons
import androidx.compose.material3.CardColors
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import com.hedvig.android.core.designsystem.component.card.HedvigInfoCard
import com.hedvig.android.core.designsystem.preview.HedvigPreview
import com.hedvig.android.core.designsystem.theme.HedvigTheme
import com.hedvig.android.core.icons.Hedvig
import com.hedvig.android.core.icons.hedvig.normal.WarningFilled

@Composable
fun VectorErrorCard(
text: String,
modifier: Modifier = Modifier,
icon: ImageVector = Icons.Hedvig.WarningFilled,
iconColor: Color = MaterialTheme.colorScheme.error,
colors: CardColors = CardDefaults.outlinedCardColors(
containerColor = MaterialTheme.colorScheme.errorContainer,
contentColor = MaterialTheme.colorScheme.onErrorContainer,
),
) {
VectorErrorCard(
text = text,
modifier = modifier,
icon = icon,
iconColor = iconColor,
colors = colors,
underTextContent = null,
)
}

@Composable
fun VectorErrorCard(
text: String,
modifier: Modifier = Modifier,
icon: ImageVector = Icons.Hedvig.WarningFilled,
iconColor: Color = MaterialTheme.colorScheme.error,
colors: CardColors = CardDefaults.outlinedCardColors(
containerColor = MaterialTheme.colorScheme.errorContainer,
contentColor = MaterialTheme.colorScheme.onErrorContainer,
),
underTextContent: @Composable (ColumnScope.() -> Unit)?,
) {
HedvigInfoCard(
modifier = modifier,
contentPadding = PaddingValues(
start = 12.dp,
top = 12.dp,
end = 16.dp,
bottom = 12.dp,
),
colors = colors,
) {
Icon(
imageVector = icon,
contentDescription = "info",
modifier = Modifier
.padding(top = 2.dp)
.size(16.dp),
tint = iconColor,
)
Spacer(Modifier.width(8.dp))
Column {
Text(
text = text,
style = MaterialTheme.typography.bodyMedium,
)
if (underTextContent != null) {
Spacer(Modifier.height(12.dp))
underTextContent()
Spacer(Modifier.height(4.dp))
}
}
}
}

@HedvigPreview
@Composable
private fun PreviewVectorInfoCard() {
HedvigTheme {
Surface(color = MaterialTheme.colorScheme.background) {
VectorErrorCard("Lorem ipsum")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.hedvig.android.core.ui.infocard

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
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.material.icons.Icons
import androidx.compose.material3.CardColors
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import com.hedvig.android.core.designsystem.component.card.HedvigInfoCard
import com.hedvig.android.core.designsystem.material3.onTypeContainer
import com.hedvig.android.core.designsystem.material3.typeContainer
import com.hedvig.android.core.designsystem.material3.typeElement
import com.hedvig.android.core.designsystem.preview.HedvigPreview
import com.hedvig.android.core.designsystem.theme.HedvigTheme
import com.hedvig.android.core.icons.Hedvig
import com.hedvig.android.core.icons.hedvig.small.hedvig.Checkmark

@Composable
fun VectorSuccessCard(
text: String,
modifier: Modifier = Modifier,
icon: ImageVector = Icons.Hedvig.Checkmark,
iconColor: Color = MaterialTheme.colorScheme.typeElement,
colors: CardColors = CardDefaults.outlinedCardColors(
containerColor = MaterialTheme.colorScheme.typeContainer,
contentColor = MaterialTheme.colorScheme.onTypeContainer,
),
) {
VectorSuccessCard(
text = text,
modifier = modifier,
icon = icon,
iconColor = iconColor,
colors = colors,
underTextContent = null,
)
}

@Composable
fun VectorSuccessCard(
text: String,
modifier: Modifier = Modifier,
icon: ImageVector = Icons.Hedvig.Checkmark,
iconColor: Color = MaterialTheme.colorScheme.typeElement,
colors: CardColors = CardDefaults.outlinedCardColors(
containerColor = MaterialTheme.colorScheme.typeContainer,
contentColor = MaterialTheme.colorScheme.onTypeContainer,
),
underTextContent: @Composable (ColumnScope.() -> Unit)?,
) {
HedvigInfoCard(
modifier = modifier,
contentPadding = PaddingValues(
start = 12.dp,
top = 12.dp,
end = 16.dp,
bottom = 12.dp,
),
colors = colors,
) {
Icon(
imageVector = icon,
contentDescription = "info",
modifier = Modifier
.padding(top = 2.dp)
.size(16.dp),
tint = iconColor,
)
Spacer(Modifier.width(8.dp))
Column {
Text(
text = text,
style = MaterialTheme.typography.bodyMedium,
)
if (underTextContent != null) {
Spacer(Modifier.height(12.dp))
underTextContent()
Spacer(Modifier.height(4.dp))
}
}
}
}

@HedvigPreview
@Composable
private fun PreviewVectorSuccessCard() {
HedvigTheme {
Surface(color = MaterialTheme.colorScheme.background) {
VectorSuccessCard("Lorem ipsum")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.hedvig.android.apollo.NetworkCacheManager
import com.hedvig.android.core.common.ErrorMessage
import com.hedvig.android.core.common.safeCast
import com.hedvig.android.feature.connect.payment.trustly.data.TrustlyCallback
Expand All @@ -18,6 +19,7 @@ internal class TrustlyPresenter(
private val trustlyCallback: TrustlyCallback,
private val startTrustlySessionUseCase: StartTrustlySessionUseCase,
private val market: Market,
private val cacheManager: NetworkCacheManager,
) : MoleculePresenter<TrustlyEvent, TrustlyUiState> {
@Composable
override fun MoleculePresenterScope<TrustlyEvent>.present(lastState: TrustlyUiState): TrustlyUiState {
Expand Down Expand Up @@ -68,6 +70,9 @@ internal class TrustlyPresenter(
}

if (succeededInConnectingCard) {
LaunchedEffect(Unit) {
cacheManager.clearCache()
}
return TrustlyUiState.SucceededInConnectingCard
}
if (connectingCardFailed) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hedvig.android.feature.connect.payment.trustly

import com.hedvig.android.apollo.NetworkCacheManager
import com.hedvig.android.feature.connect.payment.trustly.data.TrustlyCallback
import com.hedvig.android.market.Market
import com.hedvig.android.molecule.android.MoleculeViewModel
Expand All @@ -8,11 +9,13 @@ internal class TrustlyViewModel(
market: Market,
trustlyCallback: TrustlyCallback,
startTrustlySessionUseCase: StartTrustlySessionUseCase,
networkCacheManager: NetworkCacheManager,
) : MoleculeViewModel<TrustlyEvent, TrustlyUiState>(
TrustlyUiState.Loading,
TrustlyPresenter(
trustlyCallback,
startTrustlySessionUseCase,
market,
networkCacheManager,
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ internal interface TrustlyCallback {
internal class TrustlyCallbackImpl(
hedvigBuildConstants: HedvigBuildConstants,
) : TrustlyCallback {
override val successUrl: String = "${hedvigBuildConstants.deepLinkHost}/payment-success"
override val failureUrl: String = "${hedvigBuildConstants.deepLinkHost}/payment-failure"
override val successUrl: String = "https://${hedvigBuildConstants.deepLinkHost}/payment-success"
override val failureUrl: String = "https://${hedvigBuildConstants.deepLinkHost}/payment-failure"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hedvig.android.feature.connect.payment.trustly.di

import com.apollographql.apollo3.ApolloClient
import com.hedvig.android.apollo.NetworkCacheManager
import com.hedvig.android.core.buildconstants.HedvigBuildConstants
import com.hedvig.android.feature.connect.payment.trustly.StartTrustlySessionUseCase
import com.hedvig.android.feature.connect.payment.trustly.TrustlyViewModel
Expand All @@ -20,6 +21,7 @@ val connectPaymentTrustlyModule = module {
market = market,
trustlyCallback = get<TrustlyCallback>(),
startTrustlySessionUseCase = get<StartTrustlySessionUseCase>(),
networkCacheManager = get<NetworkCacheManager>(),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mutation AddDiscount($code: String!) {
memberCampaignsRedeem(code: $code) {
userError {
message
}
}
}
Loading

0 comments on commit 0d7459e

Please sign in to comment.