Skip to content

Commit

Permalink
Merge pull request #13270 from wordpress-mobile/issue/13268-introduce…
Browse files Browse the repository at this point in the history
…-feature-flag

Introduce activity log filters feature flag
  • Loading branch information
ashiagr authored Nov 10, 2020
2 parents a6c99bc + 7d690b2 commit 1797c18
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ android {
buildConfigField "boolean", "WP_STORIES_AVAILABLE", "true"
buildConfigField "boolean", "ANY_FILE_UPLOAD", "true"
buildConfigField "boolean", "CONSOLIDATED_MEDIA_PICKER", "false"
buildConfigField "boolean", "ACTIVITY_LOG_FILTERS", "false"
buildConfigField "boolean", "ENABLE_FEATURE_CONFIGURATION", "true"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.wordpress.android.WordPress
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.ui.ActivityLauncher
import org.wordpress.android.ui.posts.BasicFragmentDialog
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.util.NetworkUtils
import org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelper
import org.wordpress.android.util.helpers.SwipeToRefreshHelper
Expand All @@ -29,6 +30,7 @@ import javax.inject.Inject

class ActivityLogListFragment : Fragment() {
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject lateinit var uiHelpers: UiHelpers
private lateinit var viewModel: ActivityLogViewModel
private lateinit var swipeToRefreshHelper: SwipeToRefreshHelper

Expand Down Expand Up @@ -94,6 +96,10 @@ class ActivityLogListFragment : Fragment() {
refreshProgressBars(listStatus)
})

viewModel.dateRangePickerVisibility.observe(viewLifecycleOwner, Observer { visibility ->
uiHelpers.updateVisibility(date_range_picker, visibility)
})

viewModel.showItemDetail.observe(viewLifecycleOwner, Observer {
if (it is ActivityLogListItem.Event) {
ActivityLauncher.viewActivityLogDetailForResult(activity, viewModel.site, it.activityId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.wordpress.android.util.config

import org.wordpress.android.BuildConfig
import org.wordpress.android.annotation.FeatureInDevelopment
import javax.inject.Inject

/**
* Configuration of the Activity Log Filters feature.
*/
@FeatureInDevelopment
class ActivityLogFiltersFeatureConfig
@Inject constructor(appConfig: AppConfig) : FeatureConfig(
appConfig,
BuildConfig.ACTIVITY_LOG_FILTERS
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.wordpress.android.ui.activitylog.list.ActivityLogListItem.Footer
import org.wordpress.android.ui.activitylog.list.ActivityLogListItem.Header
import org.wordpress.android.ui.activitylog.list.ActivityLogListItem.Loading
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.config.ActivityLogFiltersFeatureConfig
import org.wordpress.android.viewmodel.ResourceProvider
import org.wordpress.android.viewmodel.ScopedViewModel
import org.wordpress.android.viewmodel.SingleLiveEvent
Expand All @@ -33,6 +34,7 @@ class ActivityLogViewModel @Inject constructor(
private val activityLogStore: ActivityLogStore,
private val rewindStatusService: RewindStatusService,
private val resourceProvider: ResourceProvider,
private val activityLogFiltersFeatureConfig: ActivityLogFiltersFeatureConfig,
@param:Named(UI_THREAD) private val uiDispatcher: CoroutineDispatcher
) : ScopedViewModel(uiDispatcher) {
enum class ActivityLogListStatus {
Expand All @@ -53,6 +55,10 @@ class ActivityLogViewModel @Inject constructor(
val eventListStatus: LiveData<ActivityLogListStatus>
get() = _eventListStatus

private val _dateRangePickerVisibility = MutableLiveData<Boolean>()
val dateRangePickerVisibility: LiveData<Boolean>
get() = _dateRangePickerVisibility

private val _showRewindDialog = SingleLiveEvent<ActivityLogListItem>()
val showRewindDialog: LiveData<ActivityLogListItem>
get() = _showRewindDialog
Expand Down Expand Up @@ -116,6 +122,8 @@ class ActivityLogViewModel @Inject constructor(
reloadEvents(done = true)
requestEventsUpdate(false)

_dateRangePickerVisibility.value = activityLogFiltersFeatureConfig.isEnabled()

isStarted = true
}

Expand Down
12 changes: 11 additions & 1 deletion WordPress/src/main/res/layout/activity_log_list_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.chip.Chip
android:id="@+id/date_range_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="Date Range - hardcoded"
tools:ignore="HardcodedText" />

<org.wordpress.android.ui.ActionableEmptyView
android:id="@+id/actionable_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/date_range_picker"
android:visibility="gone"
app:aevImage="@drawable/img_illustration_empty_results_216dp"
app:aevSubtitle="@string/activity_log_empty_subtitle"
Expand All @@ -18,7 +27,8 @@
<org.wordpress.android.util.widgets.CustomSwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_below="@id/date_range_picker">

<org.wordpress.android.ui.prefs.EmptyViewRecyclerView
android:id="@+id/log_list_view"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.wordpress.android.ui.activitylog.list.ActivityLogListItem.Event
import org.wordpress.android.ui.activitylog.list.ActivityLogListItem.Footer
import org.wordpress.android.ui.activitylog.list.ActivityLogListItem.Header
import org.wordpress.android.ui.activitylog.list.ActivityLogListItem.Loading
import org.wordpress.android.util.config.ActivityLogFiltersFeatureConfig
import org.wordpress.android.viewmodel.ResourceProvider
import org.wordpress.android.viewmodel.activitylog.ActivityLogViewModel.ActivityLogListStatus
import java.util.Calendar
Expand All @@ -48,6 +49,7 @@ class ActivityLogViewModelTest {
@Mock private lateinit var site: SiteModel
@Mock private lateinit var rewindStatusService: RewindStatusService
@Mock private lateinit var resourceProvider: ResourceProvider
@Mock private lateinit var activityLogFiltersFeatureConfig: ActivityLogFiltersFeatureConfig
private lateinit var fetchActivityLogCaptor: KArgumentCaptor<FetchActivityLogPayload>

private var events: MutableList<List<ActivityLogListItem>?> = mutableListOf()
Expand Down Expand Up @@ -96,7 +98,13 @@ class ActivityLogViewModelTest {

@Before
fun setUp() = runBlocking<Unit> {
viewModel = ActivityLogViewModel(store, rewindStatusService, resourceProvider, Dispatchers.Unconfined)
viewModel = ActivityLogViewModel(
store,
rewindStatusService,
resourceProvider,
activityLogFiltersFeatureConfig,
Dispatchers.Unconfined
)
viewModel.site = site
viewModel.events.observeForever { events.add(it) }
viewModel.eventListStatus.observeForever { eventListStatuses.add(it) }
Expand Down Expand Up @@ -318,6 +326,24 @@ class ActivityLogViewModelTest {
assertFetchEvents(true)
}

@Test
fun dateRangePickerIsNotVisibleWhenFiltersFeatureFlagIsDisabled() = runBlocking {
whenever(activityLogFiltersFeatureConfig.isEnabled()).thenReturn(false)

viewModel.start(site)

assertEquals(false, viewModel.dateRangePickerVisibility.value)
}

@Test
fun dateRangePickerIsVisibleWhenFiltersFeatureFlagIsEnabled() = runBlocking {
whenever(activityLogFiltersFeatureConfig.isEnabled()).thenReturn(true)

viewModel.start(site)

assertEquals(true, viewModel.dateRangePickerVisibility.value)
}

private suspend fun assertFetchEvents(canLoadMore: Boolean = false) {
verify(store).fetchActivities(fetchActivityLogCaptor.capture())

Expand Down

0 comments on commit 1797c18

Please sign in to comment.