AddToCartButton

AddToCartButton
AddToCartButton

AddToCartButton allows the users to add a product to their carts. AddToCartButton is included in form selection module, included by platform module. If you need to include this module, add it to your build.gradle:

implementation ("com.poqstudio:catalogue.formselection:$VERSION_NAME")

Usage

AddToCartButton
AddToCartButton

You can use it in the layout: In the layout:

<com.poqstudio.platform.view.formselection.addtocart.ui.PoqAddToCartButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:addToCartViewDTO="@{viewModel.addToCartViewDTO}" />

To handle UiAddToCartEvents success and error events, and UiNotifyMeEvents success, error and open legal information page events, inject MainAddToCartViewModel and UiAddToCartEventHandler into your Activity or Fragment and observe the appropriated SharedFlow:

mainAddToCartViewModel: MainAddToCartViewModel by context.poqViewModelActivity()
uiAddToCartEventHandler: UiAddToCartEventHandler by inject()
mainAddToCartViewModel.uiAddToCartEvents.launchAndCollectIn(context.getLifecycleOwner()) { uiAddToCartEvent ->
uiAddToCartEventHandler.handle(
uiAddToCartEvent = uiAddToCartEvent,
baseView = rootView,
goToWebView = { url -> navigator.goToWebView(url) }
)
}

If you need to select more forms when the user clicks on the AddToCartButton, you can observe MainAddToCartViewModel.formToSelectEvent LiveData with your logic to present a form picker:

mainAddToCartViewModel.formToSelectEvent.observeLiveData(context) {
//Your logic to present a form picker
}