@@ -37,6 +37,7 @@ import kotlinx.coroutines.delay
3737import kotlinx.coroutines.flow.MutableSharedFlow
3838import kotlinx.coroutines.flow.MutableStateFlow
3939import kotlinx.coroutines.flow.SharingStarted
40+ import kotlinx.coroutines.flow.StateFlow
4041import kotlinx.coroutines.flow.asSharedFlow
4142import kotlinx.coroutines.flow.asStateFlow
4243import kotlinx.coroutines.flow.first
@@ -96,6 +97,7 @@ import to.bitkit.repositories.WalletRepo
9697import to.bitkit.services.AppUpdaterService
9798import to.bitkit.ui.Routes
9899import to.bitkit.ui.components.Sheet
100+ import to.bitkit.ui.shared.toast.ToastQueueManager
99101import to.bitkit.ui.components.TimedSheetType
100102import to.bitkit.ui.shared.toast.ToastEventBus
101103import to.bitkit.ui.sheets.SendRoute
@@ -1518,8 +1520,8 @@ class AppViewModel @Inject constructor(
15181520 // endregion
15191521
15201522 // region Toasts
1521- var currentToast by mutableStateOf< Toast ?>( null )
1522- private set
1523+ private val toastManager = ToastQueueManager (viewModelScope )
1524+ val currentToast : StateFlow < Toast ?> = toastManager.currentToast
15231525
15241526 fun toast (
15251527 type : Toast .ToastType ,
@@ -1529,20 +1531,16 @@ class AppViewModel @Inject constructor(
15291531 visibilityTime : Long = Toast .VISIBILITY_TIME_DEFAULT ,
15301532 testTag : String? = null,
15311533 ) {
1532- currentToast = Toast (
1533- type = type,
1534- title = title,
1535- description = description,
1536- autoHide = autoHide,
1537- visibilityTime = visibilityTime,
1538- testTag = testTag,
1534+ toastManager.enqueue(
1535+ Toast (
1536+ type = type,
1537+ title = title,
1538+ description = description,
1539+ autoHide = autoHide,
1540+ visibilityTime = visibilityTime,
1541+ testTag = testTag,
1542+ )
15391543 )
1540- if (autoHide) {
1541- viewModelScope.launch {
1542- delay(visibilityTime)
1543- currentToast = null
1544- }
1545- }
15461544 }
15471545
15481546 fun toast (error : Throwable ) {
@@ -1560,7 +1558,19 @@ class AppViewModel @Inject constructor(
15601558 }
15611559
15621560 fun hideToast () {
1563- currentToast = null
1561+ toastManager.dismissCurrentToast()
1562+ }
1563+
1564+ fun pauseToast () {
1565+ toastManager.pauseCurrentToast()
1566+ }
1567+
1568+ fun resumeToast () {
1569+ toastManager.resumeCurrentToast()
1570+ }
1571+
1572+ fun clearToastQueue () {
1573+ toastManager.clear()
15641574 }
15651575 // endregion
15661576
0 commit comments