diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/support/help/HelpOrigin.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/support/help/HelpOrigin.kt index 506f8532014..fbe54286f0d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/support/help/HelpOrigin.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/support/help/HelpOrigin.kt @@ -32,7 +32,8 @@ enum class HelpOrigin(private val stringValue: String) { ORDERS_LIST("origin:orders-list"), BLAZE_CAMPAIGN_CREATION("origin:blaze-native-campaign-creation"), CONNECTIVITY_TOOL("origin:connectivity-tool"), - APPLICATION_PASSWORD_TUTORIAL("origin:application-password-tutorial"); + APPLICATION_PASSWORD_TUTORIAL("origin:application-password-tutorial"), + POS("origin:point-of-sale"); override fun toString(): String { return stringValue 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 cdd25daa5f2..ee20b33699c 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 @@ -14,6 +14,7 @@ import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.Conne import com.woocommerce.android.ui.woopos.home.toolbar.WooPosToolbarUIEvent.MenuItemClicked 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 dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Job import kotlinx.coroutines.delay @@ -26,6 +27,7 @@ import javax.inject.Inject class WooPosToolbarViewModel @Inject constructor( private val cardReaderFacade: WooPosCardReaderFacade, private val childrenToParentEventSender: WooPosChildrenToParentEventSender, + private val getSupportFacade: WooPosGetSupportFacade, ) : ViewModel() { private val _state = MutableStateFlow( WooPosToolbarState( @@ -75,7 +77,7 @@ class WooPosToolbarViewModel @Inject constructor( hideMenu() when (event.menuItem.title) { - R.string.woopos_get_support_title -> TODO() + R.string.woopos_get_support_title -> getSupportFacade.openSupportForm() R.string.woopos_exit_confirmation_title -> viewModelScope.launch { childrenToParentEventSender.sendToParent(ChildToParentEvent.ExitPosClicked) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt index 204e6d115a4..f3fc2f540f9 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/WooPosActivity.kt @@ -17,6 +17,7 @@ import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderFacade import com.woocommerce.android.ui.woopos.common.composeui.WooPosTheme +import com.woocommerce.android.ui.woopos.support.WooPosGetSupportFacade import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @@ -25,12 +26,16 @@ class WooPosActivity : AppCompatActivity() { @Inject lateinit var wooPosCardReaderFacade: WooPosCardReaderFacade + @Inject + lateinit var wooPosGetSupportFacade: WooPosGetSupportFacade + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) WindowCompat.setDecorFitsSystemWindows(window, false) requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE lifecycle.addObserver(wooPosCardReaderFacade) + lifecycle.addObserver(wooPosGetSupportFacade) setContent { WooPosTheme { diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt new file mode 100644 index 00000000000..7e6e641f479 --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/support/WooPosGetSupportFacade.kt @@ -0,0 +1,31 @@ +package com.woocommerce.android.ui.woopos.support + +import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner +import com.woocommerce.android.support.help.HelpOrigin +import com.woocommerce.android.support.requests.SupportRequestFormActivity +import dagger.hilt.android.scopes.ActivityRetainedScoped +import javax.inject.Inject + +@ActivityRetainedScoped +class WooPosGetSupportFacade @Inject constructor() : DefaultLifecycleObserver { + private var activity: AppCompatActivity? = null + + override fun onCreate(owner: LifecycleOwner) { + this.activity = owner as AppCompatActivity + } + + override fun onDestroy(owner: LifecycleOwner) { + this.activity = null + } + + fun openSupportForm() { + val intent = SupportRequestFormActivity.createIntent( + context = activity!!, + origin = HelpOrigin.POS, + extraTags = ArrayList() + ) + activity!!.startActivity(intent) + } +} 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 2942c4cbad9..26e947b1fa8 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 @@ -5,6 +5,7 @@ import com.woocommerce.android.cardreader.connection.CardReaderStatus import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderFacade 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 kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf @@ -26,6 +27,7 @@ class WooPosToolbarViewModelTest { private val cardReaderFacade: WooPosCardReaderFacade = mock { onBlocking { readerStatus }.thenReturn(flowOf(CardReaderStatus.NotConnected())) } + private val getSupportFacade: WooPosGetSupportFacade = mock() private val childrenToParentEventSender: WooPosChildrenToParentEventSender = mock() @Test @@ -165,8 +167,25 @@ class WooPosToolbarViewModelTest { verify(cardReaderFacade, times(3)).connectToReader() } + @Test + fun `when get support clicked, then should open support form`() { + val viewModel = createViewModel() + + viewModel.onUiEvent( + WooPosToolbarUIEvent.MenuItemClicked( + WooPosToolbarState.Menu.MenuItem( + title = R.string.woopos_get_support_title, + icon = R.drawable.woopos_ic_get_support, + ) + ) + ) + + verify(getSupportFacade).openSupportForm() + } + private fun createViewModel() = WooPosToolbarViewModel( cardReaderFacade, - childrenToParentEventSender + childrenToParentEventSender, + getSupportFacade, ) }