Review comments
This commit is contained in:
@@ -184,8 +184,8 @@ bool CrossPointSettings::loadFromBinaryFile() {
|
|||||||
readAndValidate(inputFile, hideBatteryPercentage, HIDE_BATTERY_PERCENTAGE_COUNT);
|
readAndValidate(inputFile, hideBatteryPercentage, HIDE_BATTERY_PERCENTAGE_COUNT);
|
||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
{
|
{
|
||||||
uint8_t _unused;
|
uint8_t ignored;
|
||||||
serialization::readPod(inputFile, _unused);
|
serialization::readPod(inputFile, ignored);
|
||||||
} // was longPressChapterSkip
|
} // was longPressChapterSkip
|
||||||
if (++settingsRead >= fileSettingsCount) break;
|
if (++settingsRead >= fileSettingsCount) break;
|
||||||
serialization::readPod(inputFile, hyphenationEnabled);
|
serialization::readPod(inputFile, hyphenationEnabled);
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ class CrossPointSettings {
|
|||||||
// Get singleton instance
|
// Get singleton instance
|
||||||
static CrossPointSettings& getInstance() { return instance; }
|
static CrossPointSettings& getInstance() { return instance; }
|
||||||
|
|
||||||
uint16_t getPowerButtonDuration() const { return 400; }
|
static constexpr uint16_t getPowerButtonDuration() { return 400; }
|
||||||
int getReaderFontId() const;
|
int getReaderFontId() const;
|
||||||
|
|
||||||
// If count_only is true, returns the number of settings items that would be written.
|
// If count_only is true, returns the number of settings items that would be written.
|
||||||
|
|||||||
@@ -390,7 +390,7 @@ bool ActivityManager::isReaderActivity() const { return currentActivity && curre
|
|||||||
bool ActivityManager::skipLoopDelay() const { return currentActivity && currentActivity->skipLoopDelay(); }
|
bool ActivityManager::skipLoopDelay() const { return currentActivity && currentActivity->skipLoopDelay(); }
|
||||||
|
|
||||||
void ActivityManager::dispatchButtonAction(const CrossPointSettings::BUTTON_ACTION action) {
|
void ActivityManager::dispatchButtonAction(const CrossPointSettings::BUTTON_ACTION action) {
|
||||||
if (currentActivity) {
|
if (currentActivity && currentActivity->isReaderActivity()) {
|
||||||
currentActivity->onButtonAction(action);
|
currentActivity->onButtonAction(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1813,6 +1813,7 @@ void EpubReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION
|
|||||||
const int spineIdx = currentSpineIndex;
|
const int spineIdx = currentSpineIndex;
|
||||||
const int tocIdx = section ? section->getTocIndexForPage(section->currentPage)
|
const int tocIdx = section ? section->getTocIndexForPage(section->currentPage)
|
||||||
: epub->getTocIndexForSpineIndex(currentSpineIndex);
|
: epub->getTocIndexForSpineIndex(currentSpineIndex);
|
||||||
|
ReaderUtils::enforceExitFullRefresh(renderer);
|
||||||
startActivityForResult(std::make_unique<EpubReaderChapterSelectionActivity>(renderer, mappedInput, epub,
|
startActivityForResult(std::make_unique<EpubReaderChapterSelectionActivity>(renderer, mappedInput, epub,
|
||||||
epub->getPath(), spineIdx, tocIdx),
|
epub->getPath(), spineIdx, tocIdx),
|
||||||
[this](const ActivityResult& result) {
|
[this](const ActivityResult& result) {
|
||||||
@@ -1837,39 +1838,41 @@ void EpubReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION
|
|||||||
case BA::BTN_NEXT_SECTION:
|
case BA::BTN_NEXT_SECTION:
|
||||||
case BA::BTN_PREV_SECTION: {
|
case BA::BTN_PREV_SECTION: {
|
||||||
const bool forward = (action == BA::BTN_NEXT_SECTION);
|
const bool forward = (action == BA::BTN_NEXT_SECTION);
|
||||||
RenderLock lock(*this);
|
{
|
||||||
if (section && section->pageCount > 0) {
|
RenderLock lock(*this);
|
||||||
const int curTocIndex = section->getTocIndexForPage(section->currentPage);
|
if (section && section->pageCount > 0) {
|
||||||
const int nextTocIndex = forward ? curTocIndex + 1 : curTocIndex - 1;
|
const int curTocIndex = section->getTocIndexForPage(section->currentPage);
|
||||||
if (curTocIndex < 0) {
|
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;
|
nextPageNumber = 0;
|
||||||
currentSpineIndex = forward ? currentSpineIndex + 1 : currentSpineIndex - 1;
|
currentSpineIndex = forward ? currentSpineIndex + 1 : currentSpineIndex - 1;
|
||||||
section.reset();
|
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();
|
requestUpdate();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -897,6 +897,10 @@ void MdReaderActivity::savePageIndexCache() const {
|
|||||||
void MdReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION action) {
|
void MdReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION action) {
|
||||||
using BA = CrossPointSettings::BUTTON_ACTION;
|
using BA = CrossPointSettings::BUTTON_ACTION;
|
||||||
auto clampPage = [this]() {
|
auto clampPage = [this]() {
|
||||||
|
if (totalPages == 0) {
|
||||||
|
currentPage = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (currentPage < 0) currentPage = 0;
|
if (currentPage < 0) currentPage = 0;
|
||||||
if (currentPage >= totalPages) currentPage = totalPages - 1;
|
if (currentPage >= totalPages) currentPage = totalPages - 1;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,10 +62,16 @@ struct PageTurnResult {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline PageTurnResult detectPageTurn(const MappedInputManager& input) {
|
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 =
|
const bool prev =
|
||||||
input.wasReleased(MappedInputManager::Button::PageBack) || input.wasReleased(MappedInputManager::Button::Left);
|
(SETTINGS.btnShortPageBack == BA::BTN_DEFAULT && input.wasReleased(MappedInputManager::Button::PageBack)) ||
|
||||||
const bool next = input.wasReleased(MappedInputManager::Button::PageForward) ||
|
(SETTINGS.btnShortLeft == BA::BTN_DEFAULT && input.wasReleased(MappedInputManager::Button::Left));
|
||||||
input.wasReleased(MappedInputManager::Button::Right);
|
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};
|
return {prev, next};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -806,15 +806,22 @@ void TxtReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION a
|
|||||||
bookmarkStore.toggle(0, static_cast<uint16_t>(currentPage));
|
bookmarkStore.toggle(0, static_cast<uint16_t>(currentPage));
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
break;
|
break;
|
||||||
case BA::BTN_NEXT_SECTION:
|
case BA::BTN_OPEN_BOOKMARKS:
|
||||||
currentPage += 10;
|
if (!bookmarkStore.isEmpty()) {
|
||||||
clampPage();
|
ReaderUtils::enforceExitFullRefresh(renderer);
|
||||||
requestUpdate();
|
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;
|
break;
|
||||||
|
case BA::BTN_NEXT_SECTION:
|
||||||
case BA::BTN_PREV_SECTION:
|
case BA::BTN_PREV_SECTION:
|
||||||
currentPage -= 10;
|
// TXT files have no headings/chapters; treat as unsupported (no-op).
|
||||||
clampPage();
|
|
||||||
requestUpdate();
|
|
||||||
break;
|
break;
|
||||||
case BA::BTN_EXIT_READER:
|
case BA::BTN_EXIT_READER:
|
||||||
ReaderUtils::enforceExitFullRefresh(renderer);
|
ReaderUtils::enforceExitFullRefresh(renderer);
|
||||||
|
|||||||
@@ -460,12 +460,28 @@ void XtcReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION a
|
|||||||
requestUpdate();
|
requestUpdate();
|
||||||
break;
|
break;
|
||||||
case BA::BTN_NEXT_SECTION:
|
case BA::BTN_NEXT_SECTION:
|
||||||
currentPage = (currentPage + 10 < pageCount) ? currentPage + 10 : pageCount - 1;
|
if (xtc->hasChapters()) {
|
||||||
requestUpdate();
|
const auto& chapters = xtc->getChapters();
|
||||||
|
for (const auto& ch : chapters) {
|
||||||
|
if (ch.startPage > currentPage) {
|
||||||
|
currentPage = ch.startPage;
|
||||||
|
requestUpdate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BA::BTN_PREV_SECTION:
|
case BA::BTN_PREV_SECTION:
|
||||||
currentPage = (currentPage >= 10) ? currentPage - 10 : 0;
|
if (xtc->hasChapters()) {
|
||||||
requestUpdate();
|
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;
|
break;
|
||||||
case BA::BTN_EXIT_READER:
|
case BA::BTN_EXIT_READER:
|
||||||
ReaderUtils::enforceExitFullRefresh(renderer);
|
ReaderUtils::enforceExitFullRefresh(renderer);
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ void SettingsActivity::onEnter() {
|
|||||||
controlsSettings.insert(controlsSettings.begin(),
|
controlsSettings.insert(controlsSettings.begin(),
|
||||||
SettingInfo::Action(StrId::STR_REMAP_FRONT_BUTTONS, SettingAction::RemapFrontButtons));
|
SettingInfo::Action(StrId::STR_REMAP_FRONT_BUTTONS, SettingAction::RemapFrontButtons));
|
||||||
controlsSettings.insert(controlsSettings.begin(), SettingInfo::Separator(StrId::STR_MENU_BTN_PHYSICAL));
|
controlsSettings.insert(controlsSettings.begin(), SettingInfo::Separator(StrId::STR_MENU_BTN_PHYSICAL));
|
||||||
lastControlsSub = StrId::STR_MENU_BTN_PHYSICAL;
|
|
||||||
|
|
||||||
addToMoved(readerSettings, lastReaderSub,
|
addToMoved(readerSettings, lastReaderSub,
|
||||||
SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));
|
SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));
|
||||||
|
|||||||
@@ -350,6 +350,8 @@ void loop() {
|
|||||||
// Track power button hold for sleep. We require a fresh press edge (wasPressed)
|
// 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
|
// 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.
|
// (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;
|
static unsigned long powerHoldStart = 0;
|
||||||
if (gpio.wasPressed(HalGPIO::BTN_POWER)) {
|
if (gpio.wasPressed(HalGPIO::BTN_POWER)) {
|
||||||
powerHoldStart = millis();
|
powerHoldStart = millis();
|
||||||
|
|||||||
Reference in New Issue
Block a user