Merge pull request #20 from jpirnay/feat-reader-back
feat: Short press will go back to origin / long press will go back to home
This commit is contained in:
@@ -12,7 +12,7 @@ void Activity::requestUpdateAndWait() { activityManager.requestUpdateAndWait();
|
|||||||
|
|
||||||
void Activity::onGoHome() { activityManager.goHome(); }
|
void Activity::onGoHome() { activityManager.goHome(); }
|
||||||
|
|
||||||
void Activity::onSelectBook(const std::string& path) { activityManager.goToReader(path); }
|
void Activity::onSelectBook(const std::string& path) { activityManager.pushReader(path); }
|
||||||
|
|
||||||
void Activity::startActivityForResult(std::unique_ptr<Activity>&& activity, ActivityResultHandler resultHandler) {
|
void Activity::startActivityForResult(std::unique_ptr<Activity>&& activity, ActivityResultHandler resultHandler) {
|
||||||
this->resultHandler = std::move(resultHandler);
|
this->resultHandler = std::move(resultHandler);
|
||||||
|
|||||||
@@ -200,6 +200,10 @@ void ActivityManager::goToReader(std::string path) {
|
|||||||
replaceActivity(std::make_unique<ReaderActivity>(renderer, mappedInput, std::move(path)));
|
replaceActivity(std::make_unique<ReaderActivity>(renderer, mappedInput, std::move(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ActivityManager::pushReader(std::string path) {
|
||||||
|
pushActivity(std::make_unique<ReaderActivity>(renderer, mappedInput, std::move(path)));
|
||||||
|
}
|
||||||
|
|
||||||
void ActivityManager::goToSleep() {
|
void ActivityManager::goToSleep() {
|
||||||
replaceActivity(std::make_unique<SleepActivity>(renderer, mappedInput));
|
replaceActivity(std::make_unique<SleepActivity>(renderer, mappedInput));
|
||||||
loop(); // Important: sleep screen must be rendered immediately, the caller will go to sleep right after this returns
|
loop(); // Important: sleep screen must be rendered immediately, the caller will go to sleep right after this returns
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ class ActivityManager {
|
|||||||
void goToRecentBooks();
|
void goToRecentBooks();
|
||||||
void goToBrowser();
|
void goToBrowser();
|
||||||
void goToReader(std::string path);
|
void goToReader(std::string path);
|
||||||
|
void pushReader(std::string path);
|
||||||
void goToSleep();
|
void goToSleep();
|
||||||
void goToBoot();
|
void goToBoot();
|
||||||
void goToFullScreenMessage(std::string message, EpdFontFamily::Style style = EpdFontFamily::REGULAR);
|
void goToFullScreenMessage(std::string message, EpdFontFamily::Style style = EpdFontFamily::REGULAR);
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ void HomeActivity::render(RenderLock&&) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HomeActivity::onSelectBook(const std::string& path) { activityManager.goToReader(path); }
|
void HomeActivity::onSelectBook(const std::string& path) { activityManager.pushReader(path); }
|
||||||
|
|
||||||
void HomeActivity::onFileBrowserOpen() { activityManager.goToFileBrowser(); }
|
void HomeActivity::onFileBrowserOpen() { activityManager.goToFileBrowser(); }
|
||||||
|
|
||||||
|
|||||||
@@ -183,20 +183,20 @@ void EpubReaderActivity::loop() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Long press BACK (1s+) goes to file selection
|
// Long press BACK (1s+) goes to home screen
|
||||||
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) {
|
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) {
|
||||||
activityManager.goToFileBrowser(epub ? epub->getPath() : "");
|
onGoHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Short press BACK goes directly to home (or restores position if viewing footnote)
|
// Short press BACK returns to the calling activity (or restores position if viewing footnote)
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Back) &&
|
if (mappedInput.wasReleased(MappedInputManager::Button::Back) &&
|
||||||
mappedInput.getHeldTime() < ReaderUtils::GO_HOME_MS) {
|
mappedInput.getHeldTime() < ReaderUtils::GO_HOME_MS) {
|
||||||
if (footnoteDepth > 0) {
|
if (footnoteDepth > 0) {
|
||||||
restoreSavedPosition();
|
restoreSavedPosition();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
onGoHome();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,10 +205,10 @@ void EpubReaderActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// At end of the book, forward button goes home and back button returns to last page
|
// At end of the book, forward button returns to caller and back button returns to last page
|
||||||
if (currentSpineIndex > 0 && currentSpineIndex >= epub->getSpineItemsCount()) {
|
if (currentSpineIndex > 0 && currentSpineIndex >= epub->getSpineItemsCount()) {
|
||||||
if (nextTriggered) {
|
if (nextTriggered) {
|
||||||
onGoHome();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
currentSpineIndex = epub->getSpineItemsCount() - 1;
|
currentSpineIndex = epub->getSpineItemsCount() - 1;
|
||||||
nextPageNumber = UINT16_MAX;
|
nextPageNumber = UINT16_MAX;
|
||||||
|
|||||||
@@ -88,23 +88,27 @@ void ReaderActivity::goToLibrary(const std::string& fromBookPath) {
|
|||||||
void ReaderActivity::onGoToEpubReader(std::unique_ptr<Epub> epub) {
|
void ReaderActivity::onGoToEpubReader(std::unique_ptr<Epub> epub) {
|
||||||
const auto epubPath = epub->getPath();
|
const auto epubPath = epub->getPath();
|
||||||
currentBookPath = epubPath;
|
currentBookPath = epubPath;
|
||||||
activityManager.replaceActivity(std::make_unique<EpubReaderActivity>(renderer, mappedInput, std::move(epub)));
|
startActivityForResult(std::make_unique<EpubReaderActivity>(renderer, mappedInput, std::move(epub)),
|
||||||
|
[this](const ActivityResult&) { finish(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReaderActivity::onGoToBmpViewer(const std::string& path) {
|
void ReaderActivity::onGoToBmpViewer(const std::string& path) {
|
||||||
activityManager.replaceActivity(std::make_unique<BmpViewerActivity>(renderer, mappedInput, path));
|
startActivityForResult(std::make_unique<BmpViewerActivity>(renderer, mappedInput, path),
|
||||||
|
[this](const ActivityResult&) { finish(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReaderActivity::onGoToXtcReader(std::unique_ptr<Xtc> xtc) {
|
void ReaderActivity::onGoToXtcReader(std::unique_ptr<Xtc> xtc) {
|
||||||
const auto xtcPath = xtc->getPath();
|
const auto xtcPath = xtc->getPath();
|
||||||
currentBookPath = xtcPath;
|
currentBookPath = xtcPath;
|
||||||
activityManager.replaceActivity(std::make_unique<XtcReaderActivity>(renderer, mappedInput, std::move(xtc)));
|
startActivityForResult(std::make_unique<XtcReaderActivity>(renderer, mappedInput, std::move(xtc)),
|
||||||
|
[this](const ActivityResult&) { finish(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReaderActivity::onGoToTxtReader(std::unique_ptr<Txt> txt) {
|
void ReaderActivity::onGoToTxtReader(std::unique_ptr<Txt> txt) {
|
||||||
const auto txtPath = txt->getPath();
|
const auto txtPath = txt->getPath();
|
||||||
currentBookPath = txtPath;
|
currentBookPath = txtPath;
|
||||||
activityManager.replaceActivity(std::make_unique<TxtReaderActivity>(renderer, mappedInput, std::move(txt)));
|
startActivityForResult(std::make_unique<TxtReaderActivity>(renderer, mappedInput, std::move(txt)),
|
||||||
|
[this](const ActivityResult&) { finish(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReaderActivity::onEnter() {
|
void ReaderActivity::onEnter() {
|
||||||
|
|||||||
@@ -117,16 +117,16 @@ void TxtReaderActivity::onExit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TxtReaderActivity::loop() {
|
void TxtReaderActivity::loop() {
|
||||||
// Long press BACK (1s+) goes to file selection
|
// Long press BACK (1s+) goes to home screen
|
||||||
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) {
|
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) {
|
||||||
activityManager.goToFileBrowser(txt ? txt->getPath() : "");
|
onGoHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Short press BACK goes directly to home
|
// Short press BACK returns to the calling activity
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Back) &&
|
if (mappedInput.wasReleased(MappedInputManager::Button::Back) &&
|
||||||
mappedInput.getHeldTime() < ReaderUtils::GO_HOME_MS) {
|
mappedInput.getHeldTime() < ReaderUtils::GO_HOME_MS) {
|
||||||
onGoHome();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ void TxtReaderActivity::loop() {
|
|||||||
currentPage++;
|
currentPage++;
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
} else {
|
} else {
|
||||||
onGoHome();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,15 +71,15 @@ void XtcReaderActivity::loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Long press BACK (1s+) goes to file selection
|
// Long press BACK (1s+) goes to home screen
|
||||||
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= goHomeMs) {
|
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= goHomeMs) {
|
||||||
activityManager.goToFileBrowser(xtc ? xtc->getPath() : "");
|
onGoHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Short press BACK goes directly to home
|
// Short press BACK returns to the calling activity
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Back) && mappedInput.getHeldTime() < goHomeMs) {
|
if (mappedInput.wasReleased(MappedInputManager::Button::Back) && mappedInput.getHeldTime() < goHomeMs) {
|
||||||
onGoHome();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,10 +101,10 @@ void XtcReaderActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// At end of the book, forward button goes home and back button returns to last page
|
// At end of the book, forward button returns to caller and back button returns to last page
|
||||||
if (currentPage >= xtc->getPageCount()) {
|
if (currentPage >= xtc->getPageCount()) {
|
||||||
if (nextTriggered) {
|
if (nextTriggered) {
|
||||||
onGoHome();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
currentPage = xtc->getPageCount() - 1;
|
currentPage = xtc->getPageCount() - 1;
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
|
|||||||
Reference in New Issue
Block a user