Skip to content
Merged
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
36 changes: 20 additions & 16 deletions app/src/main/java/com/getcode/view/main/home/DecorView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.getcode.view.main.home

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
Expand All @@ -26,8 +27,12 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -81,31 +86,30 @@ internal fun DecorView(
)

Column(modifier = Modifier.align(Alignment.BottomCenter)) {
//Balance Changed Toast
AnimatedContent(
AnimatedVisibility(
modifier = Modifier
.align(Alignment.End)
.padding(end = CodeTheme.dimens.grid.x5, bottom = CodeTheme.dimens.grid.x3),
targetState = dataState.billState.toast,
transitionSpec = {
slideInVertically(animationSpec = tween(600), initialOffsetY = { it }) +
fadeIn(animationSpec = tween(500, 100)) togetherWith if (!isPaused)
slideOutVertically(animationSpec = tween(600), targetOffsetY = { it }) +
fadeOut(animationSpec = tween(500, 100))
else fadeOut(animationSpec = tween(0))
},
label = "toast",
) { toast ->
if (toast != null) {
Timber.d("toast=$toast")
}
visible = dataState.billState.showToast,
enter = slideInVertically(animationSpec = tween(600), initialOffsetY = { it }) +
fadeIn(animationSpec = tween(500, 100)),
exit = if (!isPaused)
slideOutVertically(animationSpec = tween(600), targetOffsetY = { it }) +
fadeOut(animationSpec = tween(500, 100))
else fadeOut(animationSpec = tween(0)),
) {
Row(
modifier = Modifier
.wrapContentSize()
.clip(CodeTheme.shapes.xxl)
.background(Black50)
.padding(horizontal = CodeTheme.dimens.grid.x2, vertical = CodeTheme.dimens.grid.x1),
.padding(
horizontal = CodeTheme.dimens.grid.x2,
vertical = CodeTheme.dimens.grid.x1
),
) {
val toast by
remember(dataState.billState.toast) { derivedStateOf { dataState.billState.toast } }
Text(
text = toast?.formattedAmount.orEmpty(),
style = CodeTheme.typography.body2.copy(
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/getcode/view/main/home/HomeScan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ private fun HomeScan(

Lifecycle.Event.ON_PAUSE -> {
isPaused = true
homeViewModel.startSheetDismissTimer { navigator.hide() }
homeViewModel.startSheetDismissTimer {
Timber.d("hiding from timeout")
navigator.hide() }
}

Lifecycle.Event.ON_RESUME -> {
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/com/getcode/view/main/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import java.util.concurrent.TimeUnit
import javax.inject.Inject
import kotlin.concurrent.schedule
import kotlin.concurrent.timerTask
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

sealed interface PresentationStyle {
Expand Down Expand Up @@ -213,7 +214,6 @@ class HomeViewModel @Inject constructor(
}

if (bill.didReceive) {
delay(300)
withContext(Dispatchers.Main) {
uiFlow.update {
val billState = it.billState
Expand Down Expand Up @@ -349,11 +349,22 @@ class HomeViewModel @Inject constructor(
val billState = uiModel.billState
uiModel.copy(
billState = billState.copy(
toast = null,
showToast = false
)
)
}
// wait for animation to run
Timer().schedule(500.milliseconds.inWholeMilliseconds) {
uiFlow.update {
uiModel ->
val billState = uiModel.billState
uiModel.copy(
billState = billState.copy(
toast = null
)
)
}
}
}
}

Expand Down