From ba207742135f180fbc26fdc3a8a700b1199ee1c0 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 29 Dec 2023 18:35:32 -0300 Subject: [PATCH 1/8] Load site avatar in filter sheet or placeholder --- .../reader/subfilter/SubfilterPageFragment.kt | 7 ++++- .../adapters/SubfilterListAdapter.kt | 3 ++ .../subfilter/viewholders/SiteViewHolder.kt | 30 ++++++++++++++++++- .../main/res/layout/subfilter_list_item.xml | 19 ++++++++++-- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt index 0701c79e378a..814885670204 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt @@ -35,6 +35,7 @@ import org.wordpress.android.ui.stats.refresh.utils.StatsUtils import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.config.SeenUnseenWithCounterFeatureConfig import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.image.ImageManager import org.wordpress.android.widgets.WPTextView import java.lang.ref.WeakReference import javax.inject.Inject @@ -47,6 +48,9 @@ class SubfilterPageFragment : Fragment() { @Inject lateinit var uiHelpers: UiHelpers + @Inject + lateinit var imageManager: ImageManager + @Inject lateinit var seenUnseenWithCounterFeatureConfig: SeenUnseenWithCounterFeatureConfig @@ -89,7 +93,8 @@ class SubfilterPageFragment : Fragment() { recyclerView = view.findViewById(R.id.content_recycler_view) recyclerView.layoutManager = LinearLayoutManager(requireActivity()) - recyclerView.adapter = SubfilterListAdapter(uiHelpers, statsUtils, seenUnseenWithCounterFeatureConfig) + recyclerView.adapter = + SubfilterListAdapter(uiHelpers, statsUtils, imageManager, seenUnseenWithCounterFeatureConfig) emptyStateContainer = view.findViewById(R.id.empty_state_container) title = emptyStateContainer.findViewById(R.id.title) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/adapters/SubfilterListAdapter.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/adapters/SubfilterListAdapter.kt index 8e15b3570aac..dfebfbc11c96 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/adapters/SubfilterListAdapter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/adapters/SubfilterListAdapter.kt @@ -24,10 +24,12 @@ import org.wordpress.android.ui.reader.subfilter.viewholders.TagViewHolder import org.wordpress.android.ui.stats.refresh.utils.StatsUtils import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.config.SeenUnseenWithCounterFeatureConfig +import org.wordpress.android.util.image.ImageManager class SubfilterListAdapter( val uiHelpers: UiHelpers, val statsUtils: StatsUtils, + val imageManager: ImageManager, val seenUnseenWithCounterFeatureConfig: SeenUnseenWithCounterFeatureConfig ) : Adapter() { private var items: List = listOf() @@ -52,6 +54,7 @@ class SubfilterListAdapter( is SiteViewHolder -> holder.bind( item as Site, uiHelpers, + imageManager, statsUtils, seenUnseenWithCounterFeatureConfig.isEnabled() ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/viewholders/SiteViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/viewholders/SiteViewHolder.kt index 695f59d4a01a..e55426c38b83 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/viewholders/SiteViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/viewholders/SiteViewHolder.kt @@ -2,13 +2,18 @@ package org.wordpress.android.ui.reader.subfilter.viewholders import android.view.View import android.view.ViewGroup +import android.widget.ImageView import android.widget.TextView +import androidx.core.view.isVisible import org.wordpress.android.R +import org.wordpress.android.models.ReaderBlog import org.wordpress.android.ui.reader.subfilter.SubfilterListItem.Site import org.wordpress.android.ui.stats.refresh.utils.ONE_THOUSAND import org.wordpress.android.ui.stats.refresh.utils.StatsUtils import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.UrlUtils +import org.wordpress.android.util.image.ImageManager +import org.wordpress.android.util.image.ImageType class SiteViewHolder( parent: ViewGroup @@ -16,8 +21,15 @@ class SiteViewHolder( private val itemTitle = itemView.findViewById(R.id.item_title) private val itemUrl = itemView.findViewById(R.id.item_url) private val itemUnseenCount = itemView.findViewById(R.id.unseen_count) + private val itemAvatar = itemView.findViewById(R.id.item_avatar) - fun bind(site: Site, uiHelpers: UiHelpers, statsUtils: StatsUtils, showUnreadpostsCount: Boolean) { + fun bind( + site: Site, + uiHelpers: UiHelpers, + imageManager: ImageManager, + statsUtils: StatsUtils, + showUnreadpostsCount: Boolean + ) { super.bind(site, uiHelpers) this.itemTitle.text = uiHelpers.getTextOfUiString(parent.context, site.label) this.itemUrl.visibility = View.VISIBLE @@ -36,5 +48,21 @@ class SiteViewHolder( } else { this.itemUnseenCount.visibility = View.GONE } + + updateSiteAvatar(blog, imageManager) + } + + private fun updateSiteAvatar(blog: ReaderBlog, imageManager: ImageManager) { + itemAvatar.isVisible = true + if (blog.hasImageUrl()) { + imageManager.loadIntoCircle( + itemAvatar, + ImageType.BLAVATAR_CIRCULAR, + blog.imageUrl, + ) + } else { + imageManager.cancelRequestAndClearImageView(itemAvatar) + itemAvatar.setImageResource(R.drawable.bg_oval_placeholder_globe_no_border_24dp) + } } } diff --git a/WordPress/src/main/res/layout/subfilter_list_item.xml b/WordPress/src/main/res/layout/subfilter_list_item.xml index fed9b0641267..5aaeec3bb628 100644 --- a/WordPress/src/main/res/layout/subfilter_list_item.xml +++ b/WordPress/src/main/res/layout/subfilter_list_item.xml @@ -5,15 +5,28 @@ style="@style/SubfilterSiteTagItem" android:layout_width="match_parent"> + + @@ -23,11 +36,13 @@ style="@style/SiteTagFilteredUrl" android:layout_width="0dp" android:layout_height="wrap_content" + android:layout_marginStart="@dimen/margin_large" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/unseen_count" - app:layout_constraintStart_toStartOf="parent" + app:layout_constraintStart_toEndOf="@id/item_avatar" app:layout_constraintTop_toBottomOf="@+id/item_title" android:visibility="visible" + app:layout_goneMarginStart="0dp" app:layout_goneMarginEnd="0dp" tools:text="www.unknown.com" /> From 37d0cf9d96a742b100208a19b920cc1f48a08951 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Tue, 9 Jan 2024 17:04:53 -0300 Subject: [PATCH 2/8] Add avatar border in subfilter item --- WordPress/src/main/res/layout/subfilter_list_item.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/res/layout/subfilter_list_item.xml b/WordPress/src/main/res/layout/subfilter_list_item.xml index 5aaeec3bb628..ed6b501dcada 100644 --- a/WordPress/src/main/res/layout/subfilter_list_item.xml +++ b/WordPress/src/main/res/layout/subfilter_list_item.xml @@ -7,6 +7,7 @@ Date: Thu, 11 Jan 2024 17:20:57 -0300 Subject: [PATCH 3/8] Hook Search Action to existing logic * Show/hide if search is supported * Open Reader search screen --- .../android/ui/reader/ReaderFragment.kt | 3 +- .../ui/reader/viewmodels/ReaderViewModel.kt | 2 ++ .../reader/views/compose/ReaderTopAppBar.kt | 28 +++++++++++-------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt index 1ee55879d14b..c26aeae912f3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt @@ -145,7 +145,8 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider, onMenuItemClick = viewModel::onTopBarMenuItemClick, onFilterClick = ::tryOpenFilterList, onClearFilterClick = ::clearFilter, - onSearchClick = {} + isSearchVisible = state.isSearchActionVisible, + onSearchClick = viewModel::onSearchActionClicked, ) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt index 145b4171aaaa..bcbdd5ceb700 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModel.kt @@ -389,6 +389,7 @@ class ReaderViewModel @Inject constructor( menuItems = menuItems, selectedItem = selectedItem, filterUiState = filterUiState, + isSearchActionVisible = isSearchSupported(), ) ) } @@ -515,6 +516,7 @@ class ReaderViewModel @Inject constructor( val menuItems: List, val selectedItem: MenuElementData.Item.Single, val filterUiState: FilterUiState? = null, + val isSearchActionVisible: Boolean = false, ) { data class FilterUiState( val blogsFilterCount: Int, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt index 843fec5814c5..c1228c929565 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/views/compose/ReaderTopAppBar.kt @@ -54,7 +54,8 @@ fun ReaderTopAppBar( onMenuItemClick: (MenuElementData.Item.Single) -> Unit, onFilterClick: (ReaderFilterType) -> Unit, onClearFilterClick: () -> Unit, - onSearchClick: () -> Unit, + isSearchVisible: Boolean, + onSearchClick: () -> Unit = {}, ) { var selectedItem by remember { mutableStateOf(topBarUiState.selectedItem) } var isFilterShown by remember { mutableStateOf(topBarUiState.filterUiState != null) } @@ -124,17 +125,19 @@ fun ReaderTopAppBar( } } Spacer(Modifier.width(Margin.ExtraSmall.value)) - IconButton( - modifier = Modifier.align(Alignment.CenterVertically), - onClick = { onSearchClick() } - ) { - Icon( - painter = painterResource(R.drawable.ic_magnifying_glass_16dp), - contentDescription = stringResource( - R.string.reader_search_content_description - ), - tint = MaterialTheme.colors.onSurface, - ) + if (isSearchVisible) { + IconButton( + modifier = Modifier.align(Alignment.CenterVertically), + onClick = { onSearchClick() } + ) { + Icon( + painter = painterResource(R.drawable.ic_magnifying_glass_16dp), + contentDescription = stringResource( + R.string.reader_search_content_description + ), + tint = MaterialTheme.colors.onSurface, + ) + } } } } @@ -225,6 +228,7 @@ fun ReaderTopAppBarPreview() { }, onFilterClick = {}, onClearFilterClick = {}, + isSearchVisible = true, onSearchClick = {}, ) } From 124b35e6a3f5373f2887e5932bf34bd01fe00003 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Thu, 11 Jan 2024 19:20:19 -0300 Subject: [PATCH 4/8] Remove first tag recommendation card from Discover feed --- .../ui/reader/services/discover/ReaderDiscoverLogic.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt index b8f609c866ca..17a833495dcf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverLogic.kt @@ -139,7 +139,7 @@ class ReaderDiscoverLogic @Inject constructor( insertBlogsIntoDb(cards.filterIsInstance().map { it.blogs }.flatten()) // Simplify the json. The simplified version is used in the upper layers to load the data from the db. - val simplifiedCardsJson = createSimplifiedJson(fullCardsJson) + val simplifiedCardsJson = createSimplifiedJson(fullCardsJson, taskType) insertCardsJsonIntoDb(simplifiedCardsJson) val nextPageHandle = parseDiscoverCardsJsonUseCase.parseNextPageHandle(json) @@ -198,7 +198,7 @@ class ReaderDiscoverLogic @Inject constructor( * as it's already stored in the db. */ @Suppress("NestedBlockDepth") - private fun createSimplifiedJson(cardsJsonArray: JSONArray): JSONArray { + private fun createSimplifiedJson(cardsJsonArray: JSONArray, discoverTasks: DiscoverTasks): JSONArray { var index = 0 val simplifiedJson = JSONArray() for (i in 0 until cardsJsonArray.length()) { @@ -212,6 +212,10 @@ class ReaderDiscoverLogic @Inject constructor( } } JSON_CARD_INTERESTS_YOU_MAY_LIKE -> { + // We should not have an interests/tags card as the first element on Discover feed. + if (i == 0 && discoverTasks == REQUEST_FIRST_PAGE) { + continue + } simplifiedJson.put(index++, cardJson) } JSON_CARD_POST -> { From b50beba9aed17afd9160266344e4b751dbc74da9 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:19:41 -0300 Subject: [PATCH 5/8] Add source parameter to READER_FILTER_SHEET_DISPLAYED analytics event --- .../wordpress/android/ui/reader/ReaderPostListFragment.java | 1 - .../android/ui/reader/subfilter/SubFilterViewModel.kt | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java index 9836f0d2a617..3fbf5df44a6d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java @@ -638,7 +638,6 @@ private void initSubFilterViewModel(@Nullable Bundle savedInstanceState) { visibleState.getCategories(), mUiHelpers.getTextOfUiString(requireContext(), visibleState.getTitle()) ); - mReaderTracker.track(Stat.READER_FILTER_SHEET_DISPLAYED); bottomSheet.show(getChildFragmentManager(), SUBFILTER_BOTTOM_SHEET_TAG); } else if (!uiState.isVisible() && bottomSheet != null) { bottomSheet.dismiss(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt index 9e6f9543523d..699ff61bd5ce 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt @@ -213,6 +213,11 @@ class SubFilterViewModel @Inject constructor( listOf(category) // TODO thomashortadev this should accept only a single category ) ) + val source = when(category) { + SubfilterCategory.SITES -> "blogs" + SubfilterCategory.TAGS -> "tags" + } + readerTracker.track(Stat.READER_FILTER_SHEET_DISPLAYED, source) } fun updateTagsAndSites() { From f9c970a0462eeae6c9ca2d68cfaa5c8dcb3718f1 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:36:45 -0300 Subject: [PATCH 6/8] [Reader] Prevent sending the analytics event reader_filter_sheet_item_selected when user taps on clear filter --- .../android/ui/reader/ReaderFragment.kt | 2 +- .../ui/reader/ReaderPostListFragment.java | 4 ++-- .../ui/reader/subfilter/SubFilterViewModel.kt | 16 ++++++++++------ .../ui/reader/subfilter/SubfilterListItem.kt | 2 ++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt index 1ee55879d14b..708bc6b8500a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt @@ -384,6 +384,6 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider, private fun clearFilter() { val viewModel = getSubFilterViewModel() ?: return - viewModel.setDefaultSubfilter() + viewModel.setDefaultSubfilter(isClearingFilter = true) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java index 3fbf5df44a6d..b20894355a08 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListFragment.java @@ -791,7 +791,7 @@ private void resumeFollowedTag() { mSubFilterViewModel.setSubfilterFromTag(newTag); } else if (isFollowingScreen() && !ReaderTagTable.tagExists(getCurrentTag())) { // user just removed a tag which was selected in the subfilter - mSubFilterViewModel.setDefaultSubfilter(); + mSubFilterViewModel.setDefaultSubfilter(false); } else { // otherwise, refresh posts to make sure any changes are reflected and auto-update // posts in the current tag if it's time @@ -827,7 +827,7 @@ private void resumeFollowedSite(Site currentSite) { refreshPosts(); } else { if (mIsFilterableScreen) { - mSubFilterViewModel.setDefaultSubfilter(); + mSubFilterViewModel.setDefaultSubfilter(false); } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt index 699ff61bd5ce..b1715a3a007a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModel.kt @@ -193,13 +193,14 @@ class SubFilterViewModel @Inject constructor( ) } - fun setDefaultSubfilter() { + fun setDefaultSubfilter(isClearingFilter: Boolean) { readerTracker.track(Stat.READER_FILTER_SHEET_CLEARED) updateSubfilter( - SiteAll( + filter = SiteAll( onClickAction = ::onSubfilterClicked, - isSelected = true - ) + isSelected = true, + isClearingFilter = isClearingFilter, + ), ) } @@ -291,7 +292,10 @@ class SubFilterViewModel @Inject constructor( } fun onSubfilterSelected(subfilterListItem: SubfilterListItem) { - readerTracker.track(Stat.READER_FILTER_SHEET_ITEM_SELECTED) + // We should not track subfilter selected if we're clearing a filter that is currently applied. + if (!subfilterListItem.isClearingFilter) { + readerTracker.track(Stat.READER_FILTER_SHEET_ITEM_SELECTED) + } changeSubfilter(subfilterListItem, true, mTagFragmentStartedWith) } @@ -345,7 +349,7 @@ class SubFilterViewModel @Inject constructor( ) ) - setDefaultSubfilter() + setDefaultSubfilter(false) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterListItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterListItem.kt index 0827c9cd121e..1e24f2c868d4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterListItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterListItem.kt @@ -14,6 +14,7 @@ import org.wordpress.android.ui.utils.UiString.UiStringText sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean = false) { open var isSelected: Boolean = false + open var isClearingFilter: Boolean = false open val onClickAction: ((filter: SubfilterListItem) -> Unit)? = null open val label: UiString? = null @@ -52,6 +53,7 @@ sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean = @Suppress("DataClassShouldBeImmutable") data class SiteAll( override var isSelected: Boolean = false, + override var isClearingFilter: Boolean = false, override val onClickAction: (filter: SubfilterListItem) -> Unit ) : SubfilterListItem(SITE_ALL) { override val label: UiString = UiStringRes(R.string.reader_filter_cta) From 45bd9fb6eda07bcfbe6190b15368a90adca81213 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:46:30 -0300 Subject: [PATCH 7/8] Update SubFilterViewModelTest --- .../subfilter/SubFilterViewModelTest.kt | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModelTest.kt index 9e3565518c74..09c971abc5d1 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/reader/subfilter/SubFilterViewModelTest.kt @@ -16,6 +16,7 @@ import org.mockito.kotlin.times import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest +import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.fluxc.model.AccountModel import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.models.ReaderTag @@ -136,7 +137,7 @@ class SubFilterViewModelTest : BaseUnitTest() { @Test fun `view model doesn't start tracking subfiltered list if filter is a not tracked item`() { - viewModel.setDefaultSubfilter() + viewModel.setDefaultSubfilter(false) // this is done to focus this unit test only on effects of initSubfiltersTracking // usually it's not considered great to use this function but here it seemed @@ -171,7 +172,7 @@ class SubFilterViewModelTest : BaseUnitTest() { @Test fun `view model is able to set default subfilter`() { var item: SubfilterListItem? = null - viewModel.setDefaultSubfilter() + viewModel.setDefaultSubfilter(false) viewModel.currentSubFilter.observeForever { item = it } @@ -424,4 +425,24 @@ class SubFilterViewModelTest : BaseUnitTest() { assertThat(it.isFiltered).isEqualTo(true) } } + + @Test + fun `Should NOT track READER_FILTER_SHEET_ITEM_SELECTED if clearing filter when onSubfilterSelected is called`() { + val filter = SiteAll( + isClearingFilter = true, + onClickAction = {}, + ) + viewModel.onSubfilterSelected(filter) + verify(readerTracker, times(0)).track(AnalyticsTracker.Stat.READER_FILTER_SHEET_ITEM_SELECTED) + } + + @Test + fun `Should track READER_FILTER_SHEET_ITEM_SELECTED if NOT clearing filter when onSubfilterSelected is called`() { + val filter = SiteAll( + isClearingFilter = false, + onClickAction = {}, + ) + viewModel.onSubfilterSelected(filter) + verify(readerTracker).track(AnalyticsTracker.Stat.READER_FILTER_SHEET_ITEM_SELECTED) + } } From 3adf96a76eff8ab11e46f32dd4667b39de625ebc Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 3 Jan 2024 19:48:11 -0300 Subject: [PATCH 8/8] Updated reader fetch tag posts limit from 20 to 7 --- .../java/org/wordpress/android/ui/reader/ReaderConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderConstants.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderConstants.java index f2ccf32c2ba4..504d71f1de01 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderConstants.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderConstants.java @@ -2,7 +2,7 @@ public class ReaderConstants { // max # posts to request when updating posts - public static final int READER_MAX_POSTS_TO_REQUEST = 20; + public static final int READER_MAX_POSTS_TO_REQUEST = 7; // max # results to request when searching posts & sites public static final int READER_MAX_SEARCH_RESULTS_TO_REQUEST = 20;