Skip to content

Commit d49c6a7

Browse files
AdamLigaadalpari
andauthored
Fix Reader feed image display for VIDEO card types (#22325)
* Fix Reader feed image display for VIDEO card types - VIDEO cards now show featured images when available - Updated buildFeaturedImageVisibility() to support VIDEO cards with images - Updated buildFeaturedImageUrl() for consistent behavior across card types - Added comprehensive unit tests for VIDEO card image display - Fixes issue where VIDEO posts with thumbnails didn't show images Fixes #21332 * Remove unused imports (PHOTO, DEFAULT) - Removed unused ReaderCardType.PHOTO import - Removed unused ReaderCardType.DEFAULT import - Addresses SonarCloud code analysis warnings --------- Co-authored-by: Adalberto Plaza <adalpari@gmail.com>
1 parent dc52538 commit d49c6a7

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

WordPress/src/main/java/org/wordpress/android/ui/reader/discover/ReaderPostUiStateBuilder.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import kotlinx.coroutines.withContext
66
import org.wordpress.android.R
77
import org.wordpress.android.fluxc.store.AccountStore
88
import org.wordpress.android.models.ReaderBlog
9-
import org.wordpress.android.models.ReaderCardType.DEFAULT
109
import org.wordpress.android.models.ReaderCardType.GALLERY
11-
import org.wordpress.android.models.ReaderCardType.PHOTO
1210
import org.wordpress.android.models.ReaderCardType.VIDEO
1311
import org.wordpress.android.models.ReaderPost
1412
import org.wordpress.android.models.ReaderTag
@@ -282,17 +280,21 @@ class ReaderPostUiStateBuilder @Inject constructor(
282280
// TODO malinjir show overlay when buildFullVideoUrl != null
283281
private fun buildVideoOverlayVisibility(post: ReaderPost) = post.cardType == VIDEO
284282

285-
private fun buildFeaturedImageVisibility(post: ReaderPost) =
286-
(post.cardType == PHOTO || post.cardType == DEFAULT) && post.hasFeaturedImage() ||
287-
post.cardType == VIDEO && post.hasFeaturedVideo()
283+
private fun buildFeaturedImageVisibility(post: ReaderPost): Boolean {
284+
return when (post.cardType) {
285+
GALLERY -> false
286+
VIDEO -> post.hasFeaturedVideo() || post.hasFeaturedImage()
287+
else -> post.hasFeaturedImage()
288+
}
289+
}
288290

289291
private fun buildThumbnailStripUrls(post: ReaderPost) =
290292
post.takeIf { it.cardType == GALLERY }
291293
?.let { retrieveGalleryThumbnailUrls(post) }
292294

293295
private fun buildFeaturedImageUrl(post: ReaderPost, photonWidth: Int, photonHeight: Int): String? {
294296
return post
295-
.takeIf { (it.cardType == PHOTO || it.cardType == DEFAULT) && it.hasFeaturedImage() }
297+
.takeIf { it.cardType != GALLERY && it.hasFeaturedImage() }
296298
?.getFeaturedImageForDisplay(photonWidth, photonHeight)
297299
}
298300

WordPress/src/test/java/org/wordpress/android/ui/reader/discover/ReaderPostUiStateBuilderTest.kt

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ class ReaderPostUiStateBuilderTest : BaseUnitTest() {
312312

313313
// region FEATURED IMAGE
314314
@Test
315-
fun `featured image is displayed for photo and default card types`() = test {
315+
fun `featured image is displayed for supported card types`() = test {
316316
// Arrange
317317
val dummyUrl = "12345"
318-
ReaderCardType.values().filter { it == PHOTO || it == DEFAULT }.forEach {
318+
ReaderCardType.values().filter { it != GALLERY }.forEach {
319319
val post = createPost(cardType = it, hasFeaturedImage = true, featuredImageUrlForDisplay = dummyUrl)
320320
// Act
321321
val uiState = mapPostToUiState(post)
@@ -325,10 +325,10 @@ class ReaderPostUiStateBuilderTest : BaseUnitTest() {
325325
}
326326

327327
@Test
328-
fun `featured image is displayed for photo and default card types for new UI`() = test {
328+
fun `featured image is displayed for supported card types for new UI`() = test {
329329
// Arrange
330330
val dummyUrl = "12345"
331-
ReaderCardType.values().filter { it == PHOTO || it == DEFAULT }.forEach {
331+
ReaderCardType.values().filter { it != GALLERY }.forEach {
332332
val post = createPost(cardType = it, hasFeaturedImage = true, featuredImageUrlForDisplay = dummyUrl)
333333
// Act
334334
val uiState = mapPostToUiState(post)
@@ -338,27 +338,23 @@ class ReaderPostUiStateBuilderTest : BaseUnitTest() {
338338
}
339339

340340
@Test
341-
fun `featured image is not displayed for other than photo and default card types`() = test {
341+
fun `featured image is not displayed for gallery card type`() = test {
342342
// Arrange
343-
ReaderCardType.values().filter { it != PHOTO && it != DEFAULT }.forEach {
344-
val post = createPost(cardType = it, hasFeaturedImage = true)
345-
// Act
346-
val uiState = mapPostToUiState(post)
347-
// Assert
348-
assertThat(uiState.featuredImageUrl).isNull()
349-
}
343+
val post = createPost(cardType = GALLERY, hasFeaturedImage = true)
344+
// Act
345+
val uiState = mapPostToUiState(post)
346+
// Assert
347+
assertThat(uiState.featuredImageUrl).isNull()
350348
}
351349

352350
@Test
353-
fun `featured image is not displayed for other than photo and default card types for new UI`() = test {
351+
fun `featured image is not displayed for gallery card type for new UI`() = test {
354352
// Arrange
355-
ReaderCardType.values().filter { it != PHOTO && it != DEFAULT }.forEach {
356-
val post = createPost(cardType = it, hasFeaturedImage = true)
357-
// Act
358-
val uiState = mapPostToUiState(post)
359-
// Assert
360-
assertThat(uiState.featuredImageUrl).isNull()
361-
}
353+
val post = createPost(cardType = GALLERY, hasFeaturedImage = true)
354+
// Act
355+
val uiState = mapPostToUiState(post)
356+
// Assert
357+
assertThat(uiState.featuredImageUrl).isNull()
362358
}
363359

364360
@Test
@@ -380,6 +376,21 @@ class ReaderPostUiStateBuilderTest : BaseUnitTest() {
380376
// Assert
381377
assertThat(uiState.featuredImageUrl).isNull()
382378
}
379+
380+
@Test
381+
fun `video card shows featured media area when only video is available`() = test {
382+
// Arrange
383+
val post = createPost(
384+
cardType = VIDEO,
385+
hasFeaturedVideo = true,
386+
featuredVideoUrl = "video://example",
387+
hasFeaturedImage = false
388+
)
389+
// Act
390+
val uiState = mapPostToUiState(post)
391+
// Assert
392+
assertThat(uiState.featuredImageVisibility).isTrue
393+
}
383394
// endregion
384395

385396
// region TITLE & EXCERPT

0 commit comments

Comments
 (0)