Skip to content

Feature/mupdf switch - #12

Merged
backsofangels merged 14 commits into
mainfrom
feature/mupdf-switch
Nov 25, 2026
Merged

backsofangels merged 14 commits into
mainfrom
feature/mupdf-switch

Conversation

@backsofangels

Copy link
Copy Markdown
Owner

PR: Migrate Reading Engine to MuPDF with Full Design Parity and Position Persistence

Summary

Migrates the core document reading engine from Readium to MuPDF (:lib module) while maintaining complete design-language parity, UI/UX consistency, and state persistence with the main application.

This PR introduces NosferatuDocumentActivity—a host subclass integrating MuPDF's DocumentActivity with Jetpack Compose controls, unified theming (Light/Cream/Dark), persistent custom status bar (time + battery), bookmark management, non-shifting overlay chrome, and automatic reading position synchronization to the local Room database.


Key Changes

1. Engine & Host Architecture

  • MuPDF Module Integration (:lib): Added MuPDF mini engine handling reflowable and fixed-layout documents (EPUB, PDF, etc.) with native rendering.
  • NosferatuDocumentActivity: Custom subclass extending DocumentActivity bridging legacy Android Activity lifecycles with Compose:
    • Manually implements LifecycleOwner, ViewModelStoreOwner, and SavedStateRegistryOwner with ViewTree owner registrations on window.decorView.
    • Configured in AndroidManifest.xml with Theme.MuPdfReader and hardware acceleration disabled (MuPDF requirement).
    • Launched from MainActivity.openBook() with BOOK_ID intent extra.

2. Reading Position Persistence

  • Auto-save on Exit: Saves reading progress during onStop() before activity backgrounding.
  • Room DB Sync: Formats position payload as {"page": N, "totalPages": M} and dispatches to LibraryViewModel.saveBookPosition(bookId, locationJson, progression) on Dispatchers.IO.

3. Design Language & UI Parity

  • Custom Status Bar: Integrated header bar showing dynamic 1-second system clock (HH:mm) and live battery percentage with indicator bar via BatteryManager receiver.
  • Chrome Overlay (Zero-Shift Layout): Restructured document_activity.xml to an overlay layout pattern (elevation="8dp" on top/bottom bars and reader_container spanning full height), preventing reader content resizing/reflowing when toggling chrome visibility.
  • Compose Settings Overlay: Reuses ReaderTextSettings (font scaling slider mapped to MuPDF layoutEm) and SingleChoiceOptionRow (theme switcher) in a floating Compose overlay.
  • Theme & Color Token Parity:
    • Aligned Cream theme: split root page background (#FAF4E8) and chrome bar background (#EDE0C8).
    • Updated ReaderUiController.fallbackPaletteFor() for Light (#FFFFFF), Cream (#FAF4E8), and Dark (#222222) themes.
    • Replaced hardcoded values with semantic theme attributes (?attr/readerBackgroundColor, ?attr/readerTextColor, etc.).
    • Standardized dimensions (reader_bottom_padding = 20dp) and view IDs (page_seekbar → menu_seek_bar).

4. Bookmarks

  • Implemented page-level bookmarking via BookmarkStore keyed by URI + page:N.
  • Wired header bookmark icon toggle (updating filled/outline state) and bookmark navigation dialog.

Verification & Testing

  • Clean Build: Verified with ./gradlew assembleDebug (0 errors, 0 warnings).
  • Lifecycle & Resource Cleanup: Verified timer cancellation and battery BroadcastReceiver unregistration in onDestroy().
  • Position Persistence: Confirmed position and progression persist to Room DB on back/home navigation.
  • Layout Stability: Verified no UI reflow or page jumps occur when tapping to toggle reader chrome.
  • Theming: Tested Light, Cream, and Dark theme switches across document views and Compose overlay.

Related Issue / Commits

  • Closes reading engine migration roadmap
  • References: ef4aefc (feat!: migrate reading engine to mupdf)

@backsofangels
backsofangels merged commit 4771444 into main Nov 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant