From 11df0d0ac6f494938450b13b4df20288b065f518 Mon Sep 17 00:00:00 2001 From: jocmp <9521010+jocmp@users.noreply.github.com> Date: Sat, 13 Jul 2024 15:36:54 -0500 Subject: [PATCH] Small tweaks and bugfixes (#162) * 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 --- .../capyreader/app/ui/articles/ArticleRow.kt | 23 +++++++++++++++---- .../app/ui/articles/ArticleScreenViewModel.kt | 4 ++-- ...ager.kt => AccountBuildArticlePagerExt.kt} | 3 +-- 3 files changed, 22 insertions(+), 8 deletions(-) rename capy/src/main/java/com/jocmp/capy/{AccountPager.kt => AccountBuildArticlePagerExt.kt} (88%) diff --git a/app/src/main/java/com/capyreader/app/ui/articles/ArticleRow.kt b/app/src/main/java/com/capyreader/app/ui/articles/ArticleRow.kt index 9e5904e9..877cb188 100644 --- a/app/src/main/java/com/capyreader/app/ui/articles/ArticleRow.kt +++ b/app/src/main/java/com/capyreader/app/ui/articles/ArticleRow.kt @@ -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 @@ -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 @@ -83,6 +88,7 @@ fun ArticleRow( headlineContent = { Text( article.title, + fontWeight = titleFontWeight(read = article.read), ) }, supportingContent = { @@ -104,6 +110,8 @@ fun ArticleRow( time = article.publishedAt, currentTime = currentTime, ), + style = typography.labelSmall, + modifier = Modifier.padding(vertical = 4.dp), maxLines = 1, ) } @@ -153,6 +161,14 @@ fun PlaceholderArticleRow() { ) } +@Composable +fun titleFontWeight(read: Boolean): FontWeight { + return if (read) { + FontWeight.Normal + } else { + FontWeight.Bold + } +} @Composable @Stable @@ -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 } } @@ -195,7 +210,7 @@ fun ArticleRowPreview_Selected_DarkMode() { contentHTML = "
Test
", 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), @@ -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" diff --git a/app/src/main/java/com/capyreader/app/ui/articles/ArticleScreenViewModel.kt b/app/src/main/java/com/capyreader/app/ui/articles/ArticleScreenViewModel.kt index c2ae1aa5..69ac203d 100644 --- a/app/src/main/java/com/capyreader/app/ui/articles/ArticleScreenViewModel.kt +++ b/app/src/main/java/com/capyreader/app/ui/articles/ArticleScreenViewModel.kt @@ -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 @@ -54,7 +54,7 @@ class ArticleScreenViewModel( } val articles: Flow> = filter - .flatMapLatest { account.buildPager(it).flow } + .flatMapLatest { account.buildArticlePager(it).flow } .cachedIn(viewModelScope) val folders: Flow> = account.folders.combine(_counts) { folders, latestCounts -> diff --git a/capy/src/main/java/com/jocmp/capy/AccountPager.kt b/capy/src/main/java/com/jocmp/capy/AccountBuildArticlePagerExt.kt similarity index 88% rename from capy/src/main/java/com/jocmp/capy/AccountPager.kt rename to capy/src/main/java/com/jocmp/capy/AccountBuildArticlePagerExt.kt index 9c74e3dc..0f4af21d 100644 --- a/capy/src/main/java/com/jocmp/capy/AccountPager.kt +++ b/capy/src/main/java/com/jocmp/capy/AccountBuildArticlePagerExt.kt @@ -5,7 +5,7 @@ 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 { @@ -13,7 +13,6 @@ fun Account.buildPager( config = PagingConfig( pageSize = 50, prefetchDistance = 10, - enablePlaceholders = false ), pagingSourceFactory = { ArticlePagerFactory(database).find(filter = filter, since = since) } )