Review comments

This commit is contained in:
jpirnay
2026-04-26 17:57:26 +02:00
parent 812269057d
commit edf7ce1ae2
10 changed files with 85 additions and 48 deletions
+2 -2
View File
@@ -184,8 +184,8 @@ bool CrossPointSettings::loadFromBinaryFile() {
readAndValidate(inputFile, hideBatteryPercentage, HIDE_BATTERY_PERCENTAGE_COUNT);
if (++settingsRead >= fileSettingsCount) break;
{
uint8_t _unused;
serialization::readPod(inputFile, _unused);
uint8_t ignored;
serialization::readPod(inputFile, ignored);
} // was longPressChapterSkip
if (++settingsRead >= fileSettingsCount) break;
serialization::readPod(inputFile, hyphenationEnabled);
+1 -1
View File
@@ -313,7 +313,7 @@ class CrossPointSettings {
// Get singleton instance
static CrossPointSettings& getInstance() { return instance; }
uint16_t getPowerButtonDuration() const { return 400; }
static constexpr uint16_t getPowerButtonDuration() { return 400; }
int getReaderFontId() const;
// If count_only is true, returns the number of settings items that would be written.
+1 -1
View File
@@ -390,7 +390,7 @@ bool ActivityManager::isReaderActivity() const { return currentActivity && curre
bool ActivityManager::skipLoopDelay() const { return currentActivity && currentActivity->skipLoopDelay(); }
void ActivityManager::dispatchButtonAction(const CrossPointSettings::BUTTON_ACTION action) {
if (currentActivity) {
if (currentActivity && currentActivity->isReaderActivity()) {
currentActivity->onButtonAction(action);
}
}
+32 -29
View File
@@ -1813,6 +1813,7 @@ void EpubReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION
const int spineIdx = currentSpineIndex;
const int tocIdx = section ? section->getTocIndexForPage(section->currentPage)
: epub->getTocIndexForSpineIndex(currentSpineIndex);
ReaderUtils::enforceExitFullRefresh(renderer);
startActivityForResult(std::make_unique<EpubReaderChapterSelectionActivity>(renderer, mappedInput, epub,
epub->getPath(), spineIdx, tocIdx),
[this](const ActivityResult& result) {
@@ -1837,39 +1838,41 @@ void EpubReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION
case BA::BTN_NEXT_SECTION:
case BA::BTN_PREV_SECTION: {
const bool forward = (action == BA::BTN_NEXT_SECTION);
RenderLock lock(*this);
if (section && section->pageCount > 0) {
const int curTocIndex = section->getTocIndexForPage(section->currentPage);
const int nextTocIndex = forward ? curTocIndex + 1 : curTocIndex - 1;
if (curTocIndex < 0) {
{
RenderLock lock(*this);
if (section && section->pageCount > 0) {
const int curTocIndex = section->getTocIndexForPage(section->currentPage);
const int nextTocIndex = forward ? curTocIndex + 1 : curTocIndex - 1;
if (curTocIndex < 0) {
nextPageNumber = 0;
currentSpineIndex = forward ? currentSpineIndex + 1 : currentSpineIndex - 1;
section.reset();
} else if (nextTocIndex >= 0 && nextTocIndex < epub->getTocItemsCount()) {
const int newSpineIndex = epub->getSpineIndexForTocIndex(nextTocIndex);
if (newSpineIndex == currentSpineIndex) {
if (const auto resolvedPage = section->getPageForTocIndex(nextTocIndex)) {
section->currentPage = *resolvedPage;
}
} else {
pendingTocIndex = nextTocIndex;
nextPageNumber = 0;
currentSpineIndex = newSpineIndex;
section.reset();
}
} else if (forward) {
nextPageNumber = 0;
currentSpineIndex = epub->getSpineItemsCount();
section.reset();
} else {
nextPageNumber = 0;
currentSpineIndex = epub->getTocItem(curTocIndex).spineIndex - 1;
section.reset();
}
} else {
nextPageNumber = 0;
currentSpineIndex = forward ? currentSpineIndex + 1 : currentSpineIndex - 1;
section.reset();
} else if (nextTocIndex >= 0 && nextTocIndex < epub->getTocItemsCount()) {
const int newSpineIndex = epub->getSpineIndexForTocIndex(nextTocIndex);
if (newSpineIndex == currentSpineIndex) {
if (const auto resolvedPage = section->getPageForTocIndex(nextTocIndex)) {
section->currentPage = *resolvedPage;
}
} else {
pendingTocIndex = nextTocIndex;
nextPageNumber = 0;
currentSpineIndex = newSpineIndex;
section.reset();
}
} else if (forward) {
nextPageNumber = 0;
currentSpineIndex = epub->getSpineItemsCount();
section.reset();
} else {
nextPageNumber = 0;
currentSpineIndex = epub->getTocItem(curTocIndex).spineIndex - 1;
section.reset();
}
} else {
nextPageNumber = 0;
currentSpineIndex = forward ? currentSpineIndex + 1 : currentSpineIndex - 1;
section.reset();
}
requestUpdate();
break;
@@ -897,6 +897,10 @@ void MdReaderActivity::savePageIndexCache() const {
void MdReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION action) {
using BA = CrossPointSettings::BUTTON_ACTION;
auto clampPage = [this]() {
if (totalPages == 0) {
currentPage = 0;
return;
}
if (currentPage < 0) currentPage = 0;
if (currentPage >= totalPages) currentPage = totalPages - 1;
};
+9 -3
View File
@@ -62,10 +62,16 @@ struct PageTurnResult {
};
inline PageTurnResult detectPageTurn(const MappedInputManager& input) {
// Only treat wasReleased as a page turn when the button's short-press action is default.
// Non-default short-press actions are dispatched by the global dispatcher in main.cpp;
// counting wasReleased as well would double-fire the action.
using BA = CrossPointSettings::BUTTON_ACTION;
const bool prev =
input.wasReleased(MappedInputManager::Button::PageBack) || input.wasReleased(MappedInputManager::Button::Left);
const bool next = input.wasReleased(MappedInputManager::Button::PageForward) ||
input.wasReleased(MappedInputManager::Button::Right);
(SETTINGS.btnShortPageBack == BA::BTN_DEFAULT && input.wasReleased(MappedInputManager::Button::PageBack)) ||
(SETTINGS.btnShortLeft == BA::BTN_DEFAULT && input.wasReleased(MappedInputManager::Button::Left));
const bool next =
(SETTINGS.btnShortPageForward == BA::BTN_DEFAULT && input.wasReleased(MappedInputManager::Button::PageForward)) ||
(SETTINGS.btnShortRight == BA::BTN_DEFAULT && input.wasReleased(MappedInputManager::Button::Right));
return {prev, next};
}
+14 -7
View File
@@ -806,15 +806,22 @@ void TxtReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION a
bookmarkStore.toggle(0, static_cast<uint16_t>(currentPage));
requestUpdate();
break;
case BA::BTN_NEXT_SECTION:
currentPage += 10;
clampPage();
requestUpdate();
case BA::BTN_OPEN_BOOKMARKS:
if (!bookmarkStore.isEmpty()) {
ReaderUtils::enforceExitFullRefresh(renderer);
startActivityForResult(std::make_unique<StarredPagesActivity>(renderer, mappedInput, bookmarkStore),
[this](const ActivityResult& result) {
if (!result.isCancelled) {
const auto& starred = std::get<StarredPageResult>(result.data);
currentPage = starred.pageNumber;
requestUpdate();
}
});
}
break;
case BA::BTN_NEXT_SECTION:
case BA::BTN_PREV_SECTION:
currentPage -= 10;
clampPage();
requestUpdate();
// TXT files have no headings/chapters; treat as unsupported (no-op).
break;
case BA::BTN_EXIT_READER:
ReaderUtils::enforceExitFullRefresh(renderer);
+20 -4
View File
@@ -460,12 +460,28 @@ void XtcReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION a
requestUpdate();
break;
case BA::BTN_NEXT_SECTION:
currentPage = (currentPage + 10 < pageCount) ? currentPage + 10 : pageCount - 1;
requestUpdate();
if (xtc->hasChapters()) {
const auto& chapters = xtc->getChapters();
for (const auto& ch : chapters) {
if (ch.startPage > currentPage) {
currentPage = ch.startPage;
requestUpdate();
break;
}
}
}
break;
case BA::BTN_PREV_SECTION:
currentPage = (currentPage >= 10) ? currentPage - 10 : 0;
requestUpdate();
if (xtc->hasChapters()) {
const auto& chapters = xtc->getChapters();
for (int i = static_cast<int>(chapters.size()) - 1; i >= 0; i--) {
if (chapters[i].startPage < currentPage) {
currentPage = chapters[i].startPage;
requestUpdate();
break;
}
}
}
break;
case BA::BTN_EXIT_READER:
ReaderUtils::enforceExitFullRefresh(renderer);
@@ -82,7 +82,6 @@ void SettingsActivity::onEnter() {
controlsSettings.insert(controlsSettings.begin(),
SettingInfo::Action(StrId::STR_REMAP_FRONT_BUTTONS, SettingAction::RemapFrontButtons));
controlsSettings.insert(controlsSettings.begin(), SettingInfo::Separator(StrId::STR_MENU_BTN_PHYSICAL));
lastControlsSub = StrId::STR_MENU_BTN_PHYSICAL;
addToMoved(readerSettings, lastReaderSub,
SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));
+2
View File
@@ -350,6 +350,8 @@ void loop() {
// Track power button hold for sleep. We require a fresh press edge (wasPressed)
// before starting to measure hold time, so that a hold carried over from boot
// (wake-up press) is never misinterpreted as a "go to sleep" press.
// The power button long-press is not user-remappable, so this path always owns it.
// Sleep mapped to other buttons is handled by the dispatcher's BTN_SLEEP case below.
static unsigned long powerHoldStart = 0;
if (gpio.wasPressed(HalGPIO::BTN_POWER)) {
powerHoldStart = millis();