@@ -115,6 +115,7 @@ import java.util.TimerTask
115115import java.util.concurrent.TimeUnit
116116import javax.inject.Inject
117117import kotlin.concurrent.schedule
118+ import kotlin.time.Duration
118119import kotlin.time.Duration.Companion.milliseconds
119120import kotlin.time.Duration.Companion.seconds
120121
@@ -212,7 +213,7 @@ class HomeViewModel @Inject constructor(
212213 } ? : Completable .complete()
213214 receiveWithinLimits.subscribe({}, {})
214215
215- showToast(amount = amount, isDeposit = true )
216+ showToast(amount = amount, isDeposit = true , initialDelay = 1 .seconds )
216217
217218 historyController.fetchChats()
218219 },
@@ -486,30 +487,34 @@ class HomeViewModel @Inject constructor(
486487
487488 private fun showToast (
488489 amount : KinAmount ,
489- isDeposit : Boolean = false
490+ isDeposit : Boolean = false,
491+ initialDelay : Duration = 500.milliseconds
490492 ) {
491- if (amount.kin.toKinTruncatingLong() == 0L ) {
492- uiFlow.update { uiModel ->
493- val billState = uiModel.billState
494- uiModel.copy(
495- billState = billState.copy(
496- toast = null
493+ viewModelScope.launch {
494+ delay(initialDelay)
495+ if (amount.kin.toKinTruncatingLong() == 0L ) {
496+ uiFlow.update { uiModel ->
497+ val billState = uiModel.billState
498+ uiModel.copy(
499+ billState = billState.copy(
500+ toast = null
501+ )
497502 )
498- )
503+ }
504+ return @launch
499505 }
500- return
501- }
502506
503- uiFlow.update {
504- it.copy(
505- billState = it.billState.copy(
506- showToast = true ,
507- toast = BillToast (amount = amount, isDeposit = isDeposit)
507+ uiFlow.update {
508+ it.copy(
509+ billState = it.billState.copy(
510+ showToast = true ,
511+ toast = BillToast (amount = amount, isDeposit = isDeposit)
512+ )
508513 )
509- )
510- }
514+ }
515+
516+ delay(5 .seconds)
511517
512- Timer ().schedule(5 .seconds.inWholeMilliseconds) {
513518 uiFlow.update { uiModel ->
514519 val billState = uiModel.billState
515520 uiModel.copy(
@@ -518,16 +523,16 @@ class HomeViewModel @Inject constructor(
518523 )
519524 )
520525 }
526+
521527 // wait for animation to run
522- Timer ().schedule(500 .milliseconds.inWholeMilliseconds) {
523- uiFlow.update { uiModel ->
524- val billState = uiModel.billState
525- uiModel.copy(
526- billState = billState.copy(
527- toast = null
528- )
528+ delay(500 .milliseconds)
529+ uiFlow.update { uiModel ->
530+ val billState = uiModel.billState
531+ uiModel.copy(
532+ billState = billState.copy(
533+ toast = null
529534 )
530- }
535+ )
531536 }
532537 }
533538 }
0 commit comments