From b5a96ad1d0a412c21159d6265e451f7c3aefc796 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Tue, 15 Sep 2026 23:12:44 +0000 Subject: Support pinch-to-zoom for reader text size in the article view Pinching in ReaderScreen's article WebView now adjusts the same persisted reader font size the Settings slider controls, instead of doing nothing (WebView's own page zoom was never enabled, so a pinch previously had no effect at all). A ScaleGestureDetector is fed through setOnTouchListener, which always returns false so it never consumes the touch -- WebView's existing one-finger scrolling, link taps and long-press-link handling are unaffected, since ScaleGestureDetector only fires once a second pointer is down. During the gesture the WebView is scaled live via View.scaleX/ scaleY for immediate visual feedback; at gesture end the scale resets to 1x and the computed, clamped font size is persisted, which drives ReaderScreen's existing content-reload-on-fontSizePx-change path to re-render the actual HTML at the new size. TDD: pinchZoomFontSizePx (the pure scale-factor -> clamped-px calculation) was written test-first, red on a TODO() stub, green on the real implementation -- covered by SettingsTest. newReaderWebView grew from 6 to 8 parameters to carry the new gesture hooks, which pushed it over detekt's LongParameterList threshold; bundled all of its callbacks into a ReaderWebViewCallbacks data class rather than baselining past it, updating both call sites (ReaderScreen, LinkReaderScreen). ReaderContent gained no new parameter -- it now independently remembers its own Settings instance to persist the pinch-committed size, matching how it already remembers its own db and scope rather than threading them from ReaderScreen. LinkReaderScreen's WebView is untouched: it doesn't read the reader font size setting at all today, so wiring pinch-zoom there would be a separate, unrelated fix. --- .../java/org/terst/feedreader/data/SettingsTest.kt | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/src/test/java/org/terst/feedreader/data/SettingsTest.kt (limited to 'app/src/test') diff --git a/app/src/test/java/org/terst/feedreader/data/SettingsTest.kt b/app/src/test/java/org/terst/feedreader/data/SettingsTest.kt new file mode 100644 index 0000000..5b2048b --- /dev/null +++ b/app/src/test/java/org/terst/feedreader/data/SettingsTest.kt @@ -0,0 +1,32 @@ +package org.terst.feedreader.data + +import org.junit.Assert.assertEquals +import org.junit.Test + +class SettingsTest { + + @Test + fun `pinch zoom with scale factor of 1 leaves the font size unchanged`() { + assertEquals(18, pinchZoomFontSizePx(18, 1.0f)) + } + + @Test + fun `pinching out scales the font size up, rounded to the nearest pixel`() { + assertEquals(22, pinchZoomFontSizePx(20, 1.1f)) + } + + @Test + fun `pinching in scales the font size down, rounded to the nearest pixel`() { + assertEquals(16, pinchZoomFontSizePx(20, 0.8f)) + } + + @Test + fun `pinch zoom result is clamped to the minimum reader font size`() { + assertEquals(READER_FONT_SIZE_RANGE_PX.first, pinchZoomFontSizePx(14, 0.3f)) + } + + @Test + fun `pinch zoom result is clamped to the maximum reader font size`() { + assertEquals(READER_FONT_SIZE_RANGE_PX.last, pinchZoomFontSizePx(28, 3.0f)) + } +} -- cgit v1.2.3