2026-02-01 08:34:30 +01:00
|
|
|
#pragma once
|
|
|
|
|
#include <Epub.h>
|
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
|
#include <freertos/semphr.h>
|
|
|
|
|
#include <freertos/task.h>
|
|
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "../ActivityWithSubactivity.h"
|
2026-02-13 16:07:38 -05:00
|
|
|
#include "util/BookSettings.h"
|
2026-02-09 15:19:34 +06:00
|
|
|
#include "util/ButtonNavigator.h"
|
2026-02-01 08:34:30 +01:00
|
|
|
|
|
|
|
|
class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
|
|
|
|
public:
|
2026-02-05 15:17:51 +03:00
|
|
|
// Menu actions available from the reader menu.
|
2026-02-12 19:36:14 -05:00
|
|
|
enum class MenuAction {
|
|
|
|
|
ADD_BOOKMARK,
|
2026-02-12 20:40:07 -05:00
|
|
|
REMOVE_BOOKMARK,
|
2026-02-12 19:36:14 -05:00
|
|
|
LOOKUP,
|
|
|
|
|
LOOKED_UP_WORDS,
|
|
|
|
|
ROTATE_SCREEN,
|
2026-02-13 16:07:38 -05:00
|
|
|
LETTERBOX_FILL,
|
2026-02-12 19:36:14 -05:00
|
|
|
SELECT_CHAPTER,
|
|
|
|
|
GO_TO_BOOKMARK,
|
|
|
|
|
GO_TO_PERCENT,
|
|
|
|
|
GO_HOME,
|
|
|
|
|
SYNC,
|
|
|
|
|
DELETE_CACHE,
|
|
|
|
|
DELETE_DICT_CACHE
|
|
|
|
|
};
|
2026-02-01 08:34:30 +01:00
|
|
|
|
|
|
|
|
explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& title,
|
2026-02-05 15:17:51 +03:00
|
|
|
const int currentPage, const int totalPages, const int bookProgressPercent,
|
2026-02-12 19:36:14 -05:00
|
|
|
const uint8_t currentOrientation, const bool hasDictionary,
|
2026-02-13 16:07:38 -05:00
|
|
|
const bool isBookmarked, const std::string& bookCachePath,
|
2026-02-12 19:36:14 -05:00
|
|
|
const std::function<void(uint8_t)>& onBack,
|
2026-02-05 14:53:35 +03:00
|
|
|
const std::function<void(MenuAction)>& onAction)
|
2026-02-01 08:34:30 +01:00
|
|
|
: ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput),
|
2026-02-12 20:40:07 -05:00
|
|
|
menuItems(buildMenuItems(hasDictionary, isBookmarked)),
|
2026-02-01 08:34:30 +01:00
|
|
|
title(title),
|
2026-02-05 14:53:35 +03:00
|
|
|
pendingOrientation(currentOrientation),
|
2026-02-13 16:07:38 -05:00
|
|
|
bookCachePath(bookCachePath),
|
2026-02-05 15:17:51 +03:00
|
|
|
currentPage(currentPage),
|
|
|
|
|
totalPages(totalPages),
|
|
|
|
|
bookProgressPercent(bookProgressPercent),
|
2026-02-01 08:34:30 +01:00
|
|
|
onBack(onBack),
|
2026-02-13 16:07:38 -05:00
|
|
|
onAction(onAction) {
|
|
|
|
|
// Load per-book settings to initialize the letterbox fill override
|
|
|
|
|
auto bookSettings = BookSettings::load(bookCachePath);
|
|
|
|
|
pendingLetterboxFill = bookSettings.letterboxFillOverride;
|
|
|
|
|
}
|
2026-02-01 08:34:30 +01:00
|
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
|
void onExit() override;
|
|
|
|
|
void loop() override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct MenuItem {
|
|
|
|
|
MenuAction action;
|
|
|
|
|
std::string label;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-12 19:36:14 -05:00
|
|
|
std::vector<MenuItem> menuItems;
|
2026-02-01 08:34:30 +01:00
|
|
|
|
|
|
|
|
int selectedIndex = 0;
|
|
|
|
|
bool updateRequired = false;
|
|
|
|
|
TaskHandle_t displayTaskHandle = nullptr;
|
|
|
|
|
SemaphoreHandle_t renderingMutex = nullptr;
|
2026-02-09 15:19:34 +06:00
|
|
|
ButtonNavigator buttonNavigator;
|
2026-02-01 08:34:30 +01:00
|
|
|
std::string title = "Reader Menu";
|
2026-02-05 14:53:35 +03:00
|
|
|
uint8_t pendingOrientation = 0;
|
|
|
|
|
const std::vector<const char*> orientationLabels = {"Portrait", "Landscape CW", "Inverted", "Landscape CCW"};
|
2026-02-13 16:07:38 -05:00
|
|
|
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<const char*> letterboxFillLabels = {"Default", "Dithered", "Solid", "None"};
|
2026-02-05 15:17:51 +03:00
|
|
|
int currentPage = 0;
|
|
|
|
|
int totalPages = 0;
|
|
|
|
|
int bookProgressPercent = 0;
|
2026-02-01 08:34:30 +01:00
|
|
|
|
2026-02-05 14:53:35 +03:00
|
|
|
const std::function<void(uint8_t)> onBack;
|
2026-02-01 08:34:30 +01:00
|
|
|
const std::function<void(MenuAction)> onAction;
|
|
|
|
|
|
2026-02-13 16:07:38 -05:00
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-12 20:40:07 -05:00
|
|
|
static std::vector<MenuItem> buildMenuItems(bool hasDictionary, bool isBookmarked) {
|
2026-02-12 19:36:14 -05:00
|
|
|
std::vector<MenuItem> items;
|
2026-02-12 20:40:07 -05:00
|
|
|
if (isBookmarked) {
|
|
|
|
|
items.push_back({MenuAction::REMOVE_BOOKMARK, "Remove Bookmark"});
|
|
|
|
|
} else {
|
|
|
|
|
items.push_back({MenuAction::ADD_BOOKMARK, "Add Bookmark"});
|
|
|
|
|
}
|
2026-02-12 19:36:14 -05:00
|
|
|
if (hasDictionary) {
|
|
|
|
|
items.push_back({MenuAction::LOOKUP, "Lookup Word"});
|
|
|
|
|
items.push_back({MenuAction::LOOKED_UP_WORDS, "Lookup Word History"});
|
|
|
|
|
}
|
|
|
|
|
items.push_back({MenuAction::ROTATE_SCREEN, "Reading Orientation"});
|
2026-02-13 16:07:38 -05:00
|
|
|
items.push_back({MenuAction::LETTERBOX_FILL, "Letterbox Fill"});
|
2026-02-12 19:36:14 -05:00
|
|
|
items.push_back({MenuAction::SELECT_CHAPTER, "Table of Contents"});
|
|
|
|
|
items.push_back({MenuAction::GO_TO_BOOKMARK, "Go to Bookmark"});
|
|
|
|
|
items.push_back({MenuAction::GO_TO_PERCENT, "Go to %"});
|
|
|
|
|
items.push_back({MenuAction::GO_HOME, "Close Book"});
|
|
|
|
|
items.push_back({MenuAction::SYNC, "Sync Progress"});
|
|
|
|
|
items.push_back({MenuAction::DELETE_CACHE, "Delete Book Cache"});
|
|
|
|
|
if (hasDictionary) {
|
|
|
|
|
items.push_back({MenuAction::DELETE_DICT_CACHE, "Delete Dictionary Cache"});
|
|
|
|
|
}
|
|
|
|
|
return items;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 08:34:30 +01:00
|
|
|
static void taskTrampoline(void* param);
|
|
|
|
|
[[noreturn]] void displayTaskLoop();
|
|
|
|
|
void renderScreen();
|
|
|
|
|
};
|