feat: Add option to switch behavior for "back to browser / home" in Reader activity (#2366)

## Summary

It would be nice to switch back to the file list from an Reader activity
via a short back button press. This change adds an Reader option to
switch the default behavior, so a short back button press in the Reader
activity can now go back to the file list, and a long press on back goes
back to the home view. This does a fair bit of refactoring, introducing
a new constant for the ms limit.

* **What changes are included?**

- Changes to the translation
- Additional global Reader option 
- Refactoring of the back button behavior in the Reader activity
This commit is contained in:
Thomas Symalla
2026-07-19 08:29:13 +03:00
committed by GitHub
parent b1d037569b
commit 9fe4dc5e38
8 changed files with 51 additions and 31 deletions
+1
View File
@@ -343,6 +343,7 @@ STR_EMBEDDED_STYLE: "Embedded Style"
STR_FOCUS_READING: "Focus Reading" STR_FOCUS_READING: "Focus Reading"
STR_OPDS_SERVER_URL: "OPDS Server URL" STR_OPDS_SERVER_URL: "OPDS Server URL"
STR_PWR_BTN_FOOTNOTE_BACK: "Quick-return from footnotes" STR_PWR_BTN_FOOTNOTE_BACK: "Quick-return from footnotes"
STR_BACK_SHORT_TO_FILE_BROWSER: "Short Back to File Browser"
STR_SET_SLEEP_COVER: "Set Cover" STR_SET_SLEEP_COVER: "Set Cover"
STR_FOOTNOTES: "Footnotes" STR_FOOTNOTES: "Footnotes"
STR_NO_FOOTNOTES: "No footnotes on this page" STR_NO_FOOTNOTES: "No footnotes on this page"
+1
View File
@@ -315,6 +315,7 @@ STR_BOOK_S_STYLE: "Buch-Stil"
STR_EMBEDDED_STYLE: "Eingebetteter Stil" STR_EMBEDDED_STYLE: "Eingebetteter Stil"
STR_FOCUS_READING: "Fokus-Lesen" STR_FOCUS_READING: "Fokus-Lesen"
STR_OPDS_SERVER_URL: "OPDS-Server-URL" STR_OPDS_SERVER_URL: "OPDS-Server-URL"
STR_BACK_SHORT_TO_FILE_BROWSER: "Kurz zurück drücken zum Datei-Browser"
STR_SET_SLEEP_COVER: "Wähle Cover" STR_SET_SLEEP_COVER: "Wähle Cover"
STR_SCREENSHOT_BUTTON: "Screenshot aufnehmen" STR_SCREENSHOT_BUTTON: "Screenshot aufnehmen"
STR_FOOTNOTES: "Fußnoten" STR_FOOTNOTES: "Fußnoten"
+2
View File
@@ -271,6 +271,8 @@ class CrossPointSettings {
uint8_t removeReadBooksFromRecents = 0; uint8_t removeReadBooksFromRecents = 0;
// Move epub to /Read/ folder on SD card when finished (0 = disabled, 1 = enabled) // Move epub to /Read/ folder on SD card when finished (0 = disabled, 1 = enabled)
uint8_t moveFinishedToReadFolder = 0; uint8_t moveFinishedToReadFolder = 0;
// Short press Back goes to file browser instead of home (0 = disabled, 1 = enabled)
uint8_t backShortToFileBrowser = 0;
// Image rendering mode in EPUB reader // Image rendering mode in EPUB reader
uint8_t imageRendering = IMAGES_DISPLAY; uint8_t imageRendering = IMAGES_DISPLAY;
// Tilt-based page turning (X3 only — requires QMI8658 IMU) // Tilt-based page turning (X3 only — requires QMI8658 IMU)
+2
View File
@@ -181,6 +181,8 @@ inline std::vector<SettingInfo> getSettingsList(const SdCardFontRegistry* regist
"shortPwrBtn", StrId::STR_CAT_CONTROLS), "shortPwrBtn", StrId::STR_CAT_CONTROLS),
SettingInfo::Toggle(StrId::STR_PWR_BTN_FOOTNOTE_BACK, &CrossPointSettings::pwrBtnFootnoteBack, SettingInfo::Toggle(StrId::STR_PWR_BTN_FOOTNOTE_BACK, &CrossPointSettings::pwrBtnFootnoteBack,
"pwrBtnFootnoteBack", StrId::STR_CAT_CONTROLS), "pwrBtnFootnoteBack", StrId::STR_CAT_CONTROLS),
SettingInfo::Toggle(StrId::STR_BACK_SHORT_TO_FILE_BROWSER, &CrossPointSettings::backShortToFileBrowser,
"backShortToFileBrowser", StrId::STR_CAT_CONTROLS),
// --- System --- // --- System ---
SettingInfo::Value( SettingInfo::Value(
+6 -11
View File
@@ -448,20 +448,15 @@ void EpubReaderActivity::loop() {
} }
} }
// Long press BACK (1s+) goes to file selection // Short press Back restores position when viewing a footnote (takes priority over navigation)
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) { if (footnoteDepth > 0 && mappedInput.wasReleased(MappedInputManager::Button::Back) &&
activityManager.goToFileBrowser(epub ? epub->getPath() : ""); mappedInput.getHeldTime() < ReaderUtils::GO_BACK_OR_HOME_MS) {
return;
}
// Short press BACK goes directly to home (or restores position if viewing footnote)
if (mappedInput.wasReleased(MappedInputManager::Button::Back) &&
mappedInput.getHeldTime() < ReaderUtils::GO_HOME_MS) {
if (footnoteDepth > 0) {
restoreSavedPosition(); restoreSavedPosition();
return; return;
} }
onGoHome();
if (ReaderUtils::handleBackNavigation(mappedInput, activityManager, epub ? epub->getPath().c_str() : "",
{this, [](void* ctx) { static_cast<EpubReaderActivity*>(ctx)->onGoHome(); }})) {
return; return;
} }
+35
View File
@@ -6,10 +6,12 @@
#include <Logging.h> #include <Logging.h>
#include "MappedInputManager.h" #include "MappedInputManager.h"
#include "activities/ActivityManager.h"
namespace ReaderUtils { namespace ReaderUtils {
constexpr unsigned long GO_HOME_MS = 1000; constexpr unsigned long GO_HOME_MS = 1000;
constexpr unsigned long GO_BACK_OR_HOME_MS = GO_HOME_MS;
constexpr unsigned long SKIP_HOLD_MS = 700; constexpr unsigned long SKIP_HOLD_MS = 700;
constexpr unsigned long BOOKMARK_HOLD_MS = 400; constexpr unsigned long BOOKMARK_HOLD_MS = 400;
constexpr unsigned long BOOKMARK_MESSAGE_DURATION_MS = 2500; constexpr unsigned long BOOKMARK_MESSAGE_DURATION_MS = 2500;
@@ -96,4 +98,37 @@ void renderAntiAliased(GfxRenderer& renderer, RenderFn&& renderFn) {
renderer.restoreBwBuffer(); renderer.restoreBwBuffer();
} }
struct BackNavCallback {
void* ctx;
void (*fn)(void*);
};
// Returns true if the back button was consumed (caller should return).
// Long press (>= GO_BACK_OR_HOME_MS):
// - default: go to file browser
// - with backShortToFileBrowser: go home
// Short press (< GO_BACK_OR_HOME_MS):
// - default: go home
// - with backShortToFileBrowser: go to file browser.
inline bool handleBackNavigation(const MappedInputManager& mappedInput, ActivityManager& activityManager,
const char* filePath, BackNavCallback goHome) {
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= GO_BACK_OR_HOME_MS) {
if (SETTINGS.backShortToFileBrowser) {
goHome.fn(goHome.ctx);
} else {
activityManager.goToFileBrowser(filePath);
}
return true;
}
if (mappedInput.wasReleased(MappedInputManager::Button::Back) && mappedInput.getHeldTime() < GO_BACK_OR_HOME_MS) {
if (SETTINGS.backShortToFileBrowser) {
activityManager.goToFileBrowser(filePath);
} else {
goHome.fn(goHome.ctx);
}
return true;
}
return false;
}
} // namespace ReaderUtils } // namespace ReaderUtils
+2 -10
View File
@@ -60,16 +60,8 @@ void TxtReaderActivity::onExit() {
} }
void TxtReaderActivity::loop() { void TxtReaderActivity::loop() {
// Long press BACK (1s+) goes to file selection if (ReaderUtils::handleBackNavigation(mappedInput, activityManager, txt ? txt->getPath().c_str() : "",
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) { {this, [](void* ctx) { static_cast<TxtReaderActivity*>(ctx)->onGoHome(); }})) {
activityManager.goToFileBrowser(txt ? txt->getPath() : "");
return;
}
// Short press BACK goes directly to home
if (mappedInput.wasReleased(MappedInputManager::Button::Back) &&
mappedInput.getHeldTime() < ReaderUtils::GO_HOME_MS) {
onGoHome();
return; return;
} }
+2 -10
View File
@@ -101,16 +101,8 @@ void XtcReaderActivity::loop() {
openChapterSelection(); openChapterSelection();
} }
// Long press BACK (1s+) goes to file selection if (ReaderUtils::handleBackNavigation(mappedInput, activityManager, xtc ? xtc->getPath().c_str() : "",
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) { {this, [](void* ctx) { static_cast<XtcReaderActivity*>(ctx)->onGoHome(); }})) {
activityManager.goToFileBrowser(xtc ? xtc->getPath() : "");
return;
}
// Short press BACK goes directly to home
if (mappedInput.wasReleased(MappedInputManager::Button::Back) &&
mappedInput.getHeldTime() < ReaderUtils::GO_HOME_MS) {
onGoHome();
return; return;
} }