From 9fb68e032d9eae23ca6fd14b9baed9c98ae4bcd7 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Mon, 9 Sep 2024 12:27:32 +0530 Subject: [PATCH 01/12] Add class to detect network availability --- .../android/ui/woopos/util/WooPosNetworkStatus.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/util/WooPosNetworkStatus.kt diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/util/WooPosNetworkStatus.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/util/WooPosNetworkStatus.kt new file mode 100644 index 00000000000..092838dfa2d --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/util/WooPosNetworkStatus.kt @@ -0,0 +1,13 @@ +package com.woocommerce.android.ui.woopos.util + +import android.content.Context +import dagger.Reusable +import org.wordpress.android.util.NetworkUtils +import javax.inject.Inject + +@Reusable +class WooPosNetworkStatus @Inject constructor( + private val context: Context +) { + fun isConnected() = NetworkUtils.isNetworkAvailable(context) +} From 10695d701b0e6edc6a9bd8fceee8c992f358087e Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Mon, 9 Sep 2024 12:29:19 +0530 Subject: [PATCH 02/12] Add NoInternet event to communicate between children and parent --- .../ui/woopos/home/WooPosHomeChildToParentCommunication.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeChildToParentCommunication.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeChildToParentCommunication.kt index d7f3769eacc..105ba84ff87 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeChildToParentCommunication.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeChildToParentCommunication.kt @@ -29,6 +29,7 @@ sealed class ChildToParentEvent { data object FullScreen : ProductsStatusChanged() data object WithCart : ProductsStatusChanged() } + data object NoInternet : ChildToParentEvent() } interface WooPosChildrenToParentEventReceiver { From b98c2df7c5a3f8e704053d17167ea0934cc44f10 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Mon, 9 Sep 2024 12:29:53 +0530 Subject: [PATCH 03/12] Trigger NoInternet event if there's not internet when trying to connect to card reader. --- .../ui/woopos/home/toolbar/WooPosToolbarViewModel.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModel.kt index 88495a1ffcb..5f83dd9bc22 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModel.kt @@ -15,6 +15,7 @@ import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.OnCar import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.OnOutsideOfToolbarMenuClicked import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.OnToolbarMenuClicked import com.woocommerce.android.ui.woopos.support.WooPosGetSupportFacade +import com.woocommerce.android.ui.woopos.util.WooPosNetworkStatus import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -26,6 +27,7 @@ class WooPosToolbarViewModel @Inject constructor( private val cardReaderFacade: WooPosCardReaderFacade, private val childrenToParentEventSender: WooPosChildrenToParentEventSender, private val getSupportFacade: WooPosGetSupportFacade, + private val networkStatus: WooPosNetworkStatus, ) : ViewModel() { private val _state = MutableStateFlow( WooPosToolbarState( @@ -92,7 +94,15 @@ class WooPosToolbarViewModel @Inject constructor( cardReaderFacade.disconnectFromReader() } } - WooPosToolbarState.WooPosCardReaderStatus.NotConnected -> cardReaderFacade.connectToReader() + WooPosToolbarState.WooPosCardReaderStatus.NotConnected -> { + if (!networkStatus.isConnected()) { + viewModelScope.launch { + childrenToParentEventSender.sendToParent(ChildToParentEvent.NoInternet) + } + } else { + cardReaderFacade.connectToReader() + } + } } } From 41de09ac1324a92efb3248cab9dbcffce2634fbb Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Mon, 9 Sep 2024 12:31:32 +0530 Subject: [PATCH 04/12] Trigger shared flow event when there is no internet from home view model --- .../android/ui/woopos/home/WooPosHomeViewModel.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt index c1c52e8fb2b..4b99545d3d9 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt @@ -3,8 +3,11 @@ package com.woocommerce.android.ui.woopos.home import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.woocommerce.android.R import com.woocommerce.android.viewmodel.getStateFlow import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch import javax.inject.Inject @@ -21,11 +24,14 @@ class WooPosHomeViewModel @Inject constructor( initialValue = WooPosHomeState( screenPositionState = WooPosHomeState.ScreenPositionState.Cart.Visible, productsInfoDialog = WooPosHomeState.ProductsInfoDialog(isVisible = false), - exitConfirmationDialog = WooPosHomeState.ExitConfirmationDialog(isVisible = false) + exitConfirmationDialog = WooPosHomeState.ExitConfirmationDialog(isVisible = false), ) ) val state: StateFlow = _state + private val _toastEvent = MutableSharedFlow() + val toastEvent: SharedFlow = _toastEvent + init { listenBottomEvents() } @@ -119,6 +125,12 @@ class WooPosHomeViewModel @Inject constructor( productsInfoDialog = WooPosHomeState.ProductsInfoDialog(isVisible = true) ) } + + ChildToParentEvent.NoInternet -> { + viewModelScope.launch { + _toastEvent.emit(R.string.orderlist_connectivity_tool_internet_check_suggestion) + } + } } } } From 1842108993b91dacdce072cc7258ebc9684afc8f Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Mon, 9 Sep 2024 12:31:55 +0530 Subject: [PATCH 05/12] Use LaunchedEffect to display toast to user when there is no internet. --- .../android/ui/woopos/home/WooPosHomeScreen.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt index a5602df1b47..c7e002b796a 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt @@ -22,6 +22,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -41,6 +42,7 @@ import com.woocommerce.android.ui.woopos.home.toolbar.WooPosFloatingToolbar import com.woocommerce.android.ui.woopos.home.totals.WooPosTotalsScreen import com.woocommerce.android.ui.woopos.home.totals.WooPosTotalsScreenPreview import com.woocommerce.android.ui.woopos.root.navigation.WooPosNavigationEvent +import org.wordpress.android.util.ToastUtils @Composable fun WooPosHomeScreen( @@ -48,6 +50,12 @@ fun WooPosHomeScreen( ) { val viewModel: WooPosHomeViewModel = hiltViewModel() val state = viewModel.state.collectAsState().value + val context = LocalContext.current + LaunchedEffect(viewModel.toastEvent) { + viewModel.toastEvent.collect { message -> + ToastUtils.showToast(context, message) + } + } WooPosHomeScreen( state, From a997fdc4491827b4e67f24e7006435d282e5eff5 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Mon, 9 Sep 2024 12:32:59 +0530 Subject: [PATCH 06/12] Fix failing test class --- .../ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt index 04cfd05688e..f471b002709 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt @@ -7,6 +7,7 @@ import com.woocommerce.android.ui.woopos.home.ChildToParentEvent import com.woocommerce.android.ui.woopos.home.WooPosChildrenToParentEventSender import com.woocommerce.android.ui.woopos.support.WooPosGetSupportFacade import com.woocommerce.android.ui.woopos.util.WooPosCoroutineTestRule +import com.woocommerce.android.ui.woopos.util.WooPosNetworkStatus import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest @@ -27,6 +28,7 @@ class WooPosToolbarViewModelTest { } private val getSupportFacade: WooPosGetSupportFacade = mock() private val childrenToParentEventSender: WooPosChildrenToParentEventSender = mock() + private val networkStatus: WooPosNetworkStatus = mock() @Test fun `given card reader status is NotConnected, when initialized, then state should be NotConnected`() = runTest { @@ -177,5 +179,6 @@ class WooPosToolbarViewModelTest { cardReaderFacade, childrenToParentEventSender, getSupportFacade, + networkStatus ) } From 63dc317504e389dd5baa172fc3c99299a231dc1e Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Mon, 9 Sep 2024 12:37:51 +0530 Subject: [PATCH 07/12] Add test to verify that proper event is triggered when there's no internet while trying to connect card reader. --- .../toolbar/WooPosToolbarViewModelTest.kt | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt index f471b002709..200b0ac5cef 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt @@ -134,30 +134,32 @@ class WooPosToolbarViewModelTest { } @Test - fun `given card reader status is Connected, when OnCardReaderStatusClicked, then disconnect from reader should be called`() = runTest { - // GIVEN - whenever(cardReaderFacade.readerStatus).thenReturn(flowOf(CardReaderStatus.Connected(mock()))) - val viewModel = createViewModel() + fun `given card reader status is Connected, when OnCardReaderStatusClicked, then disconnect from reader should be called`() = + runTest { + // GIVEN + whenever(cardReaderFacade.readerStatus).thenReturn(flowOf(CardReaderStatus.Connected(mock()))) + val viewModel = createViewModel() - // WHEN - viewModel.onUiEvent(WooPosToolbarUIEvent.OnCardReaderStatusClicked) + // WHEN + viewModel.onUiEvent(WooPosToolbarUIEvent.OnCardReaderStatusClicked) - // THEN - verify(cardReaderFacade).disconnectFromReader() - } + // THEN + verify(cardReaderFacade).disconnectFromReader() + } @Test - fun `given card reader status is NotConnected, when OnCardReaderStatusClicked, then connect to reader should be called`() = runTest { - // GIVEN - whenever(cardReaderFacade.readerStatus).thenReturn(flowOf(CardReaderStatus.NotConnected())) - val viewModel = createViewModel() + fun `given card reader status is NotConnected, when OnCardReaderStatusClicked, then connect to reader should be called`() = + runTest { + // GIVEN + whenever(cardReaderFacade.readerStatus).thenReturn(flowOf(CardReaderStatus.NotConnected())) + val viewModel = createViewModel() - // WHEN - viewModel.onUiEvent(WooPosToolbarUIEvent.OnCardReaderStatusClicked) + // WHEN + viewModel.onUiEvent(WooPosToolbarUIEvent.OnCardReaderStatusClicked) - // THEN - verify(cardReaderFacade).connectToReader() - } + // THEN + verify(cardReaderFacade).connectToReader() + } @Test fun `when get support clicked, then should open support form`() { @@ -175,6 +177,17 @@ class WooPosToolbarViewModelTest { verify(getSupportFacade).openSupportForm() } + @Test + fun `given there is no internet, when trying to connect card reader, then trigger proper event`() = runTest { + whenever(networkStatus.isConnected()).thenReturn(false) + whenever(cardReaderFacade.readerStatus).thenReturn(flowOf(CardReaderStatus.NotConnected())) + + val viewModel = createViewModel() + viewModel.onUiEvent(WooPosToolbarUIEvent.OnCardReaderStatusClicked) + + verify(childrenToParentEventSender).sendToParent(ChildToParentEvent.NoInternet) + } + private fun createViewModel() = WooPosToolbarViewModel( cardReaderFacade, childrenToParentEventSender, From 3d6d61759926b6a138df848132546749dcda2202 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Mon, 9 Sep 2024 12:42:14 +0530 Subject: [PATCH 08/12] Add test to verify that connect to card reader is not called when there is no internet. --- .../toolbar/WooPosToolbarViewModelTest.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt index 200b0ac5cef..dee426e3e59 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/woopos/home/toolbar/WooPosToolbarViewModelTest.kt @@ -15,6 +15,7 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.Rule import org.junit.Test import org.mockito.kotlin.mock +import org.mockito.kotlin.never import org.mockito.kotlin.verify import org.mockito.kotlin.whenever @@ -107,6 +108,7 @@ class WooPosToolbarViewModelTest { fun `when ConnectToAReaderClicked passed, then connect to reader should be called`() = runTest { // GIVEN whenever(cardReaderFacade.readerStatus).thenReturn(flowOf(CardReaderStatus.NotConnected())) + whenever(networkStatus.isConnected()).thenReturn(true) val viewModel = createViewModel() // WHEN @@ -152,6 +154,7 @@ class WooPosToolbarViewModelTest { runTest { // GIVEN whenever(cardReaderFacade.readerStatus).thenReturn(flowOf(CardReaderStatus.NotConnected())) + whenever(networkStatus.isConnected()).thenReturn(true) val viewModel = createViewModel() // WHEN @@ -179,15 +182,32 @@ class WooPosToolbarViewModelTest { @Test fun `given there is no internet, when trying to connect card reader, then trigger proper event`() = runTest { + // GIVEN whenever(networkStatus.isConnected()).thenReturn(false) whenever(cardReaderFacade.readerStatus).thenReturn(flowOf(CardReaderStatus.NotConnected())) + // WHEN val viewModel = createViewModel() viewModel.onUiEvent(WooPosToolbarUIEvent.OnCardReaderStatusClicked) + // THEN verify(childrenToParentEventSender).sendToParent(ChildToParentEvent.NoInternet) } + @Test + fun `given there is no internet, when trying to connect card reader, then connect card reader method is not called`() = runTest { + // GIVEN + whenever(networkStatus.isConnected()).thenReturn(false) + whenever(cardReaderFacade.readerStatus).thenReturn(flowOf(CardReaderStatus.NotConnected())) + + // WHEN + val viewModel = createViewModel() + viewModel.onUiEvent(WooPosToolbarUIEvent.OnCardReaderStatusClicked) + + // THEN + verify(cardReaderFacade, never()).connectToReader() + } + private fun createViewModel() = WooPosToolbarViewModel( cardReaderFacade, childrenToParentEventSender, From 76396fbd28974c62ba4c6ba89f730ba00064b5b5 Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Tue, 10 Sep 2024 09:44:58 +0530 Subject: [PATCH 09/12] Add a dedicated string resource for POS --- WooCommerce/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index 0479c8c8623..0fb775de1dc 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -4251,6 +4251,7 @@ Toolbar with card reader status. Menu is open. Double tap to interact. Open toolbar menu Popup menu with options. Swipe to navigate through items. + It looks like you\'re not connected to the internet.\n\nEnsure your Wi-Fi is turned on. If you\'re using mobile data, make sure it\'s enabled in your device settings. Customer From 364c257fb0bd19d4cbd26db951b11f4d8302859c Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Tue, 10 Sep 2024 09:45:08 +0530 Subject: [PATCH 10/12] Use the new POS string resource --- .../woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt index 4b99545d3d9..fc6f4d52923 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt @@ -128,7 +128,7 @@ class WooPosHomeViewModel @Inject constructor( ChildToParentEvent.NoInternet -> { viewModelScope.launch { - _toastEvent.emit(R.string.orderlist_connectivity_tool_internet_check_suggestion) + _toastEvent.emit(R.string.woopos_no_internet_message) } } } From b72a65ff749e4fea4978d00e39ef10dd4bc7c15c Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Fri, 13 Sep 2024 11:05:10 +0530 Subject: [PATCH 11/12] Remove new line from the no internet string resource. --- WooCommerce/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index 30e0ca51c19..0c56e804e97 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -4252,7 +4252,7 @@ Toolbar with card reader status. Menu is open. Double tap to interact. Open toolbar menu Popup menu with options. Swipe to navigate through items. - It looks like you\'re not connected to the internet.\n\nEnsure your Wi-Fi is turned on. If you\'re using mobile data, make sure it\'s enabled in your device settings. + It looks like you\'re not connected to the internet. Ensure your Wi-Fi is turned on. If you\'re using mobile data, make sure it\'s enabled in your device settings. Customer From f49db88ad693dbfb5faafc447f49543da7239fda Mon Sep 17 00:00:00 2001 From: AnirudhBhat Date: Fri, 13 Sep 2024 11:05:30 +0530 Subject: [PATCH 12/12] Use data class to represent toast message. --- .../android/ui/woopos/home/WooPosHomeScreen.kt | 6 +++++- .../android/ui/woopos/home/WooPosHomeViewModel.kt | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt index fdf24930c04..3e3242edf37 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeScreen.kt @@ -53,7 +53,11 @@ fun WooPosHomeScreen( val context = LocalContext.current LaunchedEffect(viewModel.toastEvent) { viewModel.toastEvent.collect { message -> - ToastUtils.showToast(context, message) + ToastUtils.showToast( + context, + context.getString(message.message), + ToastUtils.Duration.LONG + ) } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt index fc6f4d52923..2e1f6c56054 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/home/WooPosHomeViewModel.kt @@ -1,5 +1,6 @@ package com.woocommerce.android.ui.woopos.home +import androidx.annotation.StringRes import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -29,8 +30,12 @@ class WooPosHomeViewModel @Inject constructor( ) val state: StateFlow = _state - private val _toastEvent = MutableSharedFlow() - val toastEvent: SharedFlow = _toastEvent + private val _toastEvent = MutableSharedFlow() + val toastEvent: SharedFlow = _toastEvent + + data class Toast( + @StringRes val message: Int, + ) init { listenBottomEvents() @@ -128,7 +133,7 @@ class WooPosHomeViewModel @Inject constructor( ChildToParentEvent.NoInternet -> { viewModelScope.launch { - _toastEvent.emit(R.string.woopos_no_internet_message) + _toastEvent.emit(Toast(R.string.woopos_no_internet_message)) } } }