A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Implement silent pre-indexing for the next chapter in EpubReaderActivity (#979)

## Summary

* A simple tweak to pre-index the next chapter silently during normal
reading.
* Triggers silent pre-indexing of the next chapter when the penultimate
page of a chapter is rendered to reduce visible interruptions.
* Keeps existing indexing with popup when a reader jumps directly into
an unindexed chapter.

## Additional Context

* Reader input is temporarily blocked during silent indexing to avoid
navigation/index state conflicts.
* The penultimate page is used because readers typically spend longer
there than on the final page.
* This change optimizes linear reading flow while preserving reliable
indexing for non-linear navigation.

## Possible Improvements

* Add a setting for First Page Indexing vs Penultimate Page Pre-indexing
* Display an indexing icon in the status bar instead of using a popup
that overlaps book text.

Tested on device:

https://www.dropbox.com/scl/fi/29g5kjqgsi5e4hgujv38u/Silent-Indexing.MOV?rlkey=yemi4mosmev5vicaa7gpe49qw&dl=0

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**YES**_

---------

Co-authored-by: Jake Kenneally <jakekenneally@gmail.com>

authored by

LSTAR
Jake Kenneally
and committed by
GitHub
8dd365b4 9665dd74

+37 -3
+36 -3
src/activities/reader/EpubReaderActivity.cpp
··· 530 530 orientedMarginBottom += std::max(SETTINGS.screenMargin, statusBarHeight); 531 531 } 532 532 533 + const uint16_t viewportWidth = renderer.getScreenWidth() - orientedMarginLeft - orientedMarginRight; 534 + const uint16_t viewportHeight = renderer.getScreenHeight() - orientedMarginTop - orientedMarginBottom; 535 + 533 536 if (!section) { 534 537 const auto filepath = epub->getSpineItem(currentSpineIndex).href; 535 538 LOG_DBG("ERS", "Loading file: %s, index: %d", filepath.c_str(), currentSpineIndex); 536 539 section = std::unique_ptr<Section>(new Section(epub, currentSpineIndex, renderer)); 537 - 538 - const uint16_t viewportWidth = renderer.getScreenWidth() - orientedMarginLeft - orientedMarginRight; 539 - const uint16_t viewportHeight = renderer.getScreenHeight() - orientedMarginTop - orientedMarginBottom; 540 540 541 541 if (!section->loadSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(), 542 542 SETTINGS.extraParagraphSpacing, SETTINGS.paragraphAlignment, viewportWidth, ··· 635 635 renderContents(std::move(p), orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft); 636 636 LOG_DBG("ERS", "Rendered page in %dms", millis() - start); 637 637 } 638 + silentIndexNextChapterIfNeeded(viewportWidth, viewportHeight); 638 639 saveProgress(currentSpineIndex, section->currentPage, section->pageCount); 639 640 640 641 if (pendingScreenshot) { 641 642 pendingScreenshot = false; 642 643 ScreenshotUtil::takeScreenshot(renderer); 644 + } 645 + } 646 + 647 + void EpubReaderActivity::silentIndexNextChapterIfNeeded(const uint16_t viewportWidth, const uint16_t viewportHeight) { 648 + if (!epub || !section || section->pageCount < 2) { 649 + return; 650 + } 651 + 652 + // Build the next chapter cache while the penultimate page is on screen. 653 + if (section->currentPage != section->pageCount - 2) { 654 + return; 655 + } 656 + 657 + const int nextSpineIndex = currentSpineIndex + 1; 658 + if (nextSpineIndex < 0 || nextSpineIndex >= epub->getSpineItemsCount()) { 659 + return; 660 + } 661 + 662 + Section nextSection(epub, nextSpineIndex, renderer); 663 + if (nextSection.loadSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(), 664 + SETTINGS.extraParagraphSpacing, SETTINGS.paragraphAlignment, viewportWidth, 665 + viewportHeight, SETTINGS.hyphenationEnabled, SETTINGS.embeddedStyle, 666 + SETTINGS.imageRendering)) { 667 + return; 668 + } 669 + 670 + LOG_DBG("ERS", "Silently indexing next chapter: %d", nextSpineIndex); 671 + if (!nextSection.createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(), 672 + SETTINGS.extraParagraphSpacing, SETTINGS.paragraphAlignment, viewportWidth, 673 + viewportHeight, SETTINGS.hyphenationEnabled, SETTINGS.embeddedStyle, 674 + SETTINGS.imageRendering)) { 675 + LOG_ERR("ERS", "Failed silent indexing for chapter: %d", nextSpineIndex); 643 676 } 644 677 } 645 678
+1
src/activities/reader/EpubReaderActivity.h
··· 41 41 void renderContents(std::unique_ptr<Page> page, int orientedMarginTop, int orientedMarginRight, 42 42 int orientedMarginBottom, int orientedMarginLeft); 43 43 void renderStatusBar() const; 44 + void silentIndexNextChapterIfNeeded(uint16_t viewportWidth, uint16_t viewportHeight); 44 45 void saveProgress(int spineIndex, int currentPage, int pageCount); 45 46 // Jump to a percentage of the book (0-100), mapping it to spine and page. 46 47 void jumpToPercent(int percent);