Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/6585 onboarding sl banner display logic #6620

Merged
merged 13 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.core.view.ViewCompat
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.hilt.navigation.fragment.hiltNavGraphViewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.transition.MaterialContainerTransform
Expand Down Expand Up @@ -67,6 +66,7 @@ import com.woocommerce.android.ui.orders.tracking.AddOrderShipmentTrackingFragme
import com.woocommerce.android.ui.refunds.RefundSummaryFragment
import com.woocommerce.android.util.CurrencyFormatter
import com.woocommerce.android.util.DateUtils
import com.woocommerce.android.util.FeatureFlag
import com.woocommerce.android.util.FeatureFlag.CARD_READER
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.ShowSnackbar
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.ShowUndoSnackbar
Expand Down Expand Up @@ -219,69 +219,51 @@ class OrderDetailFragment : BaseFragment(R.layout.fragment_order_detail), OrderP
binding.orderRefreshLayout.isRefreshing = it
}
new.refreshedProductId?.takeIfNotEqualTo(old?.refreshedProductId) { refreshProduct(it) }
new.installWcShippingBanner?.takeIfNotEqualTo(old?.installWcShippingBanner) {
new.installWcShippingBannerVisible?.takeIfNotEqualTo(old?.installWcShippingBannerVisible) {
showInstallWcShippingBanner(it)
}
}

viewModel.orderNotes.observe(
viewLifecycleOwner,
Observer {
showOrderNotes(it)
}
)
viewModel.orderRefunds.observe(
viewLifecycleOwner,
Observer {
showOrderRefunds(it, viewModel.order)
}
)
viewModel.productList.observe(
viewLifecycleOwner,
Observer {
showOrderProducts(it, viewModel.order.currency)
}
)
viewModel.shipmentTrackings.observe(
viewLifecycleOwner,
Observer {
showShipmentTrackings(it)
}
)
viewModel.shippingLabels.observe(
viewLifecycleOwner,
Observer {
showShippingLabels(it, viewModel.order.currency)
}
)
viewModel.orderNotes.observe(viewLifecycleOwner) {
showOrderNotes(it)
}
viewModel.orderRefunds.observe(viewLifecycleOwner) {
showOrderRefunds(it, viewModel.order)
}
viewModel.productList.observe(viewLifecycleOwner) {
showOrderProducts(it, viewModel.order.currency)
}
viewModel.shipmentTrackings.observe(viewLifecycleOwner) {
showShipmentTrackings(it)
}
viewModel.shippingLabels.observe(viewLifecycleOwner) {
showShippingLabels(it, viewModel.order.currency)
}
anitaa1990 marked this conversation as resolved.
Show resolved Hide resolved

viewModel.event.observe(
viewLifecycleOwner,
Observer { event ->
when (event) {
is ShowSnackbar -> {
if (event.args.isNotEmpty()) {
uiMessageResolver.getSnack(event.message, *event.args).show()
} else {
uiMessageResolver.showSnack(event.message)
}
}
is ShowUndoSnackbar -> {
displayUndoSnackbar(event.message, event.undoAction, event.dismissAction)
}
is OrderNavigationTarget -> navigator.navigate(this, event)
is TakePaymentViewModel.SharePaymentUrl -> {
sharePaymentUrl(event.storeName, event.paymentUrl)
viewModel.event.observe(viewLifecycleOwner) { event ->
when (event) {
is ShowSnackbar -> {
if (event.args.isNotEmpty()) {
uiMessageResolver.getSnack(event.message, *event.args).show()
} else {
uiMessageResolver.showSnack(event.message)
}
else -> event.isHandled = false
}
is ShowUndoSnackbar -> {
displayUndoSnackbar(event.message, event.undoAction, event.dismissAction)
}
is OrderNavigationTarget -> navigator.navigate(this, event)
is TakePaymentViewModel.SharePaymentUrl -> {
sharePaymentUrl(event.storeName, event.paymentUrl)
}
else -> event.isHandled = false
}
)
}
viewModel.start()
}

private fun showInstallWcShippingBanner(show: Boolean) {
binding.orderDetailInstallWcShippingBanner.isVisible = show
binding.orderDetailInstallWcShippingBanner.isVisible = show && FeatureFlag.WC_SHIPPING_BANNER.isEnabled()
}

private fun setupOrderEditingObservers(orderEditingViewModel: OrderEditingViewModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.VALUE_FLOW_EDITING
import com.woocommerce.android.annotations.OpenClassOnDebug
import com.woocommerce.android.extensions.isNotEqualTo
import com.woocommerce.android.extensions.semverCompareTo
import com.woocommerce.android.extensions.whenNotNullNorEmpty
import com.woocommerce.android.model.Order
import com.woocommerce.android.model.Order.OrderStatus
Expand Down Expand Up @@ -94,12 +93,8 @@ final class OrderDetailViewModel @Inject constructor(
private val productImageMap: ProductImageMap,
private val paymentCollectibilityChecker: CardReaderPaymentCollectibilityChecker,
private val cardReaderTracker: CardReaderTracker,
private val shippingLabelOnboardingRepository: ShippingLabelOnboardingRepository
) : ScopedViewModel(savedState), OnProductFetchedListener {
companion object {
// The required version to support shipping label creation
const val SUPPORTED_WCS_VERSION = "1.25.11"
}

private val navArgs: OrderDetailFragmentArgs by savedState.navArgs()

final var order: Order
Expand Down Expand Up @@ -136,12 +131,6 @@ final class OrderDetailViewModel @Inject constructor(
private val _shippingLabels = MutableLiveData<List<ShippingLabel>>()
val shippingLabels: LiveData<List<ShippingLabel>> = _shippingLabels

private val isShippingPluginReady: Boolean by lazy {
val pluginInfo = orderDetailRepository.getWooServicesPluginInfo()
pluginInfo.isInstalled && pluginInfo.isActive &&
(pluginInfo.version ?: "0.0.0").semverCompareTo(SUPPORTED_WCS_VERSION) >= 0
}

override fun onCleared() {
super.onCleared()
productImageMap.unsubscribeFromOnProductFetchedEvents(this)
Expand Down Expand Up @@ -560,7 +549,7 @@ final class OrderDetailViewModel @Inject constructor(
}

private fun fetchSLCreationEligibilityAsync() = async {
if (isShippingPluginReady) {
if (shippingLabelOnboardingRepository.isShippingPluginReady) {
orderDetailRepository.fetchSLCreationEligibility(order.id)
}
}
Expand Down Expand Up @@ -631,7 +620,7 @@ final class OrderDetailViewModel @Inject constructor(
val orderEligibleForInPersonPayments = viewState.orderInfo?.isPaymentCollectableWithCardReader == true &&
FeatureFlag.CARD_READER.isEnabled()

val isOrderEligibleForSLCreation = isShippingPluginReady &&
val isOrderEligibleForSLCreation = shippingLabelOnboardingRepository.isShippingPluginReady &&
orderDetailRepository.isOrderEligibleForSLCreation(order.id) &&
!orderEligibleForInPersonPayments

Expand All @@ -655,7 +644,10 @@ final class OrderDetailViewModel @Inject constructor(
isShipmentTrackingAvailable = shipmentTracking.isVisible,
isProductListVisible = orderProducts.isVisible,
areShippingLabelsVisible = shippingLabels.isVisible,
installWcShippingBanner = FeatureFlag.WC_SHIPPING_BANNER.isEnabled()
installWcShippingBannerVisible = shippingLabelOnboardingRepository.shouldShowWcShippingBanner(
order,
orderEligibleForInPersonPayments
)
)
}

Expand Down Expand Up @@ -696,7 +688,7 @@ final class OrderDetailViewModel @Inject constructor(
val areShippingLabelsVisible: Boolean? = null,
val isProductListMenuVisible: Boolean? = null,
val isSharePaymentLinkVisible: Boolean? = null,
val installWcShippingBanner: Boolean? = null
val installWcShippingBannerVisible: Boolean? = null
) : Parcelable {
val isMarkOrderCompleteButtonVisible: Boolean?
get() = if (orderStatus != null) orderStatus.statusKey == CoreOrderStatus.PROCESSING.value else null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.woocommerce.android.ui.orders.details

import com.woocommerce.android.extensions.semverCompareTo
import com.woocommerce.android.model.Order
import javax.inject.Inject

class ShippingLabelOnboardingRepository @Inject constructor(
private val orderDetailRepository: OrderDetailRepository
) {
companion object {
// The required version to support shipping label creation
const val SUPPORTED_WCS_VERSION = "1.25.11"
const val SUPPORTED_WCS_CURRENCY = "USD"
const val SUPPORTED_WCS_COUNTRY = "US"
}

val isShippingPluginReady: Boolean by lazy {
val pluginInfo = orderDetailRepository.getWooServicesPluginInfo()
pluginInfo.isInstalled && pluginInfo.isActive &&
(pluginInfo.version ?: "0.0.0").semverCompareTo(SUPPORTED_WCS_VERSION) >= 0
}

fun shouldShowWcShippingBanner(order: Order, eligibleForIpp: Boolean): Boolean {
return !isShippingPluginReady
&& orderDetailRepository.getStoreCountryCode() == SUPPORTED_WCS_COUNTRY
JorgeMucientes marked this conversation as resolved.
Show resolved Hide resolved
&& order.currency == SUPPORTED_WCS_CURRENCY
JorgeMucientes marked this conversation as resolved.
Show resolved Hide resolved
&& !order.isCashPayment
JorgeMucientes marked this conversation as resolved.
Show resolved Hide resolved
&& !eligibleForIpp
JorgeMucientes marked this conversation as resolved.
Show resolved Hide resolved
&& !hasVirtualProductsOnly(order)
JorgeMucientes marked this conversation as resolved.
Show resolved Hide resolved
}

private fun hasVirtualProductsOnly(order: Order): Boolean {
return if (order.items.isNotEmpty()) {
val remoteProductIds = order.getProductIds()
orderDetailRepository.hasVirtualProductsOnly(remoteProductIds)
} else false
}
}
Loading