diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-08-31 15:43:02 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-08-31 15:43:02 +0000 |
| commit | 0cd94d0821661fef3fc34b51011be95034e51a5b (patch) | |
| tree | ea91f813be8bbe0e5aac506744fcfbb22ce3ad41 /app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt | |
| parent | e42bfbd6a65eefd0f24677aebb74993ae56490cf (diff) | |
Add reader font size setting, rewrite paywall-avoidance settings copy
Font size was hardcoded at 18px in ReaderWebView's injected CSS. Added
a DataStore-backed setting (Settings.readerFontSizePx, 14-28px range)
with a slider in Settings, threaded through ReaderScreen/ReaderContent
into wrapReaderHtml. The reload-tracking key in ReaderContent's
AndroidView now includes font size alongside content, so changing it
and returning to an already-open article picks up the new size without
reloading on every unrelated recomposition (matches the existing
comment there about avoiding scroll-position jank).
Rewrote the Settings screen's paywall note -- it read as defensive
throat-clearing about what the app won't do. Restated as what it's
actually for: avoiding tracking, manipulation, and junk fees, with
reader mode pulling up anything findable by search anyway.
Regenerated the detekt baseline: ReaderContent's pre-existing
LongMethod/LongParameterList/CyclomaticComplexMethod findings are
keyed by exact function signature text, and adding the fontSizePx
parameter changed that text, invalidating the old baseline entries.
The underlying debt (a 300+ line, 9-now-10-parameter composable)
predates this change and isn't what this commit is about.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018AwnALZL6bD4VBtATDVv3B
Diffstat (limited to 'app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt')
| -rw-r--r-- | app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt b/app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt index 3c3ab66..a89052c 100644 --- a/app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt +++ b/app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt @@ -41,6 +41,7 @@ import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -56,6 +57,7 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import org.terst.feedreader.data.AppDatabase import org.terst.feedreader.data.ArticleEntity +import org.terst.feedreader.data.DEFAULT_READER_FONT_SIZE_PX import org.terst.feedreader.data.FeedEntity import org.terst.feedreader.data.Settings import org.terst.feedreader.data.ensureStandaloneArticle @@ -99,6 +101,7 @@ fun ReaderScreen( val db = remember { AppDatabase.get(context) } val settings = remember { Settings(context) } val scope = rememberCoroutineScope() + val fontSizePx by settings.readerFontSizePx.collectAsState(initial = DEFAULT_READER_FONT_SIZE_PX) var previousId by remember(articleId) { mutableStateOf<String?>(null) } var nextId by remember(articleId) { mutableStateOf<String?>(null) } @@ -156,7 +159,8 @@ fun ReaderScreen( hasNext = nextId != null, onPrevious = ::goToPreviousArticle, onNext = ::goToNextArticle, - onNextKeepUnread = ::goToNextArticleKeepUnread + onNextKeepUnread = ::goToNextArticleKeepUnread, + fontSizePx = fontSizePx ) } @@ -171,7 +175,8 @@ private fun ReaderContent( hasNext: Boolean, onPrevious: () -> Unit, onNext: () -> Unit, - onNextKeepUnread: () -> Unit + onNextKeepUnread: () -> Unit, + fontSizePx: Int ) { val context = LocalContext.current val db = remember { AppDatabase.get(context) } @@ -516,8 +521,11 @@ private fun ReaderContent( // flipping while a Stash save is in flight. Reloading the WebView's HTML // on those unrelated recompositions was resetting scroll position mid-swipe, // which is what made scrolling feel unsmooth/janky. Track what's actually - // loaded and only reload when the content string itself changes. - val loadedContent = remember(articleId) { mutableStateOf<String?>(null) } + // loaded and only reload when the content string or font size actually + // changes -- fontSizePx is included deliberately (not just content) so + // changing it in Settings and coming back to an already-open article + // picks up the new size, without reloading on every unrelated recomposition. + val loadedKey = remember(articleId) { mutableStateOf<Pair<String?, Int>?>(null) } AndroidView( modifier = Modifier.fillMaxSize(), factory = { ctx -> @@ -532,14 +540,16 @@ private fun ReaderContent( // to 0 on a page that hasn't grown tall enough yet. onPageFinished = { webView -> webView.scrollTo(0, ReaderScrollPositions.get(articleId)) } ).apply { - loadDataWithBaseURL(baseUrl, wrapReaderHtml(content, article?.title, article?.publishedAt, article?.imageUrl), "text/html", "UTF-8", null) - loadedContent.value = content + val html = wrapReaderHtml(content, article?.title, article?.publishedAt, article?.imageUrl, fontSizePx) + loadDataWithBaseURL(baseUrl, html, "text/html", "UTF-8", null) + loadedKey.value = content to fontSizePx } }, update = { webView -> - if (loadedContent.value != content) { - webView.loadDataWithBaseURL(baseUrl, wrapReaderHtml(content, article?.title, article?.publishedAt, article?.imageUrl), "text/html", "UTF-8", null) - loadedContent.value = content + if (loadedKey.value != content to fontSizePx) { + val html = wrapReaderHtml(content, article?.title, article?.publishedAt, article?.imageUrl, fontSizePx) + webView.loadDataWithBaseURL(baseUrl, html, "text/html", "UTF-8", null) + loadedKey.value = content to fontSizePx } }, // AndroidView does not destroy() the underlying WebView on its own -- |
