diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt index f99a37f02e54..58cefaf0d3a6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt @@ -36,8 +36,6 @@ import org.wordpress.android.ui.mysite.MySiteUiState.PartialState import org.wordpress.android.ui.mysite.MySiteViewModel.State.NoSites import org.wordpress.android.ui.mysite.MySiteViewModel.State.SiteSelected import org.wordpress.android.ui.mysite.cards.DashboardCardsViewModelSlice -import org.wordpress.android.ui.mysite.cards.dashboard.CardsTracker -import org.wordpress.android.ui.mysite.cards.jetpackfeature.JetpackFeatureCardShownTracker import org.wordpress.android.ui.mysite.cards.quickstart.QuickStartRepository import org.wordpress.android.ui.mysite.cards.siteinfo.SiteInfoHeaderCardViewModelSlice import org.wordpress.android.ui.mysite.items.DashboardItemsViewModelSlice @@ -77,12 +75,10 @@ class MySiteViewModel @Inject constructor( private val quickStartUtilsWrapper: QuickStartUtilsWrapper, private val snackbarSequencer: SnackbarSequencer, private val landOnTheEditorFeatureConfig: LandOnTheEditorFeatureConfig, - private val cardsTracker: CardsTracker, private val buildConfigWrapper: BuildConfigWrapper, private val appPrefsWrapper: AppPrefsWrapper, private val quickStartTracker: QuickStartTracker, private val dispatcher: Dispatcher, - private val jetpackFeatureCardShownTracker: JetpackFeatureCardShownTracker, private val jetpackFeatureRemovalUtils: JetpackFeatureRemovalOverlayUtil, private val getShowJetpackFullPluginInstallOnboardingUseCase: GetShowJetpackFullPluginInstallOnboardingUseCase, private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper, @@ -259,7 +255,6 @@ class MySiteViewModel @Inject constructor( } fun onResume() { -// mySiteSourceManager.onResume(isSiteSelected) isSiteSelected = false checkAndShowJetpackFullPluginInstallOnboarding() checkAndShowQuickStartNotice() @@ -471,10 +466,6 @@ class MySiteViewModel @Inject constructor( } } - private fun onDashboardErrorRetry() { -// mySiteSourceManager.refresh() - } - fun onActionableEmptyViewVisible() { analyticsTrackerWrapper.track(Stat.MY_SITE_NO_SITES_VIEW_DISPLAYED) checkJetpackIndividualPluginOverlayShouldShow() @@ -497,19 +488,6 @@ class MySiteViewModel @Inject constructor( _onNavigation.postValue(Event(BloggingPromptCardNavigationAction.LearnMore)) } - private fun trackCardsAndItemsShownIfNeeded() { -// siteSelected.dashboardData.filterIsInstance() -// .forEach { jetpackFeatureCardShownTracker.trackShown(it.type) } -//// siteSelected.dashboardData.filterIsInstance() -//// .forEach { _ -> sotw2023NudgeCardViewModelSlice.trackShown() } - } - - private fun resetShownTrackers() { - cardsTracker.resetShown() - jetpackFeatureCardShownTracker.resetShown() - dashboardCardsViewModelSlice.resetShownTracker() -// sotw2023NudgeCardViewModelSlice.resetShown() - } // FluxC events @Subscribe(threadMode = MAIN) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/DashboardItemsViewModelSlice.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/DashboardItemsViewModelSlice.kt index 56052f778279..f7fbc451328e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/DashboardItemsViewModelSlice.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/DashboardItemsViewModelSlice.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.distinctUntilChanged import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Job import kotlinx.coroutines.cancel import kotlinx.coroutines.launch import org.wordpress.android.fluxc.model.SiteModel @@ -30,6 +31,8 @@ class DashboardItemsViewModelSlice @Inject constructor( ) { private lateinit var scope: CoroutineScope + private var trackingJob : Job? = null + fun initialize(scope: CoroutineScope) { this.scope = scope sotw2023NudgeCardViewModelSlice.initialize(scope) @@ -80,6 +83,7 @@ class DashboardItemsViewModelSlice @Inject constructor( else jetpackFeatureCard?.let { add(jetpackFeatureCard) } jetpackBadge?.let { add(jetpackBadge) } }.toList() + trackShown(dasbhboardSiteItems) return dasbhboardSiteItems } @@ -101,7 +105,26 @@ class DashboardItemsViewModelSlice @Inject constructor( sotw2023NudgeCardViewModelSlice.clearValue() } + fun resetShownTracker() { + trackingJob?.cancel() + sotw2023NudgeCardViewModelSlice.resetShown() + jetpackFeatureCardViewModelSlice.resetShown() + } + + fun trackShown(dasbhboardSiteItems: MutableList) = with(dasbhboardSiteItems) { + trackingJob?.cancel() + trackingJob = scope.launch { + filterIsInstance().forEach { + jetpackFeatureCardViewModelSlice.trackShown(it.type) + } + filterIsInstance().forEach { + sotw2023NudgeCardViewModelSlice.trackShown() + } + } + } + fun onCleared() { + trackingJob?.cancel() scope.cancel() } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/jetpackfeaturecard/JetpackFeatureCardViewModelSlice.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/jetpackfeaturecard/JetpackFeatureCardViewModelSlice.kt index 2f43653d7934..e654bff1c54a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/jetpackfeaturecard/JetpackFeatureCardViewModelSlice.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/items/jetpackfeaturecard/JetpackFeatureCardViewModelSlice.kt @@ -7,12 +7,14 @@ import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil import org.wordpress.android.ui.mysite.MySiteCardAndItem import org.wordpress.android.ui.mysite.SiteNavigationAction import org.wordpress.android.ui.mysite.cards.jetpackfeature.JetpackFeatureCardHelper +import org.wordpress.android.ui.mysite.cards.jetpackfeature.JetpackFeatureCardShownTracker import org.wordpress.android.ui.utils.ListItemInteraction import org.wordpress.android.viewmodel.Event import javax.inject.Inject class JetpackFeatureCardViewModelSlice @Inject constructor( private val jetpackFeatureCardHelper: JetpackFeatureCardHelper, + private val jetpackFeatureCardShownTracker: JetpackFeatureCardShownTracker ) { private val _onNavigation = MutableLiveData>() val onNavigation = _onNavigation @@ -74,5 +76,13 @@ class JetpackFeatureCardViewModelSlice @Inject constructor( fun clearValue() { _uiModel.postValue(null) } + + fun trackShown(itemType: MySiteCardAndItem.Type) { + jetpackFeatureCardShownTracker.trackShown(itemType) + } + + fun resetShown() { + jetpackFeatureCardShownTracker.resetShown() + } }