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-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,
|
|
|
|
|
LOOKUP,
|
|
|
|
|
LOOKED_UP_WORDS,
|
|
|
|
|
ROTATE_SCREEN,
|
|
|
|
|
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,
|
|
|
|
|
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 19:36:14 -05:00
|
|
|
menuItems(buildMenuItems(hasDictionary)),
|
2026-02-01 08:34:30 +01:00
|
|
|
title(title),
|
2026-02-05 14:53:35 +03:00
|
|
|
pendingOrientation(currentOrientation),
|
2026-02-05 15:17:51 +03:00
|
|
|
currentPage(currentPage),
|
|
|
|
|
totalPages(totalPages),
|
|
|
|
|
bookProgressPercent(bookProgressPercent),
|
2026-02-01 08:34:30 +01:00
|
|
|
onBack(onBack),
|
|
|
|
|
onAction(onAction) {}
|
|
|
|
|
|
|
|
|
|
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-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-12 19:36:14 -05:00
|
|
|
static std::vector<MenuItem> buildMenuItems(bool hasDictionary) {
|
|
|
|
|
std::vector<MenuItem> items;
|
|
|
|
|
items.push_back({MenuAction::ADD_BOOKMARK, "Add Bookmark"});
|
|
|
|
|
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"});
|
|
|
|
|
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();
|
|
|
|
|
};
|