Merge pull request #82 from jpirnay/feat-globalbookmarks
feat: Add global bookmarks screen
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "EpubReaderChapterSelectionActivity.h"
|
||||
#include "EpubReaderFootnotesActivity.h"
|
||||
#include "EpubReaderPercentSelectionActivity.h"
|
||||
#include "GlobalBookmarkIndex.h"
|
||||
#include "KOReaderCredentialStore.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "QrDisplayActivity.h"
|
||||
@@ -93,6 +94,7 @@ void EpubReaderActivity::onEnter() {
|
||||
|
||||
epub->setupCacheDir();
|
||||
applyPendingSyncSession();
|
||||
applyPendingBookmarkJump();
|
||||
|
||||
FsFile f;
|
||||
if (Storage.openFileForRead("ERS", epub->getCachePath() + "/progress.bin", f)) {
|
||||
@@ -145,6 +147,9 @@ void EpubReaderActivity::onExit() {
|
||||
|
||||
// Save bookmarks before exit
|
||||
bookmarkStore.save();
|
||||
if (epub) {
|
||||
GLOBAL_BOOKMARKS.syncFromStore(bookmarkStore, epub->getPath(), epub->getCachePath(), epub->getTitle(), false);
|
||||
}
|
||||
|
||||
// Reset orientation back to portrait for the rest of the UI
|
||||
renderer.setOrientation(GfxRenderer::Orientation::Portrait);
|
||||
@@ -562,6 +567,8 @@ void EpubReaderActivity::onReaderMenuConfirm(EpubReaderMenuActivity::MenuAction
|
||||
if (!bookmarkStore.isEmpty()) {
|
||||
bookmarkStore.markDirty();
|
||||
bookmarkStore.save();
|
||||
GLOBAL_BOOKMARKS.syncFromStore(bookmarkStore, epub->getPath(), epub->getCachePath(), epub->getTitle(),
|
||||
false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -691,6 +698,25 @@ void EpubReaderActivity::applyPendingSyncSession() {
|
||||
logReaderMemSnapshot("after_apply_pending_sync_session");
|
||||
}
|
||||
|
||||
void EpubReaderActivity::applyPendingBookmarkJump() {
|
||||
auto& jump = APP_STATE.pendingBookmarkJump;
|
||||
if (!jump.active || !epub || jump.bookPath != epub->getPath()) {
|
||||
return;
|
||||
}
|
||||
LOG_DBG("ERS", "Applying pending bookmark jump: spine=%u page=%u", jump.spineIndex, jump.pageNumber);
|
||||
if (writeReaderProgressCache(epub->getCachePath(), jump.spineIndex, jump.pageNumber, 0)) {
|
||||
cachedSpineIndex = jump.spineIndex;
|
||||
cachedChapterTotalPageCount = 0;
|
||||
} else {
|
||||
currentSpineIndex = jump.spineIndex;
|
||||
nextPageNumber = jump.pageNumber;
|
||||
cachedSpineIndex = jump.spineIndex;
|
||||
cachedChapterTotalPageCount = 0;
|
||||
}
|
||||
jump.clear();
|
||||
APP_STATE.saveToFile();
|
||||
}
|
||||
|
||||
void EpubReaderActivity::applyOrientation(const uint8_t orientation) {
|
||||
// No-op if the selected orientation matches current settings.
|
||||
if (SETTINGS.orientation == orientation) {
|
||||
|
||||
@@ -80,6 +80,10 @@ class EpubReaderActivity final : public Activity {
|
||||
// reader startup path reads it. Upload-complete leaves the existing local
|
||||
// progress.bin untouched and simply clears the pending session marker.
|
||||
void applyPendingSyncSession();
|
||||
// Consume a persisted bookmark-jump request (from GlobalBookmarksActivity) for
|
||||
// this book. Rewrites progress.bin to the bookmarked position before the normal
|
||||
// reader startup path reads it.
|
||||
void applyPendingBookmarkJump();
|
||||
void applyOrientation(uint8_t orientation);
|
||||
void applyTextDarkness(uint8_t textDarkness);
|
||||
void toggleAutoPageTurn(uint8_t selectedPageTurnOption);
|
||||
|
||||
@@ -8,17 +8,6 @@
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
int StarredPagesActivity::getPageItems() const {
|
||||
constexpr int lineHeight = 30;
|
||||
const int screenHeight = renderer.getScreenHeight();
|
||||
const auto orientation = renderer.getOrientation();
|
||||
const bool isPortraitInverted = orientation == GfxRenderer::Orientation::PortraitInverted;
|
||||
const int hintGutterHeight = isPortraitInverted ? 50 : 0;
|
||||
const int startY = 60 + hintGutterHeight;
|
||||
const int availableHeight = screenHeight - startY - lineHeight;
|
||||
return std::max(1, availableHeight / lineHeight);
|
||||
}
|
||||
|
||||
std::string StarredPagesActivity::getDefaultLabel(int index) const {
|
||||
const auto& bm = bookmarkStore.getAll()[index];
|
||||
char buf[64];
|
||||
@@ -76,7 +65,6 @@ void StarredPagesActivity::deleteSelected() {
|
||||
bookmarkStore.removeAt(selectorIndex);
|
||||
const int remaining = static_cast<int>(bookmarkStore.getAll().size());
|
||||
if (remaining == 0) {
|
||||
// Nothing left — drop back to the reader.
|
||||
ActivityResult result;
|
||||
result.isCancelled = true;
|
||||
setResult(std::move(result));
|
||||
@@ -89,16 +77,6 @@ void StarredPagesActivity::deleteSelected() {
|
||||
|
||||
void StarredPagesActivity::loop() {
|
||||
const int totalItems = static_cast<int>(bookmarkStore.getAll().size());
|
||||
const int pageItems = getPageItems();
|
||||
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
if (totalItems > 0) {
|
||||
const auto& bm = bookmarkStore.getAll()[selectorIndex];
|
||||
setResult(StarredPageResult{bm.spineIndex, bm.pageNumber});
|
||||
finish();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||
ActivityResult result;
|
||||
@@ -108,6 +86,15 @@ void StarredPagesActivity::loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (totalItems == 0) return;
|
||||
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
const auto& bm = bookmarkStore.getAll()[selectorIndex];
|
||||
setResult(StarredPageResult{bm.spineIndex, bm.pageNumber});
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Left)) {
|
||||
startRename();
|
||||
return;
|
||||
@@ -118,23 +105,24 @@ void StarredPagesActivity::loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Side buttons (Up/Down) drive list navigation; Left/Right are reserved for rename/delete.
|
||||
buttonNavigator.onRelease({MappedInputManager::Button::Down}, [this, totalItems] {
|
||||
const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, false);
|
||||
|
||||
buttonNavigator.onNextRelease([this, totalItems] {
|
||||
selectorIndex = ButtonNavigator::nextIndex(selectorIndex, totalItems);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onRelease({MappedInputManager::Button::Up}, [this, totalItems] {
|
||||
buttonNavigator.onPreviousRelease([this, totalItems] {
|
||||
selectorIndex = ButtonNavigator::previousIndex(selectorIndex, totalItems);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onContinuous({MappedInputManager::Button::Down}, [this, totalItems, pageItems] {
|
||||
buttonNavigator.onNextContinuous([this, totalItems, pageItems] {
|
||||
selectorIndex = ButtonNavigator::nextPageIndex(selectorIndex, totalItems, pageItems);
|
||||
requestUpdate();
|
||||
});
|
||||
|
||||
buttonNavigator.onContinuous({MappedInputManager::Button::Up}, [this, totalItems, pageItems] {
|
||||
buttonNavigator.onPreviousContinuous([this, totalItems, pageItems] {
|
||||
selectorIndex = ButtonNavigator::previousPageIndex(selectorIndex, totalItems, pageItems);
|
||||
requestUpdate();
|
||||
});
|
||||
@@ -143,48 +131,30 @@ void StarredPagesActivity::loop() {
|
||||
void StarredPagesActivity::render(RenderLock&&) {
|
||||
renderer.clearScreen();
|
||||
|
||||
const auto& metrics = UITheme::getInstance().getMetrics();
|
||||
const Rect contentRect = UITheme::getContentRect(renderer, true, true);
|
||||
|
||||
GUI.drawHeader(renderer, Rect{contentRect.x, metrics.topPadding, contentRect.width, metrics.headerHeight},
|
||||
tr(STR_STARRED_PAGES));
|
||||
|
||||
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
|
||||
const int contentHeight = contentRect.height - contentTop - metrics.verticalSpacing;
|
||||
|
||||
const int totalItems = static_cast<int>(bookmarkStore.getAll().size());
|
||||
|
||||
if (totalItems == 0) {
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, 300, tr(STR_NO_STARRED_PAGES), true, EpdFontFamily::BOLD);
|
||||
renderer.displayBuffer();
|
||||
return;
|
||||
renderer.drawText(UI_10_FONT_ID, contentRect.x + metrics.contentSidePadding, contentTop + 20,
|
||||
tr(STR_NO_STARRED_PAGES));
|
||||
} else {
|
||||
GUI.drawList(renderer, Rect{contentRect.x, contentTop, contentRect.width, contentHeight}, totalItems, selectorIndex,
|
||||
[this](int index) { return getItemLabel(index); });
|
||||
}
|
||||
|
||||
const auto pageWidth = renderer.getScreenWidth();
|
||||
const auto orientation = renderer.getOrientation();
|
||||
const bool isLandscapeCw = orientation == GfxRenderer::Orientation::LandscapeClockwise;
|
||||
const bool isLandscapeCcw = orientation == GfxRenderer::Orientation::LandscapeCounterClockwise;
|
||||
const bool isPortraitInverted = orientation == GfxRenderer::Orientation::PortraitInverted;
|
||||
const int hintGutterWidth = (isLandscapeCw || isLandscapeCcw) ? 30 : 0;
|
||||
const int contentX = isLandscapeCw ? hintGutterWidth : 0;
|
||||
const int contentWidth = pageWidth - hintGutterWidth;
|
||||
const int hintGutterHeight = isPortraitInverted ? 50 : 0;
|
||||
const int contentY = hintGutterHeight;
|
||||
const int pageItems = getPageItems();
|
||||
|
||||
// Title
|
||||
const int titleX =
|
||||
contentX + (contentWidth - renderer.getTextWidth(UI_12_FONT_ID, tr(STR_STARRED_PAGES), EpdFontFamily::BOLD)) / 2;
|
||||
renderer.drawText(UI_12_FONT_ID, titleX, 15 + contentY, tr(STR_STARRED_PAGES), true, EpdFontFamily::BOLD);
|
||||
|
||||
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
|
||||
|
||||
// Highlight selection
|
||||
renderer.fillRect(contentX, 60 + contentY + (selectorIndex % pageItems) * 30 - 2, contentWidth - 1, 30);
|
||||
|
||||
for (int i = 0; i < pageItems; i++) {
|
||||
int itemIndex = pageStartIndex + i;
|
||||
if (itemIndex >= totalItems) break;
|
||||
const int displayY = 60 + contentY + i * 30;
|
||||
const bool isSelected = (itemIndex == selectorIndex);
|
||||
|
||||
const std::string label = renderer.truncatedText(UI_10_FONT_ID, getItemLabel(itemIndex).c_str(), contentWidth - 40);
|
||||
renderer.drawText(UI_10_FONT_ID, contentX + 20, displayY, label.c_str(), !isSelected);
|
||||
}
|
||||
|
||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SELECT), tr(STR_RENAME), tr(STR_DELETE));
|
||||
const bool hasItems = totalItems > 0;
|
||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), hasItems ? tr(STR_SELECT) : "",
|
||||
hasItems ? tr(STR_RENAME) : "", hasItems ? tr(STR_DELETE) : "");
|
||||
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
GUI.drawSideButtonHints(renderer, tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
||||
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ class StarredPagesActivity final : public Activity {
|
||||
ButtonNavigator buttonNavigator;
|
||||
int selectorIndex = 0;
|
||||
|
||||
int getPageItems() const;
|
||||
std::string getItemLabel(int index) const;
|
||||
std::string getDefaultLabel(int index) const;
|
||||
void startRename();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "CrossPointSettings.h"
|
||||
#include "CrossPointState.h"
|
||||
#include "GlobalBookmarkIndex.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "ReaderUtils.h"
|
||||
#include "RecentBooksStore.h"
|
||||
@@ -99,6 +100,7 @@ void TxtReaderActivity::onEnter() {
|
||||
}
|
||||
|
||||
txt->setupCacheDir();
|
||||
applyPendingBookmarkJump();
|
||||
|
||||
// Load bookmarks for this file
|
||||
bookmarkStore.load(txt->getCachePath());
|
||||
@@ -119,6 +121,9 @@ void TxtReaderActivity::onExit() {
|
||||
|
||||
// Save bookmarks before exit
|
||||
bookmarkStore.save();
|
||||
if (txt) {
|
||||
GLOBAL_BOOKMARKS.syncFromStore(bookmarkStore, txt->getPath(), txt->getCachePath(), txt->getTitle(), true);
|
||||
}
|
||||
|
||||
// Reset orientation back to portrait for the rest of the UI
|
||||
renderer.setOrientation(GfxRenderer::Orientation::Portrait);
|
||||
@@ -428,6 +433,34 @@ void TxtReaderActivity::saveProgress() const {
|
||||
}
|
||||
}
|
||||
|
||||
void TxtReaderActivity::applyPendingBookmarkJump() {
|
||||
auto& jump = APP_STATE.pendingBookmarkJump;
|
||||
if (!jump.active || !txt || jump.bookPath != txt->getPath()) {
|
||||
return;
|
||||
}
|
||||
LOG_DBG("TRS", "Applying pending bookmark jump: page=%u", jump.pageNumber);
|
||||
|
||||
bool persisted = false;
|
||||
FsFile f;
|
||||
if (Storage.openFileForWrite("TRS", txt->getCachePath() + "/progress.bin", f)) {
|
||||
uint8_t data[6] = {0};
|
||||
data[0] = jump.pageNumber & 0xFF;
|
||||
data[1] = (jump.pageNumber >> 8) & 0xFF;
|
||||
// Offset bytes stay 0: loadProgress reads only the page, and the lazy
|
||||
// initializeReader() rebuilds the page index on first render anyway.
|
||||
if (f.write(data, 6) == 6) {
|
||||
persisted = f.close();
|
||||
} else {
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (persisted) {
|
||||
jump.clear();
|
||||
APP_STATE.saveToFile();
|
||||
}
|
||||
}
|
||||
|
||||
void TxtReaderActivity::loadProgress() {
|
||||
FsFile f;
|
||||
if (Storage.openFileForRead("TRS", txt->getCachePath() + "/progress.bin", f)) {
|
||||
|
||||
@@ -46,6 +46,9 @@ class TxtReaderActivity final : public Activity {
|
||||
void savePageIndexCache() const;
|
||||
void saveProgress() const;
|
||||
void loadProgress();
|
||||
// Consume a persisted bookmark-jump request (from GlobalBookmarksActivity) for
|
||||
// this TXT file. Rewrites progress.bin before initializeReader() reads it.
|
||||
void applyPendingBookmarkJump();
|
||||
|
||||
public:
|
||||
explicit TxtReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::unique_ptr<Txt> txt)
|
||||
|
||||
Reference in New Issue
Block a user