Compare commits

..

No commits in common. "90d459f2c0711a44d927a365fbda803f6ce611fe" and "1cbe081a597557015223f8d6f292f5c5c36e52d7" have entirely different histories.

5 changed files with 22 additions and 26 deletions

View File

@ -131,7 +131,7 @@ void EpubReaderActivity::loop() {
const int totalPages = section ? section->pageCount : 0; const int totalPages = section ? section->pageCount : 0;
exitActivity(); exitActivity();
enterNewActivity(new EpubReaderMenuActivity( enterNewActivity(new EpubReaderMenuActivity(
this->renderer, this->mappedInput, epub->getTitle(), [this]() { onReaderMenuBack(); }, this->renderer, this->mappedInput, [this]() { onReaderMenuBack(); },
[this](EpubReaderMenuActivity::MenuAction action) { onReaderMenuConfirm(action); })); [this](EpubReaderMenuActivity::MenuAction action) { onReaderMenuConfirm(action); }));
xSemaphoreGive(renderingMutex); xSemaphoreGive(renderingMutex);
} }
@ -283,7 +283,6 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction
// We use the current variables that track our position // We use the current variables that track our position
uint16_t backupSpine = currentSpineIndex; uint16_t backupSpine = currentSpineIndex;
uint16_t backupPage = section->currentPage; uint16_t backupPage = section->currentPage;
uint16_t backupPageCount = section->pageCount;
section.reset(); section.reset();
// 3. WIPE: Clear the cache directory // 3. WIPE: Clear the cache directory
@ -292,7 +291,7 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction
// 4. RESTORE: Re-setup the directory and rewrite the progress file // 4. RESTORE: Re-setup the directory and rewrite the progress file
epub->setupCacheDir(); epub->setupCacheDir();
saveProgress(backupSpine, backupPage, backupPageCount); saveProgress(backupSpine, backupPage);
} }
exitActivity(); exitActivity();
updateRequired = true; updateRequired = true;
@ -468,22 +467,22 @@ void EpubReaderActivity::renderScreen() {
renderContents(std::move(p), orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft); renderContents(std::move(p), orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft);
Serial.printf("[%lu] [ERS] Rendered page in %dms\n", millis(), millis() - start); Serial.printf("[%lu] [ERS] Rendered page in %dms\n", millis(), millis() - start);
} }
saveProgress(currentSpineIndex, section->currentPage, section->pageCount); saveProgress(currentSpineIndex, section->currentPage);
} }
void EpubReaderActivity::saveProgress(int spineIndex, int currentPage, int pageCount) { void EpubReaderActivity::saveProgress(int spineIndex, int page) {
FsFile f; FsFile f;
if (SdMan.openFileForWrite("ERS", epub->getCachePath() + "/progress.bin", f)) { if (SdMan.openFileForWrite("ERS", epub->getCachePath() + "/progress.bin", f)) {
uint8_t data[6]; uint8_t data[6];
data[0] = currentSpineIndex & 0xFF; data[0] = currentSpineIndex & 0xFF;
data[1] = (currentSpineIndex >> 8) & 0xFF; data[1] = (currentSpineIndex >> 8) & 0xFF;
data[2] = currentPage & 0xFF; data[2] = section->currentPage & 0xFF;
data[3] = (currentPage >> 8) & 0xFF; data[3] = (section->currentPage >> 8) & 0xFF;
data[4] = pageCount & 0xFF; data[4] = section->pageCount & 0xFF;
data[5] = (pageCount >> 8) & 0xFF; data[5] = (section->pageCount >> 8) & 0xFF;
f.write(data, 6); f.write(data, 6);
f.close(); f.close();
Serial.printf("[ERS] Progress saved: Chapter %d, Page %d\n", spineIndex, currentPage); Serial.printf("[ERS] Progress saved: Chapter %d, Page %d\n", spineIndex, page);
} else { } else {
Serial.printf("[ERS] Could not save progress!\n"); Serial.printf("[ERS] Could not save progress!\n");
} }

View File

@ -28,7 +28,7 @@ class EpubReaderActivity final : public ActivityWithSubactivity {
void renderContents(std::unique_ptr<Page> page, int orientedMarginTop, int orientedMarginRight, void renderContents(std::unique_ptr<Page> page, int orientedMarginTop, int orientedMarginRight,
int orientedMarginBottom, int orientedMarginLeft); int orientedMarginBottom, int orientedMarginLeft);
void renderStatusBar(int orientedMarginRight, int orientedMarginBottom, int orientedMarginLeft) const; void renderStatusBar(int orientedMarginRight, int orientedMarginBottom, int orientedMarginLeft) const;
void saveProgress(int spineIndex, int currentPage, int pageCount); void saveProgress(int spineIndex, int page);
void onReaderMenuBack(); void onReaderMenuBack();
void onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action); void onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction action);

View File

@ -181,7 +181,9 @@ void EpubReaderChapterSelectionActivity::renderScreen() {
const int pageItems = getPageItems(); const int pageItems = getPageItems();
const int totalItems = getTotalItems(); const int totalItems = getTotalItems();
renderer.drawCenteredText(UI_12_FONT_ID, 15, "Go to Chapter", true, EpdFontFamily::BOLD); const std::string title =
renderer.truncatedText(UI_12_FONT_ID, epub->getTitle().c_str(), pageWidth - 40, EpdFontFamily::BOLD);
renderer.drawCenteredText(UI_12_FONT_ID, 15, title.c_str(), true, EpdFontFamily::BOLD);
const auto pageStartIndex = selectorIndex / pageItems * pageItems; const auto pageStartIndex = selectorIndex / pageItems * pageItems;
renderer.fillRect(0, 60 + (selectorIndex % pageItems) * 30 - 2, pageWidth - 1, 30); renderer.fillRect(0, 60 + (selectorIndex % pageItems) * 30 - 2, pageWidth - 1, 30);

View File

@ -76,23 +76,22 @@ void EpubReaderMenuActivity::renderScreen() {
const auto pageWidth = renderer.getScreenWidth(); const auto pageWidth = renderer.getScreenWidth();
// Title // Title
const std::string truncTitle = renderer.drawCenteredText(UI_12_FONT_ID, 20, "Reader Menu", true, EpdFontFamily::BOLD);
renderer.truncatedText(UI_12_FONT_ID, title.c_str(), pageWidth - 40, EpdFontFamily::BOLD); // renderer.fillRect(0, 60 + (selectedIndex % menuItems.size()) * 30 - 2, pageWidth - 1, 30);
renderer.drawCenteredText(UI_12_FONT_ID, 15, truncTitle.c_str(), true, EpdFontFamily::BOLD);
// Menu Items // Menu Items
constexpr int startY = 60; constexpr int startY = 80;
constexpr int lineHeight = 30; constexpr int lineHeight = 40;
for (size_t i = 0; i < menuItems.size(); ++i) { for (size_t i = 0; i < menuItems.size(); ++i) {
const int displayY = startY + (i * lineHeight); const int displayY = startY + (i * lineHeight);
const bool isSelected = (static_cast<int>(i) == selectedIndex); const bool isSelected = (static_cast<int>(i) == selectedIndex);
if (isSelected) { if (isSelected) {
renderer.fillRect(0, displayY, pageWidth - 1, lineHeight, true); renderer.fillRect(10, displayY - 5, pageWidth - 20, lineHeight, true);
} }
renderer.drawText(UI_10_FONT_ID, 20, displayY, menuItems[i].label.c_str(), !isSelected); renderer.drawText(UI_12_FONT_ID, 30, displayY + 5, menuItems[i].label.c_str(), !isSelected);
} }
// Footer / Hints // Footer / Hints

View File

@ -15,12 +15,9 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
public: public:
enum class MenuAction { SELECT_CHAPTER, GO_HOME, DELETE_CACHE }; enum class MenuAction { SELECT_CHAPTER, GO_HOME, DELETE_CACHE };
explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& title, explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void()>& onBack, const std::function<void(MenuAction)>& onAction) const std::function<void()>& onBack, const std::function<void(MenuAction)>& onAction)
: ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput), : ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput), onBack(onBack), onAction(onAction) {}
title(title),
onBack(onBack),
onAction(onAction) {}
void onEnter() override; void onEnter() override;
void onExit() override; void onExit() override;
@ -32,7 +29,7 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
std::string label; std::string label;
}; };
const std::vector<MenuItem> menuItems = {{MenuAction::SELECT_CHAPTER, "Go to Chapter"}, const std::vector<MenuItem> menuItems = {{MenuAction::SELECT_CHAPTER, "Select Chapter"},
{MenuAction::GO_HOME, "Go Home"}, {MenuAction::GO_HOME, "Go Home"},
{MenuAction::DELETE_CACHE, "Delete Book Cache"}}; {MenuAction::DELETE_CACHE, "Delete Book Cache"}};
@ -40,7 +37,6 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
bool updateRequired = false; bool updateRequired = false;
TaskHandle_t displayTaskHandle = nullptr; TaskHandle_t displayTaskHandle = nullptr;
SemaphoreHandle_t renderingMutex = nullptr; SemaphoreHandle_t renderingMutex = nullptr;
std::string title = "Reader Menu";
const std::function<void()> onBack; const std::function<void()> onBack;
const std::function<void(MenuAction)> onAction; const std::function<void(MenuAction)> onAction;