Use previous button for removal of active entry in recent books

This commit is contained in:
jpirnay
2026-03-23 21:16:49 +01:00
parent eadcead501
commit 5d8486ea07
3 changed files with 42 additions and 15 deletions
+9
View File
@@ -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 =
+3
View File
@@ -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<RecentBook>& getBooks() const { return recentBooks; }
+30 -15
View File
@@ -6,15 +6,12 @@
#include <algorithm>
#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<ConfirmationActivity>(renderer, mappedInput, heading, bookTitle), handler);
return;
}
int listSize = static_cast<int>(recentBooks.size());
buttonNavigator.onNextRelease([this, listSize] {
@@ -66,20 +91,10 @@ void RecentBooksActivity::loop() {
requestUpdate();
});
buttonNavigator.onPreviousRelease([this, listSize] {
selectorIndex = ButtonNavigator::previousIndex(static_cast<int>(selectorIndex), listSize);
requestUpdate();
});
buttonNavigator.onNextContinuous([this, listSize, pageItems] {
selectorIndex = ButtonNavigator::nextPageIndex(static_cast<int>(selectorIndex), listSize, pageItems);
requestUpdate();
});
buttonNavigator.onPreviousContinuous([this, listSize, pageItems] {
selectorIndex = ButtonNavigator::previousPageIndex(static_cast<int>(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();