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 all 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 @@ -219,64 +218,46 @@ 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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.woocommerce.android.analytics.AnalyticsTracker.Companion.VALUE_FLOW_E
import com.woocommerce.android.analytics.AnalyticsTrackerWrapper
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 @@ -97,12 +96,8 @@ final class OrderDetailViewModel @Inject constructor(
private val paymentCollectibilityChecker: CardReaderPaymentCollectibilityChecker,
private val cardReaderTracker: CardReaderTracker,
private val trackerWrapper: AnalyticsTrackerWrapper,
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 @@ -139,12 +134,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 @@ -570,7 +559,7 @@ final class OrderDetailViewModel @Inject constructor(
}

private fun fetchSLCreationEligibilityAsync() = async {
if (isShippingPluginReady) {
if (shippingLabelOnboardingRepository.isShippingPluginReady) {
orderDetailRepository.fetchSLCreationEligibility(order.id)
}
}
Expand Down Expand Up @@ -641,7 +630,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 @@ -665,7 +654,10 @@ final class OrderDetailViewModel @Inject constructor(
isShipmentTrackingAvailable = shipmentTracking.isVisible,
isProductListVisible = orderProducts.isVisible,
areShippingLabelsVisible = shippingLabels.isVisible,
installWcShippingBanner = true
installWcShippingBannerVisible = shippingLabelOnboardingRepository.shouldShowWcShippingBanner(
order,
orderEligibleForInPersonPayments
)
)
}

Expand Down Expand Up @@ -706,7 +698,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,37 @@
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 =
!isShippingPluginReady &&
orderDetailRepository.getStoreCountryCode() == SUPPORTED_WCS_COUNTRY &&
order.currency == SUPPORTED_WCS_CURRENCY &&
!order.isCashPayment &&
!eligibleForIpp &&
!hasVirtualProductsOnly(order)

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