From 7587b30db2e0290d519ab029d7e12b3b9d196286 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Tue, 21 May 2024 22:06:49 -0300 Subject: [PATCH 1/5] Make reader announcement card scrollable as part of the post list --- .../res/layout/reader_fragment_layout.xml | 51 ++++++------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/WordPress/src/main/res/layout/reader_fragment_layout.xml b/WordPress/src/main/res/layout/reader_fragment_layout.xml index 081157fd6aa8..8bab85f1abe9 100644 --- a/WordPress/src/main/res/layout/reader_fragment_layout.xml +++ b/WordPress/src/main/res/layout/reader_fragment_layout.xml @@ -16,47 +16,26 @@ android:layout_height="wrap_content" app:layout_scrollFlags="scroll|enterAlways" /> - - - - - - + app:layout_scrollFlags="scroll|enterAlways" /> - + - + - + + From 6f3a6bbbf02efcac28bc020095b03af3b3909c4c Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Tue, 21 May 2024 23:00:21 -0300 Subject: [PATCH 2/5] Hide reader announcement card on Discover when empty state is shown --- .../ui/reader/discover/ReaderDiscoverViewModel.kt | 3 +++ .../ui/reader/viewmodels/ReaderViewModel.kt | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverViewModel.kt index b50d61aa70ae..cac0f5ff301f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderDiscoverViewModel.kt @@ -154,11 +154,13 @@ class ReaderDiscoverViewModel @Inject constructor( // since new users have the dailyprompt tag followed by default, we need to ignore them when // checking if the user has any tags followed, so we show the onboarding state (ShowNoFollowedTags) if (userTags.filterNot { it.tagSlug == BLOGGING_PROMPT_TAG }.isEmpty()) { + parentViewModel.onFeedEmptyStateLoaded() _uiState.value = DiscoverUiState.EmptyUiState.ShowNoFollowedTagsUiState { parentViewModel.onShowReaderInterests() } } else { if (posts != null && posts.cards.isNotEmpty()) { + parentViewModel.onFeedContentLoaded() _uiState.value = DiscoverUiState.ContentUiState( convertCardsToUiStates(posts), reloadProgressVisibility = false, @@ -169,6 +171,7 @@ class ReaderDiscoverViewModel @Inject constructor( swipeToRefreshTriggered = false } } else { + parentViewModel.onFeedEmptyStateLoaded() _uiState.value = DiscoverUiState.EmptyUiState.ShowNoPostsUiState { _navigationEvents.value = Event(ShowReaderSubs) } 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 14ba95f13dbc..4bf77d16e5c3 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 @@ -142,6 +142,20 @@ class ReaderViewModel @Inject constructor( } } + fun onFeedEmptyStateLoaded() { + hideAnnouncementCard() + } + + fun onFeedContentLoaded() { + updateAnnouncementCard() + } + + private fun hideAnnouncementCard() { + _announcementCardState.value = _announcementCardState.value?.copy( + shouldShow = false, + ) + } + private fun showJetpackPoweredBottomSheet() { // _showJetpackPoweredBottomSheet.value = Event(true) } From 00dd7ead5c7fafb90bac8b5408340378ab76db1a Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Tue, 21 May 2024 23:43:13 -0300 Subject: [PATCH 3/5] Show reader announcement card only on Discover feed --- .../android/ui/reader/viewmodels/ReaderViewModel.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 4bf77d16e5c3..d95db4a3071e 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 @@ -180,9 +180,9 @@ class ReaderViewModel @Inject constructor( descriptionRes = R.string.reader_announcement_card_reading_preferences_description, ) ) - + val isDiscoverSelected = selectedReaderTag()?.isDiscover == true _announcementCardState.value = AnnouncementCardUiState( - shouldShow = readerAnnouncementCardFeatureConfig.isEnabled() && + shouldShow = isDiscoverSelected && readerAnnouncementCardFeatureConfig.isEnabled() && appPrefsWrapper.shouldShowReaderAnnouncementCard(), items = items, ) @@ -213,6 +213,7 @@ class ReaderViewModel @Inject constructor( } fun onTagChanged(selectedTag: ReaderTag?) { + updateAnnouncementCard() selectedTag?.let { trackReaderTabShownIfNecessary(it) } From 90fbfec90042e408873a636fabe89860f26e793e Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 22 May 2024 00:33:58 -0300 Subject: [PATCH 4/5] Hide reader announcement card when any feed but Discover is selected --- .../android/ui/reader/viewmodels/ReaderViewModel.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 d95db4a3071e..876beb4f2fee 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 @@ -132,7 +132,6 @@ class ReaderViewModel @Inject constructor( if (initialized) return loadTabs(savedInstanceState) if (jetpackBrandingUtils.shouldShowJetpackPoweredBottomSheet()) showJetpackPoweredBottomSheet() - updateAnnouncementCard() } fun onSaveInstanceState(out: Bundle) { @@ -213,7 +212,9 @@ class ReaderViewModel @Inject constructor( } fun onTagChanged(selectedTag: ReaderTag?) { - updateAnnouncementCard() + if (selectedTag?.isDiscover == false) { + hideAnnouncementCard() + } selectedTag?.let { trackReaderTabShownIfNecessary(it) } From 9d73d4a3d85fc3bf04114caae33d2cc275264eb8 Mon Sep 17 00:00:00 2001 From: Renan Lukas <14964993+RenanLukas@users.noreply.github.com> Date: Wed, 22 May 2024 01:17:17 -0300 Subject: [PATCH 5/5] Update ReaderViewModel unit tests --- .../reader/viewmodels/ReaderViewModelTest.kt | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModelTest.kt index 06657f8f67ca..64f90bae1d04 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/reader/viewmodels/ReaderViewModelTest.kt @@ -510,10 +510,10 @@ class ReaderViewModelTest : BaseUnitTest() { } @Test - fun `Should load announcement card correctly with tags item`() = testWithNonEmptyTags { + fun `Should update announcement card UI correctly with tags item`() = testWithNonEmptyTags { whenever(readerTagsFeedFeatureConfig.isEnabled()).thenReturn(true) - triggerContentDisplay() + viewModel.onFeedContentLoaded() val observers = initObservers() val announcementCardUiState = observers.announcementCardStateEvents.first() @@ -536,10 +536,10 @@ class ReaderViewModelTest : BaseUnitTest() { } @Test - fun `Should load announcement card correctly without tags item`() = testWithNonEmptyTags { + fun `Should update announcement card UI correctly without tags item onFeedContentLoaded`() = testWithNonEmptyTags { whenever(readerTagsFeedFeatureConfig.isEnabled()).thenReturn(false) - triggerContentDisplay() + viewModel.onFeedContentLoaded() val observers = initObservers() val announcementCardUiState = observers.announcementCardStateEvents.first() @@ -557,32 +557,41 @@ class ReaderViewModelTest : BaseUnitTest() { } @Test - fun `Should show announcement card if feature flag is enabled and app preference returns true`() = + fun `Should show announcement card if feature flag is enabled, app preference returns true and feed is Discover`() = testWithNonEmptyTags { - whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(true) - whenever(appPrefsWrapper.shouldShowReaderAnnouncementCard()).thenReturn(true) - triggerContentDisplay() - val observers = initObservers() + val readerTag = ReaderTag("Discover", "Discover", "Discover", DISCOVER_PATH, ReaderTagType.DEFAULT) + whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(true) + whenever(appPrefsWrapper.shouldShowReaderAnnouncementCard()).thenReturn(true) + val observers = initObservers() + triggerContentDisplay() + viewModel.updateSelectedContent(readerTag) + viewModel.onFeedContentLoaded() - val announcementCardUiState = observers.announcementCardStateEvents.first() - assertTrue(announcementCardUiState.shouldShow) - } + val announcementCardUiState = observers.announcementCardStateEvents.first() + assertTrue(announcementCardUiState.shouldShow) + } @Test fun `Should NOT show announcement card if feature flag is disabled`() = testWithNonEmptyTags { - whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(false) - triggerContentDisplay() - val observers = initObservers() + val readerTag = ReaderTag("Discover", "Discover", "Discover", DISCOVER_PATH, ReaderTagType.DEFAULT) + whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(false) + val observers = initObservers() + triggerContentDisplay() + viewModel.updateSelectedContent(readerTag) + viewModel.onFeedContentLoaded() - val announcementCardUiState = observers.announcementCardStateEvents.first() - assertFalse(announcementCardUiState.shouldShow) - } + val announcementCardUiState = observers.announcementCardStateEvents.first() + assertFalse(announcementCardUiState.shouldShow) + } @Test fun `Should NOT show announcement card if app preference returns false`() = testWithNonEmptyTags { + val readerTag = ReaderTag("Discover", "Discover", "Discover", DISCOVER_PATH, ReaderTagType.DEFAULT) whenever(readerAnnouncementCardFeatureConfig.isEnabled()).thenReturn(true) whenever(appPrefsWrapper.shouldShowReaderAnnouncementCard()).thenReturn(false) triggerContentDisplay() + viewModel.updateSelectedContent(readerTag) + viewModel.onFeedContentLoaded() val observers = initObservers() val announcementCardUiState = observers.announcementCardStateEvents.first()