Skip to content

Commit

Permalink
Merge pull request #20392 from wordpress-mobile/feature/make-traffic-…
Browse files Browse the repository at this point in the history
…tab-default

Make traffic tab default
  • Loading branch information
ravishanker authored Mar 3, 2024
2 parents 81cc154 + e604bec commit 9a9abce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import org.wordpress.android.fluxc.network.utils.StatsGranularity.WEEKS
import org.wordpress.android.fluxc.network.utils.StatsGranularity.YEARS
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.INSIGHTS
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.TRAFFIC
import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig
import javax.inject.Inject

const val SELECTED_SECTION_KEY = "SELECTED_STATS_SECTION_KEY"

class SelectedSectionManager
@Inject constructor(private val sharedPrefs: SharedPreferences) {
@Inject constructor(
private val sharedPrefs: SharedPreferences,
private val statsTrafficTabFeatureConfig: StatsTrafficTabFeatureConfig
) {
private val _liveSelectedSection = MutableLiveData<StatsSection>()
val liveSelectedSection: LiveData<StatsSection>
get() {
Expand All @@ -28,7 +33,8 @@ class SelectedSectionManager
}

fun getSelectedSection(): StatsSection {
val value = sharedPrefs.getString(SELECTED_SECTION_KEY, INSIGHTS.name)
val defaultValue = if (statsTrafficTabFeatureConfig.isEnabled()) TRAFFIC else INSIGHTS
val value = sharedPrefs.getString(SELECTED_SECTION_KEY, defaultValue.name)
return value?.let { StatsSection.valueOf(value) } ?: INSIGHTS
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ import org.mockito.kotlin.whenever
import org.wordpress.android.BaseUnitTest
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection
import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection.MONTHS
import org.wordpress.android.util.config.StatsTrafficTabFeatureConfig

@ExperimentalCoroutinesApi
class SelectedSectionManagerTest : BaseUnitTest() {
@Mock
private lateinit var trafficTabFeatureConfig: StatsTrafficTabFeatureConfig

@Mock
lateinit var sharedPreferences: SharedPreferences

Expand All @@ -25,7 +29,7 @@ class SelectedSectionManagerTest : BaseUnitTest() {

@Before
fun setUp() {
selectedSectionManager = SelectedSectionManager(sharedPreferences)
selectedSectionManager = SelectedSectionManager(sharedPreferences, trafficTabFeatureConfig)
whenever(sharedPreferences.edit()).thenReturn(sharedPreferencesEditor)
}

Expand Down

0 comments on commit 9a9abce

Please sign in to comment.