| 54 | } |
| 55 | |
| 56 | void XtcReaderActivity::loop() { |
| 57 | // Enter chapter selection activity |
| 58 | if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { |
| 59 | if (xtc && xtc->hasChapters() && !xtc->getChapters().empty()) { |
| 60 | startActivityForResult( |
| 61 | std::make_unique<XtcReaderChapterSelectionActivity>(renderer, mappedInput, xtc, currentPage), |
| 62 | [this](const ActivityResult& result) { |
| 63 | if (!result.isCancelled) { |
| 64 | currentPage = std::get<PageResult>(result.data).page; |
| 65 | } |
| 66 | }); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Long press BACK (1s+) goes to file selection |
| 71 | if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS) { |
| 72 | activityManager.goToFileBrowser(xtc ? xtc->getPath() : ""); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | // Short press BACK goes directly to home |
| 77 | if (mappedInput.wasReleased(MappedInputManager::Button::Back) && |
| 78 | mappedInput.getHeldTime() < ReaderUtils::GO_HOME_MS) { |
| 79 | onGoHome(); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | const auto [prevTriggered, nextTriggered, fromTilt] = ReaderUtils::detectPageTurn(mappedInput); |
| 84 | if (!prevTriggered && !nextTriggered) { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | // At end of the book, forward button goes home and back button returns to last page |
| 89 | if (currentPage >= xtc->getPageCount()) { |
| 90 | if (nextTriggered) { |
| 91 | onGoHome(); |
| 92 | } else { |
| 93 | currentPage = xtc->getPageCount() - 1; |
| 94 | requestUpdate(); |
| 95 | } |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | const bool skipPages = !fromTilt && SETTINGS.longPressButtonBehavior == SETTINGS.CHAPTER_SKIP && |
| 100 | mappedInput.getHeldTime() > ReaderUtils::SKIP_HOLD_MS; |
| 101 | const int skipAmount = skipPages ? 10 : 1; |
| 102 | |
| 103 | if (prevTriggered) { |
| 104 | if (currentPage >= static_cast<uint32_t>(skipAmount)) { |
| 105 | currentPage -= skipAmount; |
| 106 | } else { |
| 107 | currentPage = 0; |
| 108 | } |
| 109 | requestUpdate(); |
| 110 | } else if (nextTriggered) { |
| 111 | currentPage += skipAmount; |
| 112 | if (currentPage >= xtc->getPageCount()) { |
| 113 | currentPage = xtc->getPageCount(); // Allow showing "End of book" |
nothing calls this directly
no test coverage detected