From b084554ed730dcd2b90aa863dce2c9cdc7ae9dd1 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 28 Feb 2024 22:05:19 +0300 Subject: [PATCH 1/7] Pass granularity param to StatsListFragment from widgets --- .../android/ui/stats/refresh/StatsActivity.kt | 1 + .../android/ui/stats/refresh/StatsViewModel.kt | 17 ++++++++++++++--- .../ui/stats/refresh/lists/StatsListFragment.kt | 8 ++++++++ .../stats/refresh/lists/StatsListViewModel.kt | 2 +- .../refresh/lists/widget/utils/WidgetUtils.kt | 5 ++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt index 9ee8db7113e6..c814de1dfacb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt @@ -63,6 +63,7 @@ class StatsActivity : LocaleAwareActivity() { const val INITIAL_SELECTED_PERIOD_KEY = "INITIAL_SELECTED_PERIOD_KEY" const val ARG_LAUNCHED_FROM = "ARG_LAUNCHED_FROM" const val ARG_DESIRED_TIMEFRAME = "ARG_DESIRED_TIMEFRAME" + const val ARG_GRANULARITY = "ARG_GRANULARITY" @JvmStatic @JvmOverloads diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt index 11d4567fc1d8..e9f12b643126 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt @@ -121,9 +121,18 @@ class StatsViewModel val launchedFrom = intent.getSerializableExtraCompat(StatsActivity.ARG_LAUNCHED_FROM) val initialTimeFrame = getInitialTimeFrame(intent) + val initialGranularity = intent.getSerializableExtraCompat(StatsActivity.ARG_GRANULARITY) val initialSelectedPeriod = intent.getStringExtra(StatsActivity.INITIAL_SELECTED_PERIOD_KEY) val notificationType = intent.getSerializableExtraCompat(ARG_NOTIFICATION_TYPE) - start(localSiteId, launchedFrom, initialTimeFrame, initialSelectedPeriod, restart, notificationType) + start( + localSiteId, + launchedFrom, + initialTimeFrame, + initialSelectedPeriod, + restart, + notificationType, + initialGranularity + ) } fun onSaveInstanceState(outState: Bundle) { @@ -158,7 +167,8 @@ class StatsViewModel initialSection: StatsSection?, initialSelectedPeriod: String?, restart: Boolean, - notificationType: NotificationType? + notificationType: NotificationType?, + granularity: StatsGranularity? = null ) { if (restart) { selectedDateProvider.clear() @@ -173,10 +183,11 @@ class StatsViewModel ) initialSection?.let { statsSectionManager.setSelectedSection(it) } + granularity?.let { selectedTrafficGranularityManager.setSelectedTrafficGranularity(it) } updateSelectedSectionByTrafficTabFeatureConfig() trackSectionSelected(statsSectionManager.getSelectedSection()) - val initialGranularity = initialSection?.toStatsGranularity() + val initialGranularity = granularity ?: initialSection?.toStatsGranularity() if (initialGranularity != null && initialSelectedPeriod != null) { selectedDateProvider.setInitialSelectedPeriod(initialGranularity, initialSelectedPeriod) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index 913fde3dc9c6..cf21a97f9382 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -211,6 +211,14 @@ class StatsListFragment : ViewPagerFragment(R.layout.stats_list_fragment) { super.onResume() @Suppress("DEPRECATION") setHasOptionsMenu(statsSection == StatsSection.INSIGHTS) + + val viewModelGranularity = viewModel.dateSelector?.statsGranularity + val storedGranularity = selectedTrafficGranularityManager.getSelectedTrafficGranularity() + if (viewModelGranularity != storedGranularity) { + // Coming from widget + binding?.initializeViews(null) + (viewModel as? TrafficListViewModel)?.onGranularitySelected(storedGranularity) + } } override fun onDestroyView() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 0fffba4c2101..675271c3f0c1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -52,7 +52,7 @@ abstract class StatsListViewModel( defaultDispatcher: CoroutineDispatcher, protected var statsUseCase: BaseListUseCase, private val analyticsTracker: AnalyticsTrackerWrapper, - protected var dateSelector: StatsDateSelector?, + var dateSelector: StatsDateSelector?, popupMenuHandler: ItemPopupMenuHandler? = null, private val newsCardHandler: NewsCardHandler? = null, actionCardHandler: ActionCardHandler? = null diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/utils/WidgetUtils.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/utils/WidgetUtils.kt index e0610129a1ac..ae336e122ccc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/utils/WidgetUtils.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/utils/WidgetUtils.kt @@ -18,6 +18,7 @@ import org.wordpress.android.WordPress import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.stats.time.VisitsAndViewsModel import org.wordpress.android.fluxc.model.stats.time.VisitsAndViewsModel.PeriodData +import org.wordpress.android.fluxc.network.utils.StatsGranularity import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.stats.StatsTimeframe import org.wordpress.android.ui.stats.refresh.StatsActivity @@ -174,13 +175,15 @@ class WidgetUtils fun getPendingSelfIntent( context: Context, localSiteId: Int, - statsTimeframe: StatsTimeframe + statsTimeframe: StatsTimeframe, + granularity: StatsGranularity? = null ): PendingIntent { val intent = Intent(context, StatsActivity::class.java) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.putExtra(WordPress.LOCAL_SITE_ID, localSiteId) intent.putExtra(StatsActivity.ARG_DESIRED_TIMEFRAME, statsTimeframe) intent.putExtra(StatsActivity.ARG_LAUNCHED_FROM, StatsLaunchedFrom.WIDGET) + intent.putExtra(StatsActivity.ARG_GRANULARITY, granularity) return PendingIntent.getActivity( context, getRandomId(), From 79fdfe622e9dd9e7cd776343a9d599d593dab96b Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 28 Feb 2024 22:05:44 +0300 Subject: [PATCH 2/7] Open day granularity from minified widget --- .../refresh/lists/widget/minified/MinifiedWidgetUpdater.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/minified/MinifiedWidgetUpdater.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/minified/MinifiedWidgetUpdater.kt index ab29d0d10e70..66a38921d125 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/minified/MinifiedWidgetUpdater.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/minified/MinifiedWidgetUpdater.kt @@ -11,6 +11,7 @@ import kotlinx.coroutines.launch import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.network.utils.StatsGranularity import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.fluxc.store.stats.insights.TodayInsightsStore @@ -79,10 +80,11 @@ class MinifiedWidgetUpdater views.setViewVisibility(R.id.widget_retry_button, View.GONE) val timeframe = if (statsTrafficTabFeatureConfig.isEnabled()) TRAFFIC else INSIGHTS + val granularity = if (statsTrafficTabFeatureConfig.isEnabled()) StatsGranularity.DAYS else null views.setOnClickPendingIntent( R.id.widget_container, - widgetUtils.getPendingSelfIntent(context, siteModel.id, timeframe) + widgetUtils.getPendingSelfIntent(context, siteModel.id, timeframe, granularity) ) showValue(widgetManager, appWidgetId, views, siteModel, dataType, isWideView) } else { From 8147ecb7d3185a69928f1e9b51836ceda267c526 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 28 Feb 2024 22:05:53 +0300 Subject: [PATCH 3/7] Open day granularity from today widget --- .../ui/stats/refresh/lists/widget/today/TodayWidgetUpdater.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/TodayWidgetUpdater.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/TodayWidgetUpdater.kt index c9cf22b2391d..453f827eb925 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/TodayWidgetUpdater.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/TodayWidgetUpdater.kt @@ -7,6 +7,7 @@ import android.view.View import android.widget.RemoteViews import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker +import org.wordpress.android.fluxc.network.utils.StatsGranularity import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.ui.prefs.AppPrefsWrapper @@ -59,10 +60,11 @@ class TodayWidgetUpdater } else { StatsTimeframe.INSIGHTS } + val granularity = if (statsTrafficTabFeatureConfig.isEnabled()) StatsGranularity.DAYS else null siteModel.let { views.setOnClickPendingIntent( R.id.widget_title_container, - widgetUtils.getPendingSelfIntent(context, siteModel.id, timeframe) + widgetUtils.getPendingSelfIntent(context, siteModel.id, timeframe, granularity) ) } widgetUtils.showList( From 1ddb6a9ce098449ad6c1e7295b22fb11a26eac23 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 28 Feb 2024 22:06:04 +0300 Subject: [PATCH 4/7] Open week granularity from week views widget --- .../refresh/lists/widget/weeks/WeekViewsWidgetUpdater.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/WeekViewsWidgetUpdater.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/WeekViewsWidgetUpdater.kt index 1a02d247d899..72c5326644c7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/WeekViewsWidgetUpdater.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/WeekViewsWidgetUpdater.kt @@ -7,6 +7,7 @@ import android.view.View import android.widget.RemoteViews import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker +import org.wordpress.android.fluxc.network.utils.StatsGranularity import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.ui.prefs.AppPrefsWrapper @@ -53,12 +54,13 @@ class WeekViewsWidgetUpdater @Inject constructor( val hasAccessToken = accountStore.hasAccessToken() val widgetHasData = appPrefsWrapper.hasAppWidgetData(appWidgetId) val timeframe = if (statsTrafficTabFeatureConfig.isEnabled()) TRAFFIC else INSIGHTS + val granularity = if (statsTrafficTabFeatureConfig.isEnabled()) StatsGranularity.WEEKS else null if (networkAvailable && hasAccessToken && siteModel != null) { widgetUtils.setSiteIcon(siteModel, context, views, appWidgetId) siteModel.let { views.setOnClickPendingIntent( R.id.widget_title_container, - widgetUtils.getPendingSelfIntent(context, siteModel.id, timeframe) + widgetUtils.getPendingSelfIntent(context, siteModel.id, timeframe, granularity) ) } widgetUtils.showList( From f60289649be88a1a1251d03a015b50cae17fc72a Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 28 Feb 2024 22:56:12 +0300 Subject: [PATCH 5/7] Open week granularity from views widget --- .../ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt index 1b6138d480e0..f6cbb2d61c46 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt @@ -7,6 +7,7 @@ import android.view.View import android.widget.RemoteViews import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker +import org.wordpress.android.fluxc.network.utils.StatsGranularity import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.ui.prefs.AppPrefsWrapper @@ -53,7 +54,7 @@ class ViewsWidgetUpdater siteModel.let { views.setOnClickPendingIntent( R.id.widget_title_container, - widgetUtils.getPendingSelfIntent(context, siteModel.id, DAY) + widgetUtils.getPendingSelfIntent(context, siteModel.id, DAY, StatsGranularity.WEEKS) ) } widgetUtils.showList( From d0443c8ea044ab9fe68ec72ad966a8f3c4271e74 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 28 Feb 2024 23:14:32 +0300 Subject: [PATCH 6/7] Open day granularity from views widget --- .../ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt index f6cbb2d61c46..147f07ae8ac3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/ViewsWidgetUpdater.kt @@ -54,7 +54,7 @@ class ViewsWidgetUpdater siteModel.let { views.setOnClickPendingIntent( R.id.widget_title_container, - widgetUtils.getPendingSelfIntent(context, siteModel.id, DAY, StatsGranularity.WEEKS) + widgetUtils.getPendingSelfIntent(context, siteModel.id, DAY, StatsGranularity.DAYS) ) } widgetUtils.showList( From de5904e24733b157432e7edcfb7629baaaf34745 Mon Sep 17 00:00:00 2001 From: Ravi Date: Thu, 29 Feb 2024 14:21:38 +1100 Subject: [PATCH 7/7] Update StatsListFragment.kt Remove initializeViews every time --- .../android/ui/stats/refresh/lists/StatsListFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index cf21a97f9382..0387cc4ccbe9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -216,7 +216,6 @@ class StatsListFragment : ViewPagerFragment(R.layout.stats_list_fragment) { val storedGranularity = selectedTrafficGranularityManager.getSelectedTrafficGranularity() if (viewModelGranularity != storedGranularity) { // Coming from widget - binding?.initializeViews(null) (viewModel as? TrafficListViewModel)?.onGranularitySelected(storedGranularity) } }