From 7c02ba5f27af4232b1bf4019b19bce5d38dc8d52 Mon Sep 17 00:00:00 2001 From: Ravi Date: Wed, 28 Feb 2024 19:28:03 +1100 Subject: [PATCH] Update StatsViewModel.kt handle deeplink granularity --- .../android/ui/stats/refresh/StatsViewModel.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 4c4fa6cfd0b3..b4489367b2f4 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 @@ -140,7 +140,20 @@ class StatsViewModel } private fun getInitialTimeFrame(intent: Intent): StatsSection? { - return when (intent.getSerializableExtraCompat(StatsActivity.ARG_DESIRED_TIMEFRAME)) { + val timeframe = intent.getSerializableExtraCompat(StatsActivity.ARG_DESIRED_TIMEFRAME) + if (statsTrafficTabFeatureConfig.isEnabled()) { + if (timeframe == DAY || timeframe == WEEK || timeframe == MONTH || timeframe == YEAR) { + when (timeframe) { + DAY -> selectedTrafficGranularityManager.setSelectedTrafficGranularity(StatsGranularity.DAYS) + WEEK -> selectedTrafficGranularityManager.setSelectedTrafficGranularity(StatsGranularity.WEEKS) + MONTH -> selectedTrafficGranularityManager.setSelectedTrafficGranularity(StatsGranularity.MONTHS) + YEAR -> selectedTrafficGranularityManager.setSelectedTrafficGranularity(StatsGranularity.YEARS) + else -> { /* Do nothing */} + } + } + } + + return when (timeframe) { StatsTimeframe.INSIGHTS -> StatsSection.INSIGHTS DAY -> StatsSection.DAYS WEEK -> StatsSection.WEEKS