diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index 08c2f3e0..9dfaaebe 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -19,6 +19,7 @@ #include "RecentBooksStore.h" #include "components/UITheme.h" #include "fontIds.h" +#include "util/BookManager.h" #include "util/BookmarkStore.h" #include "util/Dictionary.h" @@ -264,7 +265,7 @@ void EpubReaderActivity::loop() { exitActivity(); enterNewActivity(new EpubReaderMenuActivity( this->renderer, this->mappedInput, epub->getTitle(), currentPage, totalPages, bookProgressPercent, - SETTINGS.orientation, SETTINGS.fontSize, hasDictionary, isBookmarked, epub->getCachePath(), + SETTINGS.orientation, SETTINGS.fontSize, hasDictionary, isBookmarked, epub->getCachePath(), epub->getPath(), [this](const uint8_t orientation, const uint8_t fontSize) { onReaderMenuBack(orientation, fontSize); }, [this](EpubReaderMenuActivity::MenuAction action) { onReaderMenuConfirm(action); })); } @@ -712,6 +713,36 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction pendingGoHome = true; break; } + case EpubReaderMenuActivity::MenuAction::ARCHIVE_BOOK: { + if (epub) { + BookManager::archiveBook(epub->getPath()); + } + pendingGoHome = true; + break; + } + case EpubReaderMenuActivity::MenuAction::DELETE_BOOK: { + if (epub) { + BookManager::deleteBook(epub->getPath()); + } + pendingGoHome = true; + break; + } + case EpubReaderMenuActivity::MenuAction::MANAGE_BOOK: + break; + case EpubReaderMenuActivity::MenuAction::REINDEX_BOOK: { + if (epub) { + BookManager::reindexBook(epub->getPath(), false); + } + pendingGoHome = true; + break; + } + case EpubReaderMenuActivity::MenuAction::REINDEX_BOOK_FULL: { + if (epub) { + BookManager::reindexBook(epub->getPath(), true); + } + pendingGoHome = true; + break; + } case EpubReaderMenuActivity::MenuAction::SYNC: { if (KOREADER_STORE.hasCredentials()) { const int currentPage = section ? section->currentPage : 0; diff --git a/src/activities/reader/EpubReaderMenuActivity.cpp b/src/activities/reader/EpubReaderMenuActivity.cpp index 265c6b2e..d0f25210 100644 --- a/src/activities/reader/EpubReaderMenuActivity.cpp +++ b/src/activities/reader/EpubReaderMenuActivity.cpp @@ -3,10 +3,12 @@ #include #include +#include "../home/BookManageMenuActivity.h" #include "CrossPointSettings.h" #include "MappedInputManager.h" #include "components/UITheme.h" #include "fontIds.h" +#include "util/BookManager.h" void EpubReaderMenuActivity::onEnter() { ActivityWithSubactivity::onEnter(); @@ -116,6 +118,42 @@ void EpubReaderMenuActivity::loop() { return; } + if (selectedAction == MenuAction::MANAGE_BOOK) { + const bool isArchived = BookManager::isArchived(bookFilePath); + enterNewActivity(new BookManageMenuActivity( + renderer, mappedInput, bookFilePath, isArchived, + [this](BookManageMenuActivity::Action action) { + exitActivity(); + auto cb = onAction; + switch (action) { + case BookManageMenuActivity::Action::ARCHIVE: + cb(MenuAction::ARCHIVE_BOOK); + break; + case BookManageMenuActivity::Action::DELETE: + cb(MenuAction::DELETE_BOOK); + break; + case BookManageMenuActivity::Action::DELETE_CACHE: + cb(MenuAction::DELETE_CACHE); + break; + case BookManageMenuActivity::Action::REINDEX: + cb(MenuAction::REINDEX_BOOK); + break; + case BookManageMenuActivity::Action::REINDEX_FULL: + cb(MenuAction::REINDEX_BOOK_FULL); + break; + case BookManageMenuActivity::Action::UNARCHIVE: + // Unarchive from within reader is unusual but handle gracefully + cb(MenuAction::GO_HOME); + break; + } + }, + [this] { + exitActivity(); + requestUpdate(); + })); + return; + } + // 1. Capture the callback and action locally auto actionCallback = onAction; diff --git a/src/activities/reader/EpubReaderMenuActivity.h b/src/activities/reader/EpubReaderMenuActivity.h index ac7b205b..cc9acdbd 100644 --- a/src/activities/reader/EpubReaderMenuActivity.h +++ b/src/activities/reader/EpubReaderMenuActivity.h @@ -28,12 +28,18 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity { GO_HOME, SYNC, DELETE_CACHE, + MANAGE_BOOK, + ARCHIVE_BOOK, + DELETE_BOOK, + REINDEX_BOOK, + REINDEX_BOOK_FULL, }; explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& title, const int currentPage, const int totalPages, const int bookProgressPercent, const uint8_t currentOrientation, const uint8_t currentFontSize, const bool hasDictionary, const bool isBookmarked, const std::string& bookCachePath, + const std::string& bookFilePath, const std::function& onBack, const std::function& onAction) : ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput), @@ -42,6 +48,7 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity { pendingOrientation(currentOrientation), pendingFontSize(currentFontSize), bookCachePath(bookCachePath), + bookFilePath(bookFilePath), currentPage(currentPage), totalPages(totalPages), bookProgressPercent(bookProgressPercent), @@ -75,6 +82,7 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity { StrId::STR_LANDSCAPE_CCW}; const std::vector fontSizeLabels = {StrId::STR_SMALL, StrId::STR_MEDIUM, StrId::STR_LARGE, StrId::STR_X_LARGE}; std::string bookCachePath; + std::string bookFilePath; // Letterbox fill override: 0xFF = Default (use global), 0 = Dithered, 1 = Solid, 2 = None uint8_t pendingLetterboxFill = BookSettings::USE_GLOBAL; static constexpr int LETTERBOX_FILL_OPTION_COUNT = 4; // Default + 3 modes @@ -132,7 +140,7 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity { items.push_back({MenuAction::GO_TO_PERCENT, StrId::STR_GO_TO_PERCENT}); items.push_back({MenuAction::GO_HOME, StrId::STR_CLOSE_BOOK}); items.push_back({MenuAction::SYNC, StrId::STR_SYNC_PROGRESS}); - items.push_back({MenuAction::DELETE_CACHE, StrId::STR_DELETE_CACHE}); + items.push_back({MenuAction::MANAGE_BOOK, StrId::STR_MANAGE_BOOK}); return items; } };