Repository navigation
feat(reader): redesign EPUB reader chrome and progress scrubbing - #1351
Merged
Merged
Conversation
dyphire
added a commit
to kmworks/kmreader-android
that referenced
this pull request
Nov 28, 2026
…e count (#90) Ports the navigation half of the iOS reader redesign (kmworks/kmreader#1351) without its chrome rework: the reader now remembers where every explicit jump started, names its position in pages across the whole book, and keeps split chapters under one title. Return stack. `linkBackStack` lived in the EPUB screen and carried a (chapterIndex, fraction) pair per in-book link, so the return affordance existed for links only: a jump through the table of contents, a bookmark or the progress slider was one-way, and the stack died with the composition. It is now `EpubPositionHistory` — pure push/pop over an immutable list, 50 entries, a 0.005 fraction tolerance so a tap repeated on the same page does not stack — with the state owned by the view model. Every explicit jump pushes (toc, bookmark, slider, in-book link) and nothing else does: page turns and chapter seams stay out, so "return" always means "the place I jumped from" rather than "undo my last page turn". `goToChapter` records only when the chapter actually changes; a same-chapter anchor jump records in the UI, where the page genuinely travels. Whole-book page count. The reader knew a chapter's page count from the paged measure pass and nothing else: "Chapter 3 / 12" was as good as it got, and a scrolled chapter had no page at all. `EpubBookPages` turns per-chapter counts into a running offset list; `resolveEpubBookPages` mixes measured chapters with estimates — a chapter the server placed N positions in gets N x (pages this session has measured / positions those same chapters carried), which absorbs the reader's font size without needing a text-density model — and the result lands in `EpubBookPageProgress(currentPage, totalPages)`. The overlay gained a `BOOK_POSITION` item ("Book 421 / 1,204", all three locales) and the chrome-visible footer now defaults to it, which is where iOS puts its "X of Y". Page-count cache. Reopening a book restarted the total from zero, because only the visited chapters had counts. `EpubPageCountStore` persists href -> pages per book (memory LRU plus cacheDir/epub-page-counts, the same atomic-rename shape as the positions index). Its identity is the spine AND a layout signature (flow style, font size, line height, margins, columns, viewport width, page insets) pushed in by the UI: a page count is a property of the layout that produced it, so a font-size change re-measures instead of printing a stale total. Chapter titles. A chapter split across several spine files named only its head; the tails fell back to "Chapter 13", "Chapter 14" in the contents. Titles now resolve as manifest link -> toc entry for that file (deeper entry wins) -> nearest preceding titled spine item -> positional fallback, and inheritance stops at chapters that carry a title of their own, so front matter cannot borrow the chapter that follows it. Also fixes a pothole this work exposed: a seek that landed inside the current chapter queued `scrollToFraction`, which only a chapter load consumes. The numbers moved while the page stood still, and the queued value also hid the WebView behind its 12s reveal backstop. `seekTo` now returns the fraction for the caller to scroll the live page with and leaves the reload path to chapter switches. Deliberately not ported from the iOS PR: the persistent top/bottom bar shell, the long-press scrubber with chapter ticks and callouts, and the fixed controls labels. The iOS preference-key precomputation has no counterpart here and was not added — overlay preferences serialize only on write, the page theme converts to JS once per chapter load or on a real theme change, and metrics are throttled to 200ms in the page JS, so nothing serializes per frame. Validated with :app:compileDebugKotlin, :app:testDebugUnitTest (16 new cases), :app:assembleDebug and :app:lintDebug. No device run yet: the jump/return behaviour and the page numbers on a real book still need eyes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Redesigns the iOS EPUB reader controls after Apple Books, with faster, more stable navigation and zero page reflow when toggling controls.
X of Ypage counter and an ellipsis menu (Contents, Theme, Settings, Book Info) at the bottom.Side effects:
Contents · %@andepub.overlay.controlsare no longer used and are marked stale inLocalizable.xcstrings; adds%lld of %lld,Chapter %lld, andepub.overlay.item.book_pageacross all 10 supported languages. Removes the unused iOS native overlay label plumbing (native overlay labels remain macOS-only).Validation:
make format,make build(iOS/macOS/tvOS),make localizewith no missing translations, and iPhone simulator verification across WebView and CoreText engines (toggle stability, long-press scrubbing, return jumps, menu sheets, light/dark themes).Includes
make bumpto build 692.