Skip to content

Commit

Permalink
Small tweaks and bugfixes (#162)
Browse files Browse the repository at this point in the history
* Attempt to fix layout crash with placeholders

Default "placeholders" to true for the article pager
in an attempt to avoid the IllegalStateException
"Error: Placement happened before lookahead." Placeholders
in the DB are different from placeholders in the UI, but the
error also only happens during scroll.

* Tweak font styles on article cards
  • Loading branch information
jocmp authored Jul 13, 2024
1 parent e3cef3d commit 11df0d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
23 changes: 19 additions & 4 deletions app/src/main/java/com/capyreader/app/ui/articles/ArticleRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.material3.ListItemColors
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
Expand All @@ -24,6 +25,10 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
Expand Down Expand Up @@ -83,6 +88,7 @@ fun ArticleRow(
headlineContent = {
Text(
article.title,
fontWeight = titleFontWeight(read = article.read),
)
},
supportingContent = {
Expand All @@ -104,6 +110,8 @@ fun ArticleRow(
time = article.publishedAt,
currentTime = currentTime,
),
style = typography.labelSmall,
modifier = Modifier.padding(vertical = 4.dp),
maxLines = 1,
)
}
Expand Down Expand Up @@ -153,6 +161,14 @@ fun PlaceholderArticleRow() {
)
}

@Composable
fun titleFontWeight(read: Boolean): FontWeight {
return if (read) {
FontWeight.Normal
} else {
FontWeight.Bold
}
}

@Composable
@Stable
Expand All @@ -173,12 +189,11 @@ private fun listItemColors(
@Composable
fun findFeedNameColor(read: Boolean): Color {
val defaults = ListItemDefaults.colors()
val colorScheme = MaterialTheme.colorScheme

return if (read) {
defaults.disabledHeadlineColor
} else {
colorScheme.onSurface
Color.Unspecified
}
}

Expand All @@ -195,7 +210,7 @@ fun ArticleRowPreview_Selected_DarkMode() {
contentHTML = "<div>Test</div>",
extractedContentURL = null,
imageURL = URL("https://example.com"),
summary = "Test article here",
summary = "The Galaxy S24 series, while bringing little physical change, packs a lot of AI narrative. One of the biggest Galaxy S24 features is the AI Generative Edit",
url = URL("https://9to5google.com/?p=605559"),
updatedAt = ZonedDateTime.of(2024, 2, 11, 8, 33, 0, 0, ZoneOffset.UTC),
publishedAt = ZonedDateTime.of(2024, 2, 11, 8, 33, 0, 0, ZoneOffset.UTC),
Expand Down Expand Up @@ -249,7 +264,7 @@ fun ArticleRowPreview_Unread() {
summary = "Test article here",
url = URL("https://9to5google.com/?p=605559"),
updatedAt = ZonedDateTime.of(2024, 2, 11, 8, 33, 0, 0, ZoneOffset.UTC),
publishedAt = ZonedDateTime.of(2024, 2, 11, 8, 33, 0, 0, ZoneOffset.UTC),
publishedAt = ZonedDateTime.of(LocalDateTime.now().minusHours(1), ZoneOffset.UTC),
read = false,
starred = false,
feedName = "9to5Google"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.jocmp.capy.Countable
import com.jocmp.capy.Feed
import com.jocmp.capy.Folder
import com.jocmp.capy.MarkRead
import com.jocmp.capy.buildPager
import com.jocmp.capy.buildArticlePager
import com.jocmp.capy.common.UnauthorizedError
import com.jocmp.capy.countAll
import com.capyreader.app.common.AppPreferences
Expand Down Expand Up @@ -54,7 +54,7 @@ class ArticleScreenViewModel(
}

val articles: Flow<PagingData<Article>> = filter
.flatMapLatest { account.buildPager(it).flow }
.flatMapLatest { account.buildArticlePager(it).flow }
.cachedIn(viewModelScope)

val folders: Flow<List<Folder>> = account.folders.combine(_counts) { folders, latestCounts ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import androidx.paging.PagingConfig
import com.jocmp.capy.persistence.ArticlePagerFactory
import java.time.OffsetDateTime

fun Account.buildPager(
fun Account.buildArticlePager(
filter: ArticleFilter,
since: OffsetDateTime = OffsetDateTime.now()
): Pager<Int, Article> {
return Pager(
config = PagingConfig(
pageSize = 50,
prefetchDistance = 10,
enablePlaceholders = false
),
pagingSourceFactory = { ArticlePagerFactory(database).find(filter = filter, since = since) }
)
Expand Down

0 comments on commit 11df0d0

Please sign in to comment.