From 5d8486ea0700def46b63c0307839dea4f02c0e9a Mon Sep 17 00:00:00 2001 From: jpirnay Date: Mon, 23 Mar 2026 21:16:49 +0100 Subject: [PATCH] Use previous button for removal of active entry in recent books --- src/RecentBooksStore.cpp | 9 +++++ src/RecentBooksStore.h | 3 ++ src/activities/home/RecentBooksActivity.cpp | 45 ++++++++++++++------- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/RecentBooksStore.cpp b/src/RecentBooksStore.cpp index f5a2c048..04c150ca 100644 --- a/src/RecentBooksStore.cpp +++ b/src/RecentBooksStore.cpp @@ -40,6 +40,15 @@ void RecentBooksStore::addBook(const std::string& path, const std::string& title saveToFile(); } +void RecentBooksStore::removeBook(const std::string& path) { + auto it = + std::find_if(recentBooks.begin(), recentBooks.end(), [&](const RecentBook& book) { return book.path == path; }); + if (it != recentBooks.end()) { + recentBooks.erase(it); + saveToFile(); + } +} + void RecentBooksStore::updateBook(const std::string& path, const std::string& title, const std::string& author, const std::string& coverBmpPath) { auto it = diff --git a/src/RecentBooksStore.h b/src/RecentBooksStore.h index 5d98ce83..4d916f99 100644 --- a/src/RecentBooksStore.h +++ b/src/RecentBooksStore.h @@ -37,6 +37,9 @@ class RecentBooksStore { void updateBook(const std::string& path, const std::string& title, const std::string& author, const std::string& coverBmpPath); + // Remove a book from the recent list by path + void removeBook(const std::string& path); + // Get the list of recent books (most recent first) const std::vector& getBooks() const { return recentBooks; } diff --git a/src/activities/home/RecentBooksActivity.cpp b/src/activities/home/RecentBooksActivity.cpp index 6ba8f8cf..563e3bdf 100644 --- a/src/activities/home/RecentBooksActivity.cpp +++ b/src/activities/home/RecentBooksActivity.cpp @@ -6,15 +6,12 @@ #include +#include "../util/ConfirmationActivity.h" #include "MappedInputManager.h" #include "RecentBooksStore.h" #include "components/UITheme.h" #include "fontIds.h" -namespace { -constexpr unsigned long GO_HOME_MS = 1000; -} // namespace - void RecentBooksActivity::loadRecentBooks() { recentBooks.clear(); const auto& books = RECENT_BOOKS.getBooks(); @@ -59,6 +56,34 @@ void RecentBooksActivity::loop() { onGoHome(); } + // Left button: remove selected book from recent list + if (!recentBooks.empty() && selectorIndex < recentBooks.size() && + (mappedInput.wasReleased(MappedInputManager::Button::Left) || + mappedInput.wasReleased(MappedInputManager::Button::Up))) { + const std::string bookPath = recentBooks[selectorIndex].path; + const std::string bookTitle = recentBooks[selectorIndex].title; + + auto handler = [this, bookPath](const ActivityResult& res) { + if (!res.isCancelled) { + LOG_DBG("RBA", "Removing from recent books: %s", bookPath.c_str()); + RECENT_BOOKS.removeBook(bookPath); + loadRecentBooks(); + if (recentBooks.empty()) { + selectorIndex = 0; + } else if (selectorIndex >= recentBooks.size()) { + selectorIndex = recentBooks.size() - 1; + } + requestUpdate(true); + } else { + LOG_DBG("RBA", "Remove cancelled by user"); + } + }; + + std::string heading = tr(STR_DELETE) + std::string("? "); + startActivityForResult(std::make_unique(renderer, mappedInput, heading, bookTitle), handler); + return; + } + int listSize = static_cast(recentBooks.size()); buttonNavigator.onNextRelease([this, listSize] { @@ -66,20 +91,10 @@ void RecentBooksActivity::loop() { requestUpdate(); }); - buttonNavigator.onPreviousRelease([this, listSize] { - selectorIndex = ButtonNavigator::previousIndex(static_cast(selectorIndex), listSize); - requestUpdate(); - }); - buttonNavigator.onNextContinuous([this, listSize, pageItems] { selectorIndex = ButtonNavigator::nextPageIndex(static_cast(selectorIndex), listSize, pageItems); requestUpdate(); }); - - buttonNavigator.onPreviousContinuous([this, listSize, pageItems] { - selectorIndex = ButtonNavigator::previousPageIndex(static_cast(selectorIndex), listSize, pageItems); - requestUpdate(); - }); } void RecentBooksActivity::render(RenderLock&&) { @@ -105,7 +120,7 @@ void RecentBooksActivity::render(RenderLock&&) { } // Help text - const auto labels = mappedInput.mapLabels(tr(STR_HOME), tr(STR_OPEN), tr(STR_DIR_UP), tr(STR_DIR_DOWN)); + const auto labels = mappedInput.mapLabels(tr(STR_HOME), tr(STR_OPEN), tr(STR_DELETE), tr(STR_DIR_DOWN)); GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4); renderer.displayBuffer();