Use previous button for removal of active entry in recent books
This commit is contained in:
@@ -40,6 +40,15 @@ void RecentBooksStore::addBook(const std::string& path, const std::string& title
|
|||||||
saveToFile();
|
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,
|
void RecentBooksStore::updateBook(const std::string& path, const std::string& title, const std::string& author,
|
||||||
const std::string& coverBmpPath) {
|
const std::string& coverBmpPath) {
|
||||||
auto it =
|
auto it =
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ class RecentBooksStore {
|
|||||||
void updateBook(const std::string& path, const std::string& title, const std::string& author,
|
void updateBook(const std::string& path, const std::string& title, const std::string& author,
|
||||||
const std::string& coverBmpPath);
|
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)
|
// Get the list of recent books (most recent first)
|
||||||
const std::vector<RecentBook>& getBooks() const { return recentBooks; }
|
const std::vector<RecentBook>& getBooks() const { return recentBooks; }
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,12 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "../util/ConfirmationActivity.h"
|
||||||
#include "MappedInputManager.h"
|
#include "MappedInputManager.h"
|
||||||
#include "RecentBooksStore.h"
|
#include "RecentBooksStore.h"
|
||||||
#include "components/UITheme.h"
|
#include "components/UITheme.h"
|
||||||
#include "fontIds.h"
|
#include "fontIds.h"
|
||||||
|
|
||||||
namespace {
|
|
||||||
constexpr unsigned long GO_HOME_MS = 1000;
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void RecentBooksActivity::loadRecentBooks() {
|
void RecentBooksActivity::loadRecentBooks() {
|
||||||
recentBooks.clear();
|
recentBooks.clear();
|
||||||
const auto& books = RECENT_BOOKS.getBooks();
|
const auto& books = RECENT_BOOKS.getBooks();
|
||||||
@@ -59,6 +56,34 @@ void RecentBooksActivity::loop() {
|
|||||||
onGoHome();
|
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());
|
int listSize = static_cast<int>(recentBooks.size());
|
||||||
|
|
||||||
buttonNavigator.onNextRelease([this, listSize] {
|
buttonNavigator.onNextRelease([this, listSize] {
|
||||||
@@ -66,20 +91,10 @@ void RecentBooksActivity::loop() {
|
|||||||
requestUpdate();
|
requestUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonNavigator.onPreviousRelease([this, listSize] {
|
|
||||||
selectorIndex = ButtonNavigator::previousIndex(static_cast<int>(selectorIndex), listSize);
|
|
||||||
requestUpdate();
|
|
||||||
});
|
|
||||||
|
|
||||||
buttonNavigator.onNextContinuous([this, listSize, pageItems] {
|
buttonNavigator.onNextContinuous([this, listSize, pageItems] {
|
||||||
selectorIndex = ButtonNavigator::nextPageIndex(static_cast<int>(selectorIndex), listSize, pageItems);
|
selectorIndex = ButtonNavigator::nextPageIndex(static_cast<int>(selectorIndex), listSize, pageItems);
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonNavigator.onPreviousContinuous([this, listSize, pageItems] {
|
|
||||||
selectorIndex = ButtonNavigator::previousPageIndex(static_cast<int>(selectorIndex), listSize, pageItems);
|
|
||||||
requestUpdate();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecentBooksActivity::render(RenderLock&&) {
|
void RecentBooksActivity::render(RenderLock&&) {
|
||||||
@@ -105,7 +120,7 @@ void RecentBooksActivity::render(RenderLock&&) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Help text
|
// 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);
|
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||||
|
|
||||||
renderer.displayBuffer();
|
renderer.displayBuffer();
|
||||||
|
|||||||
Reference in New Issue
Block a user