Migrate 5 mod Activity subclasses from old polling-based display task pattern to the upstream render() super-class pattern with freeRTOS notification: - EpubReaderBookmarkSelectionActivity - DictionaryWordSelectActivity - DictionarySuggestionsActivity - DictionaryDefinitionActivity - LookedUpWordsActivity Changes: remove own TaskHandle/SemaphoreHandle/updateRequired, use requestUpdate() + render(RenderLock&&) override, fix potential deadlocks around enterNewActivity() calls. Also fix stale conflict marker in EpubReaderMenuActivity.h. Co-authored-by: Cursor <cursoragent@cursor.com>
131 lines
4.9 KiB
C++
131 lines
4.9 KiB
C++
#pragma once
|
|
#include <Epub.h>
|
|
#include <I18n.h>
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../ActivityWithSubactivity.h"
|
|
#include "util/BookSettings.h"
|
|
#include "util/ButtonNavigator.h"
|
|
|
|
class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
|
public:
|
|
// Menu actions available from the reader menu.
|
|
enum class MenuAction {
|
|
ADD_BOOKMARK,
|
|
REMOVE_BOOKMARK,
|
|
LOOKUP,
|
|
LOOKED_UP_WORDS,
|
|
ROTATE_SCREEN,
|
|
LETTERBOX_FILL,
|
|
SELECT_CHAPTER,
|
|
GO_TO_BOOKMARK,
|
|
GO_TO_PERCENT,
|
|
GO_HOME,
|
|
SYNC,
|
|
DELETE_CACHE,
|
|
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 hasDictionary,
|
|
const bool isBookmarked, const std::string& bookCachePath,
|
|
const std::function<void(uint8_t)>& onBack,
|
|
const std::function<void(MenuAction)>& onAction)
|
|
: ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput),
|
|
menuItems(buildMenuItems(hasDictionary, isBookmarked)),
|
|
title(title),
|
|
pendingOrientation(currentOrientation),
|
|
bookCachePath(bookCachePath),
|
|
currentPage(currentPage),
|
|
totalPages(totalPages),
|
|
bookProgressPercent(bookProgressPercent),
|
|
onBack(onBack),
|
|
onAction(onAction) {
|
|
// Load per-book settings to initialize the letterbox fill override
|
|
auto bookSettings = BookSettings::load(bookCachePath);
|
|
pendingLetterboxFill = bookSettings.letterboxFillOverride;
|
|
}
|
|
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
void render(Activity::RenderLock&&) override;
|
|
|
|
private:
|
|
struct MenuItem {
|
|
MenuAction action;
|
|
StrId labelId;
|
|
};
|
|
|
|
std::vector<MenuItem> menuItems;
|
|
|
|
int selectedIndex = 0;
|
|
|
|
ButtonNavigator buttonNavigator;
|
|
std::string title = "Reader Menu";
|
|
uint8_t pendingOrientation = 0;
|
|
const std::vector<StrId> orientationLabels = {StrId::STR_PORTRAIT, StrId::STR_LANDSCAPE_CW, StrId::STR_INVERTED,
|
|
StrId::STR_LANDSCAPE_CCW};
|
|
std::string bookCachePath;
|
|
// 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
|
|
const std::vector<StrId> letterboxFillLabels = {StrId::STR_DEFAULT_OPTION, StrId::STR_DITHERED, StrId::STR_SOLID,
|
|
StrId::STR_NONE_OPT};
|
|
int currentPage = 0;
|
|
int totalPages = 0;
|
|
int bookProgressPercent = 0;
|
|
|
|
const std::function<void(uint8_t)> onBack;
|
|
const std::function<void(MenuAction)> onAction;
|
|
|
|
// Map the internal override value to an index into letterboxFillLabels.
|
|
int letterboxFillToIndex() const {
|
|
if (pendingLetterboxFill == BookSettings::USE_GLOBAL) return 0; // "Default"
|
|
return pendingLetterboxFill + 1; // 0->1 (Dithered), 1->2 (Solid), 2->3 (None)
|
|
}
|
|
|
|
// Map an index from letterboxFillLabels back to an override value.
|
|
static uint8_t indexToLetterboxFill(int index) {
|
|
if (index == 0) return BookSettings::USE_GLOBAL;
|
|
return static_cast<uint8_t>(index - 1);
|
|
}
|
|
|
|
// Save the current letterbox fill override to the book's settings file.
|
|
void saveLetterboxFill() const {
|
|
auto bookSettings = BookSettings::load(bookCachePath);
|
|
bookSettings.letterboxFillOverride = pendingLetterboxFill;
|
|
BookSettings::save(bookCachePath, bookSettings);
|
|
}
|
|
|
|
static std::vector<MenuItem> buildMenuItems(bool hasDictionary, bool isBookmarked) {
|
|
std::vector<MenuItem> items;
|
|
if (isBookmarked) {
|
|
items.push_back({MenuAction::REMOVE_BOOKMARK, StrId::STR_REMOVE_BOOKMARK});
|
|
} else {
|
|
items.push_back({MenuAction::ADD_BOOKMARK, StrId::STR_ADD_BOOKMARK});
|
|
}
|
|
if (hasDictionary) {
|
|
items.push_back({MenuAction::LOOKUP, StrId::STR_LOOKUP_WORD});
|
|
items.push_back({MenuAction::LOOKED_UP_WORDS, StrId::STR_LOOKUP_HISTORY});
|
|
}
|
|
items.push_back({MenuAction::ROTATE_SCREEN, StrId::STR_ORIENTATION});
|
|
items.push_back({MenuAction::LETTERBOX_FILL, StrId::STR_LETTERBOX_FILL});
|
|
items.push_back({MenuAction::SELECT_CHAPTER, StrId::STR_TABLE_OF_CONTENTS});
|
|
items.push_back({MenuAction::GO_TO_BOOKMARK, StrId::STR_GO_TO_BOOKMARK});
|
|
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});
|
|
if (hasDictionary) {
|
|
items.push_back({MenuAction::DELETE_DICT_CACHE, StrId::STR_DELETE_DICT_CACHE});
|
|
}
|
|
return items;
|
|
}
|
|
|
|
};
|