feat: add setting that allows removing books from recent list when read (#2043)
This commit is contained in:
@@ -231,6 +231,8 @@ class CrossPointSettings {
|
||||
char sdFontFamilyName[32] = "";
|
||||
// Show hidden files/directories (starting with '.') in the file browser (0 = hidden, 1 = show)
|
||||
uint8_t showHiddenFiles = 0;
|
||||
// Remove a book from the Recent Books list when its End-of-Book screen is reached (0 = off, 1 = on)
|
||||
uint8_t removeReadBooksFromRecents = 0;
|
||||
// Move epub to /Read/ folder on SD card when finished (0 = disabled, 1 = enabled)
|
||||
uint8_t moveFinishedToReadFolder = 0;
|
||||
// Image rendering mode in EPUB reader
|
||||
|
||||
@@ -56,6 +56,21 @@ void RecentBooksStore::updateBook(const std::string& path, const std::string& ti
|
||||
}
|
||||
}
|
||||
|
||||
bool RecentBooksStore::removeByPath(const std::string& path) {
|
||||
auto it =
|
||||
std::find_if(recentBooks.begin(), recentBooks.end(), [&](const RecentBook& book) { return book.path == path; });
|
||||
if (it == recentBooks.end()) {
|
||||
return false;
|
||||
}
|
||||
recentBooks.erase(it);
|
||||
if (!saveToFile()) {
|
||||
// In-memory removal succeeded; persistence is best-effort here (consistent with
|
||||
// addBook/updateBook). Log the failure but still report the entry as removed.
|
||||
LOG_ERR("RBS", "Failed to persist removal of recent book: %s", path.c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RecentBooksStore::updatePath(const std::string& oldPath, const std::string& newPath,
|
||||
const std::string& oldCachePath, const std::string& newCachePath) {
|
||||
auto it = std::find_if(recentBooks.begin(), recentBooks.end(),
|
||||
|
||||
@@ -37,6 +37,11 @@ class RecentBooksStore {
|
||||
void updateBook(const std::string& path, const std::string& title, const std::string& author,
|
||||
const std::string& coverBmpPath);
|
||||
|
||||
// Remove the entry whose path matches (used when a book is finished/read).
|
||||
// Returns true if an entry was found and removed (no-op + false otherwise).
|
||||
// Persistence is best-effort: a failed save is logged, not reflected in the return.
|
||||
bool removeByPath(const std::string& path);
|
||||
|
||||
// Repoint an entry's path (and coverBmpPath, if it lived under the old cache dir) after the
|
||||
// backing file and cache dir were moved on disk. No-op if no entry matches oldPath.
|
||||
// Persists on success. Keeps the entry's list position (does not reorder).
|
||||
|
||||
@@ -178,6 +178,8 @@ inline std::vector<SettingInfo> getSettingsList(const SdCardFontRegistry* regist
|
||||
"sleepTimeout", StrId::STR_CAT_SYSTEM),
|
||||
SettingInfo::Toggle(StrId::STR_SHOW_HIDDEN_FILES, &CrossPointSettings::showHiddenFiles, "showHiddenFiles",
|
||||
StrId::STR_CAT_SYSTEM),
|
||||
SettingInfo::Toggle(StrId::STR_REMOVE_READ_FROM_RECENTS, &CrossPointSettings::removeReadBooksFromRecents,
|
||||
"removeReadBooksFromRecents", StrId::STR_CAT_SYSTEM),
|
||||
SettingInfo::Toggle(StrId::STR_MOVE_FINISHED_TO_READ, &CrossPointSettings::moveFinishedToReadFolder,
|
||||
"moveFinishedToReadFolder", StrId::STR_CAT_SYSTEM),
|
||||
|
||||
|
||||
@@ -190,10 +190,30 @@ void EpubReaderActivity::loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Being on the "End of Book" screen (currentSpineIndex == spine count) means the book is
|
||||
// finished. Arm the move here so ANY exit path (Back, Home, file browser) relocates the
|
||||
// book in onExit(); paging back off the end screen disarms it (book not actually finished).
|
||||
if (currentSpineIndex > 0 && currentSpineIndex >= epub->getSpineItemsCount()) {
|
||||
// End-of-Book screen reached (currentSpineIndex == spine count) means the book is
|
||||
// finished. Two independent finished-book features key off this same condition.
|
||||
const bool atEndOfBook = currentSpineIndex > 0 && currentSpineIndex >= epub->getSpineItemsCount();
|
||||
|
||||
// Drop this book from the Recent Books list; if the reader then pages back into the book,
|
||||
// re-add it. So removal only sticks if the reader leaves while still on the End-of-Book
|
||||
// screen. Acts only on the transition (guarded by recentsEntryRemoved) — no per-frame writes.
|
||||
if (SETTINGS.removeReadBooksFromRecents) {
|
||||
if (atEndOfBook && !recentsEntryRemoved) {
|
||||
// Only treat the book as "removed by us" if it was actually in the list, so the
|
||||
// re-add branch below doesn't insert a book the feature never removed.
|
||||
recentsEntryRemoved = RECENT_BOOKS.removeByPath(epub->getPath());
|
||||
} else if (!atEndOfBook && recentsEntryRemoved) {
|
||||
// Re-add (goes to front of the list via addBook — accepted ordering side effect).
|
||||
RECENT_BOOKS.addBook(epub->getPath(), epub->getTitle(), epub->getAuthor(), epub->getThumbBmpPath());
|
||||
recentsEntryRemoved = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Arm the move here so ANY exit path (Back, Home, file browser) relocates the book into
|
||||
// /Read/ in onExit(); paging back off the end screen disarms it (book not actually
|
||||
// finished). If removeReadBooksFromRecents also fired, RecentBooksStore::updatePath in the
|
||||
// move path becomes a safe no-op since the entry was already removed.
|
||||
if (atEndOfBook) {
|
||||
pendingReadFolderMove = SETTINGS.moveFinishedToReadFolder && !isInReadFolder(epub->getPath());
|
||||
} else {
|
||||
pendingReadFolderMove = false;
|
||||
|
||||
@@ -31,6 +31,9 @@ class EpubReaderActivity final : public Activity {
|
||||
bool pendingSyncSaveError = false;
|
||||
bool skipNextButtonCheck = false; // Skip button processing for one frame after subactivity exit
|
||||
bool automaticPageTurnActive = false;
|
||||
// Tracks whether this book is currently removed from Recent Books by the
|
||||
// removeReadBooksFromRecents feature (set at End-of-Book, cleared if paged back in).
|
||||
bool recentsEntryRemoved = false;
|
||||
// Set when the reader is left at end-of-book and SETTINGS.moveFinishedToReadFolder is on.
|
||||
// Consumed in onExit() to relocate the finished book into /Read/.
|
||||
bool pendingReadFolderMove = false;
|
||||
|
||||
Reference in New Issue
Block a user