diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubCardState.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubCardState.kt index fa1783068cd..57361a584ac 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubCardState.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubCardState.kt @@ -85,9 +85,23 @@ sealed class AnalyticsHubCustomSelectionListViewState : AnalyticsCardViewState { } } - data class HiddenState( - override val card: AnalyticsCards - ) : AnalyticsHubCustomSelectionListViewState() + data class ShowCTAState( + override val card: AnalyticsCards, + val title: String, + val description: String, + val callToActionText: String, + val isVisible: Boolean, + val onCallToActionClickListener: () -> Unit + ) : AnalyticsHubCustomSelectionListViewState() { + val asAnalyticsHubUserCallToActionViewState + get() = AnalyticsHubUserCallToActionViewState( + title = title, + description = description, + callToActionText = callToActionText, + isVisible = isVisible, + onCallToActionClickListener = onCallToActionClickListener + ) + } } data class AnalyticsHubUserCallToActionViewState( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubFragment.kt index 46cda4682fb..b5d8451394c 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubFragment.kt @@ -162,7 +162,6 @@ class AnalyticsHubFragment : BaseFragment(R.layout.fragment_analytics) { binding.analyticsDateSelectorCard.updatePreviousRange(viewState.analyticsDateRangeSelectorState.previousRange) binding.analyticsDateSelectorCard.updateCurrentRange(viewState.analyticsDateRangeSelectorState.currentRange) binding.analyticsDateSelectorCard.updateLastUpdateTimestamp(viewState.lastUpdateTimestamp) - binding.analyticsCallToActionCard.updateInformation(viewState.ctaState) binding.analyticsRefreshLayout.isRefreshing = viewState.refreshIndicator == ShowIndicator displayFeedbackBanner(viewState.showFeedBackBanner) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubViewModel.kt index b64f354a36a..c905effc0bf 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubViewModel.kt @@ -28,8 +28,8 @@ import com.woocommerce.android.model.SessionStat import com.woocommerce.android.model.StatType import com.woocommerce.android.tools.SelectedSite import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.CustomListViewState -import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.HiddenState import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.LoadingAdsViewState +import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.ShowCTAState import com.woocommerce.android.ui.analytics.hub.AnalyticsHubInformationViewState.DataViewState import com.woocommerce.android.ui.analytics.hub.AnalyticsHubInformationViewState.LoadingViewState import com.woocommerce.android.ui.analytics.hub.AnalyticsHubInformationViewState.NoDataState @@ -118,7 +118,6 @@ class AnalyticsHubViewModel @Inject constructor( refreshIndicator = NotShowIndicator, analyticsDateRangeSelectorState = AnalyticsHubDateRangeSelectorViewState.EMPTY, cards = AnalyticsHubCardViewState.LoadingCardsConfiguration, - ctaState = AnalyticsHubUserCallToActionViewState.EMPTY, showFeedBackBanner = false, lastUpdateTimestamp = "" ) @@ -486,16 +485,19 @@ class AnalyticsHubViewModel @Inject constructor( private fun observeGoogleAdsChanges() { googleAdsObservationJob = updateStats.googleAdsState.onEach { state -> - updateGoogleAdsCTAVisibility(isVisible = false) - when (state) { is GoogleAdsState.Available -> { updateCardStatus(AnalyticsCards.GoogleAds, buildGoogleAdsDataViewState(state.googleAdsStat)) } is GoogleAdsState.Empty -> { - updateGoogleAdsCTAVisibility(isVisible = true) - updateCardStatus(AnalyticsCards.GoogleAds, HiddenState(AnalyticsCards.GoogleAds)) + tracker.track( + stat = AnalyticsEvent.GOOGLEADS_ENTRY_POINT_DISPLAYED, + properties = mapOf( + KEY_GOOGLEADS_SOURCE to VALUE_GOOGLEADS_ENTRY_POINT_TYPE_ANALYTICS_HUB + ) + ) + updateCardStatus(AnalyticsCards.GoogleAds, buildGoogleAdsCTAViewState()) } is GoogleAdsState.Error -> { @@ -742,6 +744,17 @@ class AnalyticsHubViewModel @Inject constructor( ) } + private fun buildGoogleAdsCTAViewState(): ShowCTAState { + return ShowCTAState( + card = AnalyticsCards.GoogleAds, + title = resourceProvider.getString(R.string.analytics_google_ads_cta_title), + description = resourceProvider.getString(R.string.analytics_google_ads_cta_description), + callToActionText = resourceProvider.getString(R.string.analytics_google_ads_cta_action), + isVisible = true, + onCallToActionClickListener = { onGoogleAdsCTAClicked() } + ) + } + private fun onGoogleCampaignFilterSelected( googleAdsStats: GoogleAdsStat, selectedFilterName: String @@ -823,27 +836,6 @@ class AnalyticsHubViewModel @Inject constructor( giftCardsObservationJob?.cancel() } - private fun updateGoogleAdsCTAVisibility(isVisible: Boolean) { - AnalyticsHubUserCallToActionViewState( - title = resourceProvider.getString(R.string.analytics_google_ads_cta_title), - description = resourceProvider.getString(R.string.analytics_google_ads_cta_description), - callToActionText = resourceProvider.getString(R.string.analytics_google_ads_cta_action), - isVisible = isVisible, - onCallToActionClickListener = { onGoogleAdsCTAClicked() } - ).let { newState -> - mutableState.update { it.copy(ctaState = newState) } - } - - if (isVisible) { - tracker.track( - stat = AnalyticsEvent.GOOGLEADS_ENTRY_POINT_DISPLAYED, - properties = mapOf( - KEY_GOOGLEADS_SOURCE to VALUE_GOOGLEADS_ENTRY_POINT_TYPE_ANALYTICS_HUB - ) - ) - } - } - private fun onGoogleAdsCTAClicked() { selectedSite.getOrNull()?.let { it.adminUrlOrDefault + GOOGLE_ADMIN_CAMPAIGN_CREATION_SUFFIX diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubViewState.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubViewState.kt index 3a48da178c5..6c42bc19c4f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubViewState.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/AnalyticsHubViewState.kt @@ -7,7 +7,6 @@ data class AnalyticsViewState( val refreshIndicator: RefreshIndicator, val analyticsDateRangeSelectorState: AnalyticsHubDateRangeSelectorViewState, val cards: AnalyticsHubCardViewState, - val ctaState: AnalyticsHubUserCallToActionViewState, val showFeedBackBanner: Boolean, val lastUpdateTimestamp: String ) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/customlistcard/AnalyticsHubCustomSelectionCardView.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/customlistcard/AnalyticsHubCustomSelectionCardView.kt index e563419f94c..e3a7786f695 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/customlistcard/AnalyticsHubCustomSelectionCardView.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/analytics/hub/customlistcard/AnalyticsHubCustomSelectionCardView.kt @@ -13,9 +13,9 @@ import com.woocommerce.android.R import com.woocommerce.android.databinding.AnalyticsCustomSelectionCardViewBinding import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.CustomListViewState -import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.HiddenState import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.LoadingAdsViewState import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.NoAdsState +import com.woocommerce.android.ui.analytics.hub.AnalyticsHubCustomSelectionListViewState.ShowCTAState import com.woocommerce.android.ui.analytics.hub.informationcard.SeeReportClickListener import com.woocommerce.android.ui.analytics.hub.listcard.AnalyticsHubListAdapter import com.woocommerce.android.ui.analytics.hub.listcard.AnalyticsHubListCardView @@ -37,13 +37,15 @@ class AnalyticsHubCustomSelectionCardView @JvmOverloads constructor( is LoadingAdsViewState -> setSkeleton() is NoAdsState -> setNoAdsViewState(viewState) is CustomListViewState -> setDataViewState(viewState) - is HiddenState -> setHiddenState() + is ShowCTAState -> setCtaState(viewState) } } - private fun setHiddenState() { + private fun setCtaState(state: ShowCTAState) { skeletonView.hide() binding.analyticsCustomCardListContainer.visibility = GONE + binding.analyticsCallToActionCard.visibility = VISIBLE + binding.analyticsCallToActionCard.updateInformation(state.asAnalyticsHubUserCallToActionViewState) } private fun setDataViewState(viewState: CustomListViewState) { @@ -78,6 +80,7 @@ class AnalyticsHubCustomSelectionCardView @JvmOverloads constructor( binding.analyticsListLeftHeader.visibility = VISIBLE binding.analyticsListRightHeader.visibility = VISIBLE binding.noDataText.visibility = GONE + binding.analyticsCallToActionCard.visibility = GONE viewState.reportUrl?.let { binding.reportGroup.visibility = VISIBLE @@ -121,6 +124,7 @@ class AnalyticsHubCustomSelectionCardView @JvmOverloads constructor( binding.analyticsListRightHeader.visibility = GONE binding.analyticsItemsTag.visibility = GONE binding.analyticsFilterButton.visibility = GONE + binding.analyticsCallToActionCard.visibility = GONE binding.noDataText.visibility = VISIBLE binding.noDataText.text = viewState.message } @@ -140,6 +144,7 @@ class AnalyticsHubCustomSelectionCardView @JvmOverloads constructor( binding.analyticsItemsTag.visibility = GONE binding.noDataText.visibility = GONE binding.analyticsFilterButton.visibility = GONE + binding.analyticsCallToActionCard.visibility = GONE } private fun getDeltaTagText(viewState: CustomListViewState) = diff --git a/WooCommerce/src/main/res/layout/analytics_call_to_action_view.xml b/WooCommerce/src/main/res/layout/analytics_call_to_action_view.xml index 09a5fbc704a..87c6bb01364 100644 --- a/WooCommerce/src/main/res/layout/analytics_call_to_action_view.xml +++ b/WooCommerce/src/main/res/layout/analytics_call_to_action_view.xml @@ -9,7 +9,7 @@ android:id="@+id/analyticsCallToActionCard" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_margin="@dimen/major_75" + android:layout_marginVertical="@dimen/major_75" android:orientation="vertical"> + + - - + app:layout_constraintTop_toBottomOf="@+id/analyticsDateSelectorCard" />