From a5fa7adcd764710350ce48fab76981145b9877d3 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Sat, 16 May 2026 12:11:00 +0200 Subject: [PATCH] Change mark as read behaviour --- src/activities/home/FileBrowserActivity.cpp | 62 +++++++++++++++++++-- src/activities/settings/SettingInfo.cpp | 7 ++- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/activities/home/FileBrowserActivity.cpp b/src/activities/home/FileBrowserActivity.cpp index 335dbe11..39eec730 100644 --- a/src/activities/home/FileBrowserActivity.cpp +++ b/src/activities/home/FileBrowserActivity.cpp @@ -13,6 +13,7 @@ #include "../ActivityManager.h" #include "../ActivityResult.h" +#include "../reader/FinishedBookActivity.h" #include "../settings/SdFirmwareUpdateActivity.h" #include "../util/BmpViewerActivity.h" #include "../util/ConfirmationActivity.h" @@ -376,7 +377,6 @@ void FileBrowserActivity::handleContextMenuAction(int action, const std::string& } case Action::MarkAsRead: doMarkAsRead(fullPath); - requestUpdate(); return; case Action::Info: startActivityForResult(std::make_unique(renderer, mappedInput, fullPath), @@ -431,13 +431,63 @@ void FileBrowserActivity::doMarkAsRead(const std::string& fullPath) { } FsFile f; - if (Storage.openFileForWrite("FBR", cachePath + "/progress.bin", f)) { - f.write(data, dataLen); - f.close(); - LOG_INF("FBR", "Marked as read: %s", fullPath.c_str()); - } else { + if (!Storage.openFileForWrite("FBR", cachePath + "/progress.bin", f)) { LOG_ERR("FBR", "Failed to write progress for mark-as-read: %s", fullPath.c_str()); + return; } + f.write(data, dataLen); + f.close(); + LOG_INF("FBR", "Marked as read: %s", fullPath.c_str()); + + // Series/index unknown without loading — findNextBook falls back to alphabetical order. + const std::string nextBookPath = BookFinished::findNextBookInDirectory(fullPath, {}, {}); + startActivityForResult(std::make_unique(renderer, mappedInput, fullPath, nextBookPath), + [this, fullPath, nextBookPath](const ActivityResult& result) { + if (result.isCancelled) { + requestUpdate(); + return; + } + const auto& menuResult = std::get(result.data); + if (menuResult.action == static_cast(BookFinished::FinishedBookAction::GoHome)) { + if (SETTINGS.moveFinishedBooksToCompleted) { + std::string movedPath; + BookFinished::moveFinishedBookToCompleted(fullPath, movedPath); + } + if (SETTINGS.removeFinishedBooksFromRecents) { + RECENT_BOOKS.removeBook(fullPath); + } + onGoHome(); + return; + } + if (menuResult.action == static_cast(BookFinished::FinishedBookAction::OpenNextBook) && + !nextBookPath.empty()) { + if (SETTINGS.moveFinishedBooksToCompleted) { + std::string movedPath; + BookFinished::moveFinishedBookToCompleted(fullPath, movedPath); + } + if (SETTINGS.removeFinishedBooksFromRecents) { + RECENT_BOOKS.removeBook(fullPath); + } + ReturnHint hint; + hint.target = ReturnTo::FileBrowser; + hint.path = basepath; + activityManager.replaceWithReader(nextBookPath, std::move(hint)); + return; + } + // Stay — apply side effects then reload the list (file may have moved to /COMPLETED). + if (SETTINGS.moveFinishedBooksToCompleted) { + std::string movedPath; + BookFinished::moveFinishedBookToCompleted(fullPath, movedPath); + } + if (SETTINGS.removeFinishedBooksFromRecents) { + RECENT_BOOKS.removeBook(fullPath); + } + loadFiles(); + if (selectorIndex >= static_cast(files.size())) { + selectorIndex = files.empty() ? 0 : static_cast(files.size()) - 1; + } + requestUpdate(true); + }); } void FileBrowserActivity::doSetAsSleepCover(const std::string& fullPath) { diff --git a/src/activities/settings/SettingInfo.cpp b/src/activities/settings/SettingInfo.cpp index 912f8556..086af934 100644 --- a/src/activities/settings/SettingInfo.cpp +++ b/src/activities/settings/SettingInfo.cpp @@ -6,8 +6,11 @@ #include "components/UITheme.h" std::string SettingInfo::getTitle() const { - const auto t = I18N.get(nameId); - return isSeparator ? UITheme::makeSeparatorTitle(t) : t; + if (isSeparator) { + if (nameId == StrId::STR_NONE_OPT) return UITheme::makeSeparatorTitle(std::string{}); + return UITheme::makeSeparatorTitle(std::string{I18N.get(nameId)}); + } + return std::string{I18N.get(nameId)}; } std::string SettingInfo::getDisplayValue() const {