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..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) {
@@ -142,6 +141,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)
}
@@ -166,9 +179,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,
)
@@ -199,6 +212,9 @@ class ReaderViewModel @Inject constructor(
}
fun onTagChanged(selectedTag: ReaderTag?) {
+ if (selectedTag?.isDiscover == false) {
+ hideAnnouncementCard()
+ }
selectedTag?.let {
trackReaderTabShownIfNecessary(it)
}
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" />
-
+
-
+
-
+
+
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()