diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index 18600780..49a352a0 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -300,21 +300,16 @@ void EpubReaderActivity::jumpToPercent(int percent) { } // Compute the overall reading position as a percent of the book. -int EpubReaderActivity::getCurrentPercent() const { - if (!epub || epub->getBookSize() == 0) { - return 0; +float EpubReaderActivity::getBookProgressPercent() const { + if (!epub || epub->getBookSize() == 0 || !section || section->pageCount == 0) { + return 0.0f; } // Estimate within-spine progress based on the current page. - float chapterProgress = 0.0f; - if (section && section->pageCount > 0) { - chapterProgress = static_cast(section->currentPage) / static_cast(section->pageCount); - } + const float chapterProgress = static_cast(section->currentPage) / static_cast(section->pageCount); // Convert to overall progress using cumulative spine sizes. - const float progress = epub->calculateProgress(currentSpineIndex, chapterProgress); - const int percent = static_cast(progress * 100.0f + 0.5f); - return clampPercent(percent); + return epub->calculateProgress(currentSpineIndex, chapterProgress) * 100.0f; } void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action) { @@ -362,7 +357,7 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction } case EpubReaderMenuActivity::MenuAction::GO_TO_PERCENT: { // Launch the slider-based percent selector and return here on confirm/cancel. - const int initialPercent = getCurrentPercent(); + const int initialPercent = clampPercent(static_cast(getBookProgressPercent() + 0.5f)); xSemaphoreTake(renderingMutex, portMAX_DELAY); exitActivity(); enterNewActivity(new EpubReaderPercentSelectionActivity( @@ -515,9 +510,7 @@ void EpubReaderActivity::renderScreen() { if (pendingPercentJump && section->pageCount > 0) { // Apply the pending percent jump now that we know the new section's page count. int newPage = static_cast(pendingSpineProgress * static_cast(section->pageCount)); - if (newPage < 0) { - newPage = 0; - } else if (newPage >= section->pageCount) { + if (newPage >= section->pageCount) { newPage = section->pageCount - 1; } section->currentPage = newPage; @@ -637,8 +630,7 @@ void EpubReaderActivity::renderStatusBar(const int orientedMarginRight, const in int progressTextWidth = 0; // Calculate progress in book - const float sectionChapterProg = static_cast(section->currentPage) / section->pageCount; - const float bookProgress = epub->calculateProgress(currentSpineIndex, sectionChapterProg) * 100; + const float bookProgress = getBookProgressPercent(); if (showProgressText || showProgressPercentage) { // Right aligned text for progress counter diff --git a/src/activities/reader/EpubReaderActivity.h b/src/activities/reader/EpubReaderActivity.h index 76ba95f9..ba615cde 100644 --- a/src/activities/reader/EpubReaderActivity.h +++ b/src/activities/reader/EpubReaderActivity.h @@ -33,11 +33,11 @@ class EpubReaderActivity final : public ActivityWithSubactivity { void renderContents(std::unique_ptr page, int orientedMarginTop, int orientedMarginRight, int orientedMarginBottom, int orientedMarginLeft); void renderStatusBar(int orientedMarginRight, int orientedMarginBottom, int orientedMarginLeft) const; + // Compute overall book progress as a percentage in the range 0-100. + float getBookProgressPercent() const; void saveProgress(int spineIndex, int currentPage, int pageCount); // Jump to a percentage of the book (0-100), mapping it to spine and page. void jumpToPercent(int percent); - // Compute the current reading position as an integer percent (0-100). - int getCurrentPercent() const; void onReaderMenuBack(); void onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action);