Skip to content

Commit

Permalink
feature(bank-sdk): Skonto + RA. Code refactor
Browse files Browse the repository at this point in the history
PP-795
  • Loading branch information
ndubkov-distcotech committed Dec 2, 2024
1 parent d945049 commit 9ca03a9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bank-sdk/example-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:launchMode="singleTask">
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.widget.FrameLayout
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.focusable
Expand All @@ -19,8 +20,10 @@ 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.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
Expand Down Expand Up @@ -87,6 +90,7 @@ import net.gini.android.capture.ui.components.topbar.GiniTopBarColors
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
import net.gini.android.capture.util.compose.rememberImeState
import net.gini.android.capture.view.InjectedViewAdapterInstance
import org.orbitmvi.orbit.compose.collectAsState
import org.orbitmvi.orbit.compose.collectSideEffect
Expand Down Expand Up @@ -214,7 +218,16 @@ private fun ScreenReadyState(
screenColorScheme: SkontoScreenColors = SkontoScreenColors.colors(),
) {
val scrollState = rememberScrollState()
Scaffold(modifier = modifier,
val imeState = rememberImeState()


LaunchedEffect(key1 = imeState.value) {
if (imeState.value) {
scrollState.animateScrollTo(scrollState.maxValue, tween(300))
}
}

Scaffold(modifier = modifier.fillMaxSize().imePadding(),
containerColor = screenColorScheme.backgroundColor,
topBar = {
TopAppBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ internal class SkontoAmountValidator {
newSkontoAmount > fullAmount ->
SkontoScreenState.Ready.SkontoAmountValidationError.SkontoAmountMoreThanFullAmount

newSkontoAmount > BigDecimal.valueOf(SKONTO_AMOUNT_LIMIT) ->
newSkontoAmount > BigDecimal(SKONTO_AMOUNT_LIMIT) ->
SkontoScreenState.Ready.SkontoAmountValidationError.SkontoAmountLimitExceeded

else -> null
}

companion object {
internal const val SKONTO_AMOUNT_LIMIT = 99_999L
internal const val SKONTO_AMOUNT_LIMIT = "99999.99"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ internal class SkontoFullAmountValidator {
fullAmount: BigDecimal
): SkontoScreenState.Ready.FullAmountValidationError? = when {

fullAmount > BigDecimal.valueOf(SKONTO_AMOUNT_LIMIT) ->
fullAmount > BigDecimal(SKONTO_AMOUNT_LIMIT) ->
SkontoScreenState.Ready.FullAmountValidationError.FullAmountLimitExceeded

else -> null
}

companion object {
private const val SKONTO_AMOUNT_LIMIT = 99_999L
private const val SKONTO_AMOUNT_LIMIT = "99999.99"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.gini.android.capture.util.compose

import android.view.ViewTreeObserver
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalView
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

@Composable
fun rememberImeState(): State<Boolean> {
val imeState = remember { mutableStateOf(false) }

val view = LocalView.current
DisposableEffect(view) {
val listener = ViewTreeObserver.OnGlobalLayoutListener {
val isKeyboardOpen = ViewCompat.getRootWindowInsets(view)
?.isVisible(WindowInsetsCompat.Type.ime()) ?: true
imeState.value = isKeyboardOpen
}

view.viewTreeObserver.addOnGlobalLayoutListener(listener)
onDispose {
view.viewTreeObserver.removeOnGlobalLayoutListener(listener)
}
}
return imeState
}

0 comments on commit 9ca03a9

Please sign in to comment.