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

feature(bank-sdk): Skonto. Handle UI on small devices #629

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@file:OptIn(ExperimentalMaterial3Api::class)
@file:OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3Api::class)

package net.gini.android.bank.sdk.capture.digitalinvoice.skonto

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.icu.util.Calendar
import android.os.Bundle
import android.view.LayoutInflater
Expand Down Expand Up @@ -57,7 +56,6 @@ import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.window.Dialog
Expand Down Expand Up @@ -91,6 +89,8 @@ import net.gini.android.capture.ui.components.textinput.amount.GiniAmountTextInp
import net.gini.android.capture.ui.components.tooltip.GiniTooltipBox
import net.gini.android.capture.ui.components.topbar.GiniTopBar
import net.gini.android.capture.ui.components.topbar.GiniTopBarColors
import net.gini.android.capture.ui.compose.GiniScreenPreviewSizes
import net.gini.android.capture.ui.compose.GiniScreenPreviewUiModes
import net.gini.android.capture.ui.theme.GiniTheme
import net.gini.android.capture.ui.theme.modifier.tabletMaxWidth
import net.gini.android.capture.util.compose.keyboardPadding
Expand Down Expand Up @@ -551,6 +551,7 @@ private fun SkontoSection(
verticalAlignment = Alignment.CenterVertically,
) {
Text(
modifier = Modifier.weight(1f, fill = false),
text = stringResource(id = R.string.gbs_skonto_section_discount_title),
style = GiniTheme.typography.subtitle1,
color = colors.titleTextColor,
Expand Down Expand Up @@ -857,21 +858,16 @@ private fun InfoDialog(
}

@Composable
@Preview
@GiniScreenPreviewUiModes
@GiniScreenPreviewSizes
private fun ScreenReadyStatePreviewLight() {
ScreenReadyStatePreview()
}

@Composable
@Preview(uiMode = UI_MODE_NIGHT_YES)
private fun ScreenReadyStatePreviewDark() {
ScreenReadyStatePreview()
}

@Composable
private fun ScreenReadyStatePreview() {
GiniTheme {
var state by remember { mutableStateOf(previewState) }
val state by remember { mutableStateOf(previewState) }

ScreenReadyState(
state = state,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
@file:OptIn(ExperimentalMaterial3Api::class)
@file:OptIn(
ExperimentalMaterial3Api::class,
ExperimentalMaterial3Api::class,
ExperimentalMaterial3Api::class
)

package net.gini.android.bank.sdk.capture.skonto

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.icu.util.Calendar
import android.widget.FrameLayout
import androidx.activity.compose.BackHandler
Expand All @@ -18,11 +21,11 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
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.requiredWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
Expand Down Expand Up @@ -52,7 +55,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.window.Dialog
Expand Down Expand Up @@ -82,6 +84,8 @@ import net.gini.android.capture.ui.components.textinput.amount.GiniAmountTextInp
import net.gini.android.capture.ui.components.tooltip.GiniTooltipBox
import net.gini.android.capture.ui.components.topbar.GiniTopBar
import net.gini.android.capture.ui.components.topbar.GiniTopBarColors
import net.gini.android.capture.ui.compose.GiniScreenPreviewSizes
import net.gini.android.capture.ui.compose.GiniScreenPreviewUiModes
import net.gini.android.capture.ui.theme.GiniTheme
import net.gini.android.capture.ui.theme.modifier.tabletMaxWidth
import net.gini.android.capture.ui.theme.typography.bold
Expand Down Expand Up @@ -507,28 +511,35 @@ private fun SkontoSection(
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Start,
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = stringResource(id = R.string.gbs_skonto_section_discount_title),
style = GiniTheme.typography.subtitle1,
color = colors.titleTextColor,
)
Box {
androidx.compose.animation.AnimatedVisibility(visible = isActive) {
Row(
modifier = Modifier.weight(1f, fill = false),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier.weight(0.1f, fill = false),
text = stringResource(id = R.string.gbs_skonto_section_discount_title),
style = GiniTheme.typography.subtitle1,
color = colors.titleTextColor,
)

AnimatedVisibility(
modifier = Modifier.requiredWidth(IntrinsicSize.Max),
visible = isActive
) {
Text(
text = stringResource(id = R.string.gbs_skonto_section_discount_hint_label_enabled),
style = GiniTheme.typography.subtitle2,
color = colors.enabledHintTextColor,
softWrap = false,
)
}
}

Spacer(Modifier.weight(1f))


GiniSwitch(
modifier = Modifier.padding(start = 8.dp),
checked = isActive,
onCheckedChange = onActiveChange,
)
Expand Down Expand Up @@ -794,14 +805,17 @@ private fun WithoutSkontoSection(
verticalAlignment = Alignment.CenterVertically,
) {
Text(
modifier = Modifier.weight(0.1f, fill = false),
text = stringResource(id = R.string.gbs_skonto_section_without_discount_title),
style = GiniTheme.typography.subtitle1,
color = colors.titleTextColor,
)
AnimatedVisibility(visible = isActive) {
AnimatedVisibility(
modifier = Modifier.requiredWidth(IntrinsicSize.Max),
visible = isActive
) {
Text(
text = stringResource(id = R.string.gbs_skonto_section_discount_hint_label_enabled),
modifier = Modifier.weight(0.1f),
style = GiniTheme.typography.subtitle2,
color = colors.enabledHintTextColor,
)
Expand Down Expand Up @@ -993,17 +1007,12 @@ private fun FooterSection(
}

@Composable
@Preview
@GiniScreenPreviewUiModes
@GiniScreenPreviewSizes
private fun ScreenReadyStatePreviewLight() {
ScreenReadyStatePreview()
}

@Composable
@Preview(uiMode = UI_MODE_NIGHT_YES)
private fun ScreenReadyStatePreviewDark() {
ScreenReadyStatePreview()
}

@Composable
private fun ScreenReadyStatePreview() {
GiniTheme {
Expand Down Expand Up @@ -1047,7 +1056,7 @@ private fun previewState() = SkontoScreenState.Ready(
edgeCase = SkontoEdgeCase.PayByCashOnly,
edgeCaseInfoDialogVisible = false,
savedAmount = Amount.parse("3:EUR"),
transactionDialogVisible = true,
transactionDialogVisible = false,
skontoAmountValidationError = null,
fullAmountValidationError = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.gini.android.capture.ui.compose

import android.content.res.Configuration
import androidx.compose.ui.tooling.preview.Preview

@Preview(
name = "Font Scale 200%",
group = "FontScale",
fontScale = 2f,
showBackground = true,
)
@Preview(
name = "Font Scale 100%",
group = "FontScale",
fontScale = 1f,
showBackground = true,
)
/**
* This annotation is used to preview the screen in different sizes (100% and 200% font scale)
* It can be combined with [GiniScreenPreviewUiModes]
*
* @see GiniScreenPreviewUiModes
*/
annotation class GiniScreenPreviewSizes

@Preview(
name = "Dark",
group = "UiMode",
uiMode = Configuration.UI_MODE_NIGHT_YES,
showBackground = true,
)
@Preview(
name = "Light",
group = "UiMode",
uiMode = Configuration.UI_MODE_NIGHT_NO,
showBackground = true,
)
/**
* This annotation is used to preview the screen in different UI modes (Light and Dark)
* It can be combined with [GiniScreenPreviewSizes]
*
* @see GiniScreenPreviewSizes
*/
annotation class GiniScreenPreviewUiModes
2 changes: 1 addition & 1 deletion config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ style:
UnusedPrivateMember:
active: true
allowedNames: ''
ignoreAnnotated: [ 'Preview' ]
ignoreAnnotated: [ '*Preview*' ]
UnusedPrivateProperty:
active: true
allowedNames: '_|ignored|expected|serialVersionUID'
Expand Down
Loading