diff --git a/src/activities/home/RecentBooksActivity.cpp b/src/activities/home/RecentBooksActivity.cpp index 22e311a9..b5d081ec 100644 --- a/src/activities/home/RecentBooksActivity.cpp +++ b/src/activities/home/RecentBooksActivity.cpp @@ -41,13 +41,14 @@ void RecentBooksActivity::onEnter() { // Load book titles from recent books list bookTitles.clear(); + bookPaths.clear(); const auto& books = RECENT_BOOKS.getBooks(); bookTitles.reserve(books.size()); + bookPaths.reserve(books.size()); for (const auto& path : books) { // Skip if file no longer exists if (!SdMan.exists(path.c_str())) { - bookTitles.emplace_back("[Missing]"); continue; } @@ -75,6 +76,7 @@ void RecentBooksActivity::onEnter() { } bookTitles.push_back(title); + bookPaths.push_back(path); } selectorIndex = 0; @@ -102,6 +104,7 @@ void RecentBooksActivity::onExit() { vSemaphoreDelete(renderingMutex); renderingMutex = nullptr; bookTitles.clear(); + bookPaths.clear(); } void RecentBooksActivity::loop() { @@ -112,12 +115,11 @@ void RecentBooksActivity::loop() { const bool skipPage = mappedInput.getHeldTime() > SKIP_PAGE_MS; const int pageItems = getPageItems(); - const int bookCount = RECENT_BOOKS.getCount(); + const int bookCount = static_cast(bookTitles.size()); if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { if (bookCount > 0 && selectorIndex < bookCount) { - const auto& books = RECENT_BOOKS.getBooks(); - onSelectBook(books[selectorIndex]); + onSelectBook(bookPaths[selectorIndex]); } } else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) { onGoBack(); @@ -155,7 +157,7 @@ void RecentBooksActivity::render() const { const auto pageWidth = renderer.getScreenWidth(); const int pageItems = getPageItems(); - const int bookCount = RECENT_BOOKS.getCount(); + const int bookCount = static_cast(bookTitles.size()); // Draw header renderer.drawCenteredText(UI_12_FONT_ID, 15, "Recent Books", true, EpdFontFamily::BOLD); diff --git a/src/activities/home/RecentBooksActivity.h b/src/activities/home/RecentBooksActivity.h index 1bb693cf..3e386787 100644 --- a/src/activities/home/RecentBooksActivity.h +++ b/src/activities/home/RecentBooksActivity.h @@ -15,6 +15,7 @@ class RecentBooksActivity final : public Activity { int selectorIndex = 0; bool updateRequired = false; std::vector bookTitles; // Display titles for each book + std::vector bookPaths; // Paths for each visible book (excludes missing) const std::function onGoBack; const std::function onSelectBook; diff --git a/src/main.cpp b/src/main.cpp index a56e15b6..21dc4d20 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -224,7 +224,6 @@ void onGoToSettings() { enterNewActivity(new SettingsActivity(renderer, mappedInputManager, onGoHome)); } -void onGoHome(); void onGoToRecentBooks() { exitActivity(); enterNewActivity(new RecentBooksActivity(renderer, mappedInputManager, onGoHome, onGoToReader));