Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reader] Implement announcement card improvements #20861

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -169,6 +171,7 @@ class ReaderDiscoverViewModel @Inject constructor(
swipeToRefreshTriggered = false
}
} else {
parentViewModel.onFeedEmptyStateLoaded()
_uiState.value = DiscoverUiState.EmptyUiState.ShowNoPostsUiState {
_navigationEvents.value = Event(ShowReaderSubs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class ReaderViewModel @Inject constructor(
if (initialized) return
loadTabs(savedInstanceState)
if (jetpackBrandingUtils.shouldShowJetpackPoweredBottomSheet()) showJetpackPoweredBottomSheet()
updateAnnouncementCard()
}

fun onSaveInstanceState(out: Bundle) {
Expand All @@ -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)
}
Expand All @@ -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,
)
Expand Down Expand Up @@ -199,6 +212,9 @@ class ReaderViewModel @Inject constructor(
}

fun onTagChanged(selectedTag: ReaderTag?) {
if (selectedTag?.isDiscover == false) {
hideAnnouncementCard()
}
selectedTag?.let {
trackReaderTabShownIfNecessary(it)
}
Expand Down
51 changes: 15 additions & 36 deletions WordPress/src/main/res/layout/reader_fragment_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,26 @@
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways" />

</com.google.android.material.appbar.AppBarLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="56dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<FrameLayout
android:id="@+id/container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/reader_announcement_card_compose_view" />

<androidx.compose.ui.platform.ComposeView
android:id="@+id/reader_announcement_card_compose_view"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_scrollFlags="scroll|enterAlways" />

<FrameLayout
android:id="@+id/interests_fragment_container"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</com.google.android.material.appbar.AppBarLayout>

<include
android:id="@+id/jetpack_banner"
layout="@layout/jetpack_banner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</androidx.constraintlayout.widget.ConstraintLayout>
<include
android:id="@+id/jetpack_banner"
layout="@layout/jetpack_banner" />

<FrameLayout
android:id="@+id/interests_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
Loading