mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
refactor: Rename getCurrentPercent to getBookProgressPercent and update its logic for improved accuracy
This commit is contained in:
parent
78e9c7c733
commit
f7a0c8ac65
@ -300,21 +300,16 @@ void EpubReaderActivity::jumpToPercent(int percent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compute the overall reading position as a percent of the book.
|
// Compute the overall reading position as a percent of the book.
|
||||||
int EpubReaderActivity::getCurrentPercent() const {
|
float EpubReaderActivity::getBookProgressPercent() const {
|
||||||
if (!epub || epub->getBookSize() == 0) {
|
if (!epub || epub->getBookSize() == 0 || !section || section->pageCount == 0) {
|
||||||
return 0;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Estimate within-spine progress based on the current page.
|
// Estimate within-spine progress based on the current page.
|
||||||
float chapterProgress = 0.0f;
|
const float chapterProgress = static_cast<float>(section->currentPage) / static_cast<float>(section->pageCount);
|
||||||
if (section && section->pageCount > 0) {
|
|
||||||
chapterProgress = static_cast<float>(section->currentPage) / static_cast<float>(section->pageCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to overall progress using cumulative spine sizes.
|
// Convert to overall progress using cumulative spine sizes.
|
||||||
const float progress = epub->calculateProgress(currentSpineIndex, chapterProgress);
|
return epub->calculateProgress(currentSpineIndex, chapterProgress) * 100.0f;
|
||||||
const int percent = static_cast<int>(progress * 100.0f + 0.5f);
|
|
||||||
return clampPercent(percent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action) {
|
void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action) {
|
||||||
@ -362,7 +357,7 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction
|
|||||||
}
|
}
|
||||||
case EpubReaderMenuActivity::MenuAction::GO_TO_PERCENT: {
|
case EpubReaderMenuActivity::MenuAction::GO_TO_PERCENT: {
|
||||||
// Launch the slider-based percent selector and return here on confirm/cancel.
|
// Launch the slider-based percent selector and return here on confirm/cancel.
|
||||||
const int initialPercent = getCurrentPercent();
|
const int initialPercent = clampPercent(static_cast<int>(getBookProgressPercent() + 0.5f));
|
||||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||||
exitActivity();
|
exitActivity();
|
||||||
enterNewActivity(new EpubReaderPercentSelectionActivity(
|
enterNewActivity(new EpubReaderPercentSelectionActivity(
|
||||||
@ -515,9 +510,7 @@ void EpubReaderActivity::renderScreen() {
|
|||||||
if (pendingPercentJump && section->pageCount > 0) {
|
if (pendingPercentJump && section->pageCount > 0) {
|
||||||
// Apply the pending percent jump now that we know the new section's page count.
|
// Apply the pending percent jump now that we know the new section's page count.
|
||||||
int newPage = static_cast<int>(pendingSpineProgress * static_cast<float>(section->pageCount));
|
int newPage = static_cast<int>(pendingSpineProgress * static_cast<float>(section->pageCount));
|
||||||
if (newPage < 0) {
|
if (newPage >= section->pageCount) {
|
||||||
newPage = 0;
|
|
||||||
} else if (newPage >= section->pageCount) {
|
|
||||||
newPage = section->pageCount - 1;
|
newPage = section->pageCount - 1;
|
||||||
}
|
}
|
||||||
section->currentPage = newPage;
|
section->currentPage = newPage;
|
||||||
@ -637,8 +630,7 @@ void EpubReaderActivity::renderStatusBar(const int orientedMarginRight, const in
|
|||||||
int progressTextWidth = 0;
|
int progressTextWidth = 0;
|
||||||
|
|
||||||
// Calculate progress in book
|
// Calculate progress in book
|
||||||
const float sectionChapterProg = static_cast<float>(section->currentPage) / section->pageCount;
|
const float bookProgress = getBookProgressPercent();
|
||||||
const float bookProgress = epub->calculateProgress(currentSpineIndex, sectionChapterProg) * 100;
|
|
||||||
|
|
||||||
if (showProgressText || showProgressPercentage) {
|
if (showProgressText || showProgressPercentage) {
|
||||||
// Right aligned text for progress counter
|
// Right aligned text for progress counter
|
||||||
|
|||||||
@ -33,11 +33,11 @@ class EpubReaderActivity final : public ActivityWithSubactivity {
|
|||||||
void renderContents(std::unique_ptr<Page> page, int orientedMarginTop, int orientedMarginRight,
|
void renderContents(std::unique_ptr<Page> page, int orientedMarginTop, int orientedMarginRight,
|
||||||
int orientedMarginBottom, int orientedMarginLeft);
|
int orientedMarginBottom, int orientedMarginLeft);
|
||||||
void renderStatusBar(int orientedMarginRight, int orientedMarginBottom, int orientedMarginLeft) const;
|
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);
|
void saveProgress(int spineIndex, int currentPage, int pageCount);
|
||||||
// Jump to a percentage of the book (0-100), mapping it to spine and page.
|
// Jump to a percentage of the book (0-100), mapping it to spine and page.
|
||||||
void jumpToPercent(int percent);
|
void jumpToPercent(int percent);
|
||||||
// Compute the current reading position as an integer percent (0-100).
|
|
||||||
int getCurrentPercent() const;
|
|
||||||
void onReaderMenuBack();
|
void onReaderMenuBack();
|
||||||
void onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action);
|
void onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user