Skip to content

Commit

Permalink
Fixed small thumbnails not being displayed in card style
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Dec 21, 2023
1 parent 403133b commit 67b521a
Show file tree
Hide file tree
Showing 4 changed files with 663 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.nononsenseapps.feeder.ui.compose

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import com.nononsenseapps.feeder.archmodel.FeedItemStyle
import com.nononsenseapps.feeder.archmodel.Repository
import com.nononsenseapps.feeder.archmodel.SyncFrequency
import com.nononsenseapps.feeder.db.room.Feed
import com.nononsenseapps.feeder.db.room.FeedItem
import com.nononsenseapps.feeder.model.ImageFromHTML
import com.nononsenseapps.feeder.ui.MainActivity
import kotlinx.coroutines.runBlocking
import org.junit.Rule
import org.junit.Test
import org.kodein.di.instance
import java.net.URL
import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime

class ThumbnailsAreDisplayedTest : BaseComposeTest {
@get:Rule
override val composeTestRule = createAndroidComposeRule<MainActivity>()

@OptIn(ExperimentalTestApi::class)
@Test
fun thumbnailsAreShown() {
val repository by (composeTestRule.activity).di.instance<Repository>()

repository.setSyncFrequency(SyncFrequency.MANUAL)
repository.setFeedItemStyle(FeedItemStyle.CARD)
repository.setShowThumbnails(true)

// Ensure we have feeds and items
runBlocking {
val feedId =
repository.saveFeed(
Feed(
title = "Ampersands are & the worst",
url = URL("https://example.com/ampersands"),
),
)

repository.setCurrentFeedAndTag(feedId, "")

repository.upsertFeedItems(
listOf(
FeedItem(
guid = "guid anime2you",
plainTitle = "Item with image",
plainSnippet = "Snippet with image",
feedId = feedId,
pubDate = ZonedDateTime.now(ZoneOffset.UTC),
primarySortTime = Instant.now(),
thumbnailImage =
ImageFromHTML(
url = "https://img.anime2you.de/2023/12/jujutsu-kaisen-6.jpg",
width = 700,
height = 350,
),
) to "",
),
) { _, _ -> }
}

composeTestRule.waitUntilExactlyOneExists(
hasTestTag("feed_list"),
5_000L,
)

composeTestRule.onNodeWithTag("card_image", useUnmergedTree = true)
.assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
Expand All @@ -36,6 +34,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.text.withStyle
Expand All @@ -50,6 +49,7 @@ import com.nononsenseapps.feeder.db.room.ID_UNSET
import com.nononsenseapps.feeder.model.MediaImage
import com.nononsenseapps.feeder.ui.compose.coil.RestrainedCropScaling
import com.nononsenseapps.feeder.ui.compose.coil.rememberTintedVectorPainter
import com.nononsenseapps.feeder.ui.compose.components.safeSemantics
import com.nononsenseapps.feeder.ui.compose.feedarticle.wordsToReadTimeSecs
import com.nononsenseapps.feeder.ui.compose.minimumTouchSize
import com.nononsenseapps.feeder.ui.compose.text.WithBidiDeterminedLayoutDirection
Expand Down Expand Up @@ -92,11 +92,7 @@ fun FeedItemCard(
if (showThumbnail) {
item.image?.let { image ->
// Don't render known super small images. Null is OK
val width = image.width
val height = image.height
val badHeight = (height ?: 1000) < 360
val badWidth = (width ?: 1000) < 640
if (!badWidth && !badHeight) {
if ((image.width ?: 1000) >= 10 && (image.height ?: 1000) >= 10) {
val pixelDensity = LocalDensity.current.density
val contentScale =
remember(pixelDensity) {
Expand Down Expand Up @@ -138,7 +134,10 @@ fun FeedItemCard(
.fillMaxWidth()
.aspectRatio(16.0f / 9.0f)
.background(MaterialTheme.colorScheme.surfaceVariant)
.alpha(alpha),
.alpha(alpha)
.safeSemantics {
testTag = "card_image"
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,35 @@ class FeedParserTest : DIAware {
}
}

@Test
fun anime2youHasThumbnails() {
runBlocking {
readResource("rss_anime2you.xml") {
val feed =
feedParser.parseFeedResponse(
URL("https://www.anime2you.de/feed/"),
it,
null,
)

val item = feed.getOrNull()?.items!!.first()

val expected =
ImageFromHTML(
url = "https://img.anime2you.de/2023/12/jujutsu-kaisen-6.jpg",
width = 700,
height = 350,
)

assertEquals(
expected,
item.image,
"Thumbnail image was unexpected",
)
}
}
}

@Test
fun dcCreatorEndsUpAsAuthor() =
runBlocking {
Expand Down
Loading

0 comments on commit 67b521a

Please sign in to comment.