adds delete and archive abilities
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <GfxRenderer.h>
|
||||
#include <SDCardManager.h>
|
||||
|
||||
#include "BookManager.h"
|
||||
#include "CrossPointSettings.h"
|
||||
#include "CrossPointState.h"
|
||||
#include "EpubReaderChapterSelectionActivity.h"
|
||||
@@ -119,6 +120,33 @@ void EpubReaderActivity::loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle end-of-book prompt
|
||||
if (showingEndOfBookPrompt) {
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Up)) {
|
||||
endOfBookSelection = (endOfBookSelection + 2) % 3;
|
||||
updateRequired = true;
|
||||
return;
|
||||
}
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Down)) {
|
||||
endOfBookSelection = (endOfBookSelection + 1) % 3;
|
||||
updateRequired = true;
|
||||
return;
|
||||
}
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
handleEndOfBookAction();
|
||||
return;
|
||||
}
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||
// Go back to last page instead
|
||||
currentSpineIndex = epub->getSpineItemsCount() - 1;
|
||||
nextPageNumber = UINT16_MAX;
|
||||
showingEndOfBookPrompt = false;
|
||||
updateRequired = true;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Enter chapter selection activity
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
// Don't start activity transition while rendering
|
||||
@@ -260,11 +288,9 @@ void EpubReaderActivity::loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
// any botton press when at end of the book goes back to the last page
|
||||
if (currentSpineIndex > 0 && currentSpineIndex >= epub->getSpineItemsCount()) {
|
||||
currentSpineIndex = epub->getSpineItemsCount() - 1;
|
||||
nextPageNumber = UINT16_MAX;
|
||||
updateRequired = true;
|
||||
// any button press when at end of the book - this is now handled by the prompt
|
||||
// Just ensure we don't go past the end
|
||||
if (currentSpineIndex >= epub->getSpineItemsCount()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -341,13 +367,13 @@ void EpubReaderActivity::renderScreen() {
|
||||
currentSpineIndex = epub->getSpineItemsCount();
|
||||
}
|
||||
|
||||
// Show end of book screen
|
||||
// Show end of book prompt
|
||||
if (currentSpineIndex == epub->getSpineItemsCount()) {
|
||||
renderer.clearScreen();
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, 300, "End of book", true, EpdFontFamily::BOLD);
|
||||
renderer.displayBuffer();
|
||||
showingEndOfBookPrompt = true;
|
||||
renderEndOfBookPrompt();
|
||||
return;
|
||||
}
|
||||
showingEndOfBookPrompt = false;
|
||||
|
||||
// Apply screen viewable areas and additional padding
|
||||
int orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft;
|
||||
@@ -586,3 +612,60 @@ void EpubReaderActivity::renderStatusBar(const int orientedMarginRight, const in
|
||||
title.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void EpubReaderActivity::renderEndOfBookPrompt() {
|
||||
const int pageWidth = renderer.getScreenWidth();
|
||||
const int pageHeight = renderer.getScreenHeight();
|
||||
|
||||
renderer.clearScreen();
|
||||
|
||||
// Title
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, 80, "Finished!", true, EpdFontFamily::BOLD);
|
||||
|
||||
// Book title (truncated if needed)
|
||||
std::string bookTitle = epub->getTitle();
|
||||
if (bookTitle.length() > 30) {
|
||||
bookTitle = bookTitle.substr(0, 27) + "...";
|
||||
}
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, 120, bookTitle.c_str());
|
||||
|
||||
// Menu options
|
||||
const int menuStartY = pageHeight / 2 - 30;
|
||||
constexpr int menuLineHeight = 45;
|
||||
constexpr int menuItemWidth = 140;
|
||||
const int menuX = (pageWidth - menuItemWidth) / 2;
|
||||
|
||||
const char* options[] = {"Archive", "Delete", "Keep"};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
const int optionY = menuStartY + i * menuLineHeight;
|
||||
if (endOfBookSelection == i) {
|
||||
renderer.fillRect(menuX - 10, optionY - 5, menuItemWidth + 20, menuLineHeight - 5);
|
||||
}
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, optionY, options[i], endOfBookSelection != i);
|
||||
}
|
||||
|
||||
// Button hints
|
||||
const auto labels = mappedInput.mapLabels("« Back", "Select", "", "");
|
||||
renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
|
||||
void EpubReaderActivity::handleEndOfBookAction() {
|
||||
const std::string bookPath = epub->getPath();
|
||||
|
||||
switch (endOfBookSelection) {
|
||||
case 0: // Archive
|
||||
BookManager::archiveBook(bookPath);
|
||||
onGoHome();
|
||||
break;
|
||||
case 1: // Delete
|
||||
BookManager::deleteBook(bookPath);
|
||||
onGoHome();
|
||||
break;
|
||||
case 2: // Keep
|
||||
default:
|
||||
onGoHome();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user