mod: Phase 2b - adapt HomeActivity, EpubReaderMenuActivity, EpubReaderActivity
HomeActivity: Add mod features on top of upstream ActivityManager pattern: - Multi-server OPDS support (OpdsServerStore instead of single URL) - Long-press recent book for BookManageMenuActivity - Long-press Browse Files to open archive folder - Placeholder cover generation for books without covers - startActivityForResult pattern for manage menu EpubReaderMenuActivity: Replace upstream menu items with mod menu: - Add/Remove Bookmark, Lookup Word, Go to Bookmark, Lookup History - Table of Contents, Toggle Orientation, Toggle Font Size - Close Book, Delete Dictionary Cache - Pass isBookmarked and currentFontSize to constructor - Show current orientation/font size value inline EpubReaderActivity: Add mod action handlers: - Bookmark add/remove via BookmarkStore - Go to Bookmark via EpubReaderBookmarkSelectionActivity - Dictionary word lookup via DictionaryWordSelectActivity - Lookup history via LookedUpWordsActivity - Delete dictionary cache - Font size toggle with section re-layout - Close Book action ActivityResult: Add fontSize field to MenuResult Made-with: Cursor
This commit is contained in:
@@ -10,16 +10,21 @@
|
||||
|
||||
#include "CrossPointSettings.h"
|
||||
#include "CrossPointState.h"
|
||||
#include "DictionaryWordSelectActivity.h"
|
||||
#include "EpubReaderBookmarkSelectionActivity.h"
|
||||
#include "EpubReaderChapterSelectionActivity.h"
|
||||
#include "EpubReaderFootnotesActivity.h"
|
||||
#include "EpubReaderPercentSelectionActivity.h"
|
||||
#include "KOReaderCredentialStore.h"
|
||||
#include "KOReaderSyncActivity.h"
|
||||
#include "LookedUpWordsActivity.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "QrDisplayActivity.h"
|
||||
#include "RecentBooksStore.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
#include "util/BookmarkStore.h"
|
||||
#include "util/Dictionary.h"
|
||||
#include "util/ScreenshotUtil.h"
|
||||
|
||||
namespace {
|
||||
@@ -164,13 +169,16 @@ void EpubReaderActivity::loop() {
|
||||
bookProgress = epub->calculateProgress(currentSpineIndex, chapterProgress) * 100.0f;
|
||||
}
|
||||
const int bookProgressPercent = clampPercent(static_cast<int>(bookProgress + 0.5f));
|
||||
const bool isBookmarked =
|
||||
section ? BookmarkStore::hasBookmark(epub->getCachePath(), currentSpineIndex, section->currentPage) : false;
|
||||
startActivityForResult(std::make_unique<EpubReaderMenuActivity>(
|
||||
renderer, mappedInput, epub->getTitle(), currentPage, totalPages, bookProgressPercent,
|
||||
SETTINGS.orientation, !currentPageFootnotes.empty()),
|
||||
SETTINGS.orientation, !currentPageFootnotes.empty(), isBookmarked, SETTINGS.fontSize),
|
||||
[this](const ActivityResult& result) {
|
||||
// Always apply orientation change even if the menu was cancelled
|
||||
// Always apply orientation and font size even if the menu was cancelled
|
||||
const auto& menu = std::get<MenuResult>(result.data);
|
||||
applyOrientation(menu.orientation);
|
||||
applyFontSize(menu.fontSize);
|
||||
toggleAutoPageTurn(menu.pageTurnOption);
|
||||
if (!result.isCancelled) {
|
||||
onReaderMenuConfirm(static_cast<EpubReaderMenuActivity::MenuAction>(menu.action));
|
||||
@@ -313,6 +321,7 @@ void EpubReaderActivity::jumpToPercent(int percent) {
|
||||
|
||||
void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action) {
|
||||
switch (action) {
|
||||
case EpubReaderMenuActivity::MenuAction::TABLE_OF_CONTENTS:
|
||||
case EpubReaderMenuActivity::MenuAction::SELECT_CHAPTER: {
|
||||
const int spineIdx = currentSpineIndex;
|
||||
const std::string path = epub->getPath();
|
||||
@@ -432,6 +441,79 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::CLOSE_BOOK:
|
||||
onGoHome();
|
||||
return;
|
||||
case EpubReaderMenuActivity::MenuAction::ADD_BOOKMARK: {
|
||||
if (section && BookmarkStore::addBookmark(epub->getCachePath(), currentSpineIndex, section->currentPage, "")) {
|
||||
requestUpdate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::REMOVE_BOOKMARK: {
|
||||
if (section && BookmarkStore::removeBookmark(epub->getCachePath(), currentSpineIndex, section->currentPage)) {
|
||||
requestUpdate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::GO_TO_BOOKMARK: {
|
||||
auto bookmarks = BookmarkStore::load(epub->getCachePath());
|
||||
startActivityForResult(
|
||||
std::make_unique<EpubReaderBookmarkSelectionActivity>(renderer, mappedInput, epub, std::move(bookmarks),
|
||||
epub->getCachePath()),
|
||||
[this](const ActivityResult& result) {
|
||||
if (!result.isCancelled) {
|
||||
const auto& sync = std::get<SyncResult>(result.data);
|
||||
if (currentSpineIndex != sync.spineIndex || (section && section->currentPage != sync.page)) {
|
||||
RenderLock lock(*this);
|
||||
currentSpineIndex = sync.spineIndex;
|
||||
nextPageNumber = sync.page;
|
||||
section.reset();
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::LOOKUP_WORD: {
|
||||
if (!section || !Dictionary::cacheExists()) {
|
||||
requestUpdate();
|
||||
break;
|
||||
}
|
||||
auto p = section->loadPageFromSectionFile();
|
||||
if (!p) {
|
||||
requestUpdate();
|
||||
break;
|
||||
}
|
||||
int orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft;
|
||||
renderer.getOrientedViewableTRBL(&orientedMarginTop, &orientedMarginRight, &orientedMarginBottom,
|
||||
&orientedMarginLeft);
|
||||
orientedMarginTop += SETTINGS.screenMargin;
|
||||
orientedMarginLeft += SETTINGS.screenMargin;
|
||||
startActivityForResult(
|
||||
std::make_unique<DictionaryWordSelectActivity>(
|
||||
renderer, mappedInput, std::move(p), SETTINGS.getReaderFontId(), orientedMarginLeft, orientedMarginTop,
|
||||
epub->getCachePath(), SETTINGS.orientation, ""),
|
||||
[this](const ActivityResult&) { requestUpdate(); });
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::LOOKUP_HISTORY: {
|
||||
if (!Dictionary::cacheExists()) {
|
||||
requestUpdate();
|
||||
break;
|
||||
}
|
||||
startActivityForResult(
|
||||
std::make_unique<LookedUpWordsActivity>(renderer, mappedInput, epub->getCachePath(),
|
||||
SETTINGS.getReaderFontId(), SETTINGS.orientation),
|
||||
[this](const ActivityResult&) { requestUpdate(); });
|
||||
break;
|
||||
}
|
||||
case EpubReaderMenuActivity::MenuAction::DELETE_DICT_CACHE: {
|
||||
if (Dictionary::cacheExists()) {
|
||||
Dictionary::deleteCache();
|
||||
}
|
||||
requestUpdate();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,6 +544,25 @@ void EpubReaderActivity::applyOrientation(const uint8_t orientation) {
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderActivity::applyFontSize(const uint8_t fontSize) {
|
||||
if (fontSize >= CrossPointSettings::FONT_SIZE_COUNT || SETTINGS.fontSize == fontSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
RenderLock lock(*this);
|
||||
if (section) {
|
||||
cachedSpineIndex = currentSpineIndex;
|
||||
cachedChapterTotalPageCount = section->pageCount;
|
||||
nextPageNumber = section->currentPage;
|
||||
}
|
||||
|
||||
SETTINGS.fontSize = fontSize;
|
||||
SETTINGS.saveToFile();
|
||||
section.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderActivity::toggleAutoPageTurn(const uint8_t selectedPageTurnOption) {
|
||||
if (selectedPageTurnOption == 0 || selectedPageTurnOption >= PAGE_TURN_LABELS.size()) {
|
||||
automaticPageTurnActive = false;
|
||||
|
||||
@@ -46,6 +46,7 @@ class EpubReaderActivity final : public Activity {
|
||||
void jumpToPercent(int percent);
|
||||
void onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action);
|
||||
void applyOrientation(uint8_t orientation);
|
||||
void applyFontSize(uint8_t fontSize);
|
||||
void toggleAutoPageTurn(uint8_t selectedPageTurnOption);
|
||||
void pageTurn(bool isForwardTurn);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <GfxRenderer.h>
|
||||
#include <I18n.h>
|
||||
|
||||
#include "CrossPointSettings.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
@@ -10,30 +11,37 @@
|
||||
EpubReaderMenuActivity::EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
||||
const std::string& title, const int currentPage, const int totalPages,
|
||||
const int bookProgressPercent, const uint8_t currentOrientation,
|
||||
const bool hasFootnotes)
|
||||
const bool hasFootnotes, bool isBookmarked, uint8_t currentFontSize)
|
||||
: Activity("EpubReaderMenu", renderer, mappedInput),
|
||||
menuItems(buildMenuItems(hasFootnotes)),
|
||||
menuItems(buildMenuItems(hasFootnotes, isBookmarked)),
|
||||
title(title),
|
||||
pendingOrientation(currentOrientation),
|
||||
pendingFontSize(currentFontSize < CrossPointSettings::FONT_SIZE_COUNT ? currentFontSize : 0),
|
||||
currentPage(currentPage),
|
||||
totalPages(totalPages),
|
||||
bookProgressPercent(bookProgressPercent) {}
|
||||
|
||||
std::vector<EpubReaderMenuActivity::MenuItem> EpubReaderMenuActivity::buildMenuItems(bool hasFootnotes) {
|
||||
std::vector<EpubReaderMenuActivity::MenuItem> EpubReaderMenuActivity::buildMenuItems(bool hasFootnotes,
|
||||
bool isBookmarked) {
|
||||
std::vector<MenuItem> items;
|
||||
items.reserve(10);
|
||||
items.push_back({MenuAction::SELECT_CHAPTER, StrId::STR_SELECT_CHAPTER});
|
||||
if (hasFootnotes) {
|
||||
items.push_back({MenuAction::FOOTNOTES, StrId::STR_FOOTNOTES});
|
||||
items.reserve(13);
|
||||
// Mod menu order
|
||||
if (isBookmarked) {
|
||||
items.push_back({MenuAction::REMOVE_BOOKMARK, StrId::STR_REMOVE_BOOKMARK});
|
||||
} else {
|
||||
items.push_back({MenuAction::ADD_BOOKMARK, StrId::STR_ADD_BOOKMARK});
|
||||
}
|
||||
items.push_back({MenuAction::ROTATE_SCREEN, StrId::STR_ORIENTATION});
|
||||
items.push_back({MenuAction::AUTO_PAGE_TURN, StrId::STR_AUTO_TURN_PAGES_PER_MIN});
|
||||
items.push_back({MenuAction::LOOKUP_WORD, StrId::STR_LOOKUP_WORD});
|
||||
items.push_back({MenuAction::GO_TO_BOOKMARK, StrId::STR_GO_TO_BOOKMARK});
|
||||
items.push_back({MenuAction::LOOKUP_HISTORY, StrId::STR_LOOKUP_HISTORY});
|
||||
items.push_back({MenuAction::TABLE_OF_CONTENTS, StrId::STR_TABLE_OF_CONTENTS});
|
||||
items.push_back({MenuAction::GO_TO_PERCENT, StrId::STR_GO_TO_PERCENT});
|
||||
items.push_back({MenuAction::SCREENSHOT, StrId::STR_SCREENSHOT_BUTTON});
|
||||
items.push_back({MenuAction::DISPLAY_QR, StrId::STR_DISPLAY_QR});
|
||||
items.push_back({MenuAction::GO_HOME, StrId::STR_GO_HOME_BUTTON});
|
||||
items.push_back({MenuAction::TOGGLE_ORIENTATION, StrId::STR_TOGGLE_ORIENTATION});
|
||||
items.push_back({MenuAction::TOGGLE_FONT_SIZE, StrId::STR_TOGGLE_FONT_SIZE});
|
||||
items.push_back({MenuAction::SYNC, StrId::STR_SYNC_PROGRESS});
|
||||
items.push_back({MenuAction::CLOSE_BOOK, StrId::STR_CLOSE_BOOK});
|
||||
items.push_back({MenuAction::DELETE_CACHE, StrId::STR_DELETE_CACHE});
|
||||
items.push_back({MenuAction::DELETE_DICT_CACHE, StrId::STR_DELETE_DICT_CACHE});
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -58,26 +66,28 @@ void EpubReaderMenuActivity::loop() {
|
||||
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
const auto selectedAction = menuItems[selectedIndex].action;
|
||||
if (selectedAction == MenuAction::ROTATE_SCREEN) {
|
||||
// Cycle orientation preview locally; actual rotation happens on menu exit.
|
||||
pendingOrientation = (pendingOrientation + 1) % orientationLabels.size();
|
||||
if (selectedAction == MenuAction::TOGGLE_ORIENTATION) {
|
||||
// Toggle between preferred portrait and preferred landscape.
|
||||
const bool isCurrentlyPortrait =
|
||||
(pendingOrientation == CrossPointSettings::PORTRAIT || pendingOrientation == CrossPointSettings::INVERTED);
|
||||
pendingOrientation = isCurrentlyPortrait ? SETTINGS.preferredLandscape : SETTINGS.preferredPortrait;
|
||||
requestUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedAction == MenuAction::AUTO_PAGE_TURN) {
|
||||
selectedPageTurnOption = (selectedPageTurnOption + 1) % pageTurnLabels.size();
|
||||
if (selectedAction == MenuAction::TOGGLE_FONT_SIZE) {
|
||||
pendingFontSize = (pendingFontSize + 1) % CrossPointSettings::FONT_SIZE_COUNT;
|
||||
requestUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
setResult(MenuResult{static_cast<int>(selectedAction), pendingOrientation, selectedPageTurnOption});
|
||||
setResult(MenuResult{static_cast<int>(selectedAction), pendingOrientation, selectedPageTurnOption, pendingFontSize});
|
||||
finish();
|
||||
return;
|
||||
} else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||
ActivityResult result;
|
||||
result.isCancelled = true;
|
||||
result.data = MenuResult{-1, pendingOrientation, selectedPageTurnOption};
|
||||
result.data = MenuResult{-1, pendingOrientation, selectedPageTurnOption, pendingFontSize};
|
||||
setResult(std::move(result));
|
||||
finish();
|
||||
return;
|
||||
@@ -134,16 +144,14 @@ void EpubReaderMenuActivity::render(RenderLock&&) {
|
||||
|
||||
renderer.drawText(UI_10_FONT_ID, contentX + 20, displayY, I18N.get(menuItems[i].labelId), !isSelected);
|
||||
|
||||
if (menuItems[i].action == MenuAction::ROTATE_SCREEN) {
|
||||
// Render current orientation value on the right edge of the content area.
|
||||
if (menuItems[i].action == MenuAction::TOGGLE_ORIENTATION) {
|
||||
const char* value = I18N.get(orientationLabels[pendingOrientation]);
|
||||
const auto width = renderer.getTextWidth(UI_10_FONT_ID, value);
|
||||
renderer.drawText(UI_10_FONT_ID, contentX + contentWidth - 20 - width, displayY, value, !isSelected);
|
||||
}
|
||||
|
||||
if (menuItems[i].action == MenuAction::AUTO_PAGE_TURN) {
|
||||
// Render current page turn value on the right edge of the content area.
|
||||
const auto value = pageTurnLabels[selectedPageTurnOption];
|
||||
if (menuItems[i].action == MenuAction::TOGGLE_FONT_SIZE) {
|
||||
const char* value = I18N.get(fontSizeLabels[pendingFontSize]);
|
||||
const auto width = renderer.getTextWidth(UI_10_FONT_ID, value);
|
||||
renderer.drawText(UI_10_FONT_ID, contentX + contentWidth - 20 - width, displayY, value, !isSelected);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,24 @@ class EpubReaderMenuActivity final : public Activity {
|
||||
DISPLAY_QR,
|
||||
GO_HOME,
|
||||
SYNC,
|
||||
DELETE_CACHE
|
||||
DELETE_CACHE,
|
||||
// Mod-specific actions
|
||||
ADD_BOOKMARK,
|
||||
REMOVE_BOOKMARK,
|
||||
LOOKUP_WORD,
|
||||
LOOKUP_HISTORY,
|
||||
GO_TO_BOOKMARK,
|
||||
TABLE_OF_CONTENTS,
|
||||
TOGGLE_ORIENTATION,
|
||||
TOGGLE_FONT_SIZE,
|
||||
CLOSE_BOOK,
|
||||
DELETE_DICT_CACHE
|
||||
};
|
||||
|
||||
explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& title,
|
||||
const int currentPage, const int totalPages, const int bookProgressPercent,
|
||||
const uint8_t currentOrientation, const bool hasFootnotes);
|
||||
const uint8_t currentOrientation, const bool hasFootnotes,
|
||||
bool isBookmarked = false, uint8_t currentFontSize = 0);
|
||||
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
@@ -39,7 +51,7 @@ class EpubReaderMenuActivity final : public Activity {
|
||||
StrId labelId;
|
||||
};
|
||||
|
||||
static std::vector<MenuItem> buildMenuItems(bool hasFootnotes);
|
||||
static std::vector<MenuItem> buildMenuItems(bool hasFootnotes, bool isBookmarked);
|
||||
|
||||
// Fixed menu layout
|
||||
const std::vector<MenuItem> menuItems;
|
||||
@@ -49,9 +61,11 @@ class EpubReaderMenuActivity final : public Activity {
|
||||
ButtonNavigator buttonNavigator;
|
||||
std::string title = "Reader Menu";
|
||||
uint8_t pendingOrientation = 0;
|
||||
uint8_t pendingFontSize = 0;
|
||||
uint8_t selectedPageTurnOption = 0;
|
||||
const std::vector<StrId> orientationLabels = {StrId::STR_PORTRAIT, StrId::STR_LANDSCAPE_CW, StrId::STR_INVERTED,
|
||||
StrId::STR_LANDSCAPE_CCW};
|
||||
const std::vector<StrId> fontSizeLabels = {StrId::STR_SMALL, StrId::STR_MEDIUM, StrId::STR_LARGE, StrId::STR_X_LARGE};
|
||||
const std::vector<const char*> pageTurnLabels = {I18N.get(StrId::STR_STATE_OFF), "1", "3", "6", "12"};
|
||||
int currentPage = 0;
|
||||
int totalPages = 0;
|
||||
|
||||
Reference in New Issue
Block a user