| 42 | } |
| 43 | |
| 44 | void RecentBooksActivity::loop() { |
| 45 | const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, true); |
| 46 | |
| 47 | // After a long-press has fired, swallow input until Confirm is physically released |
| 48 | // (so the release doesn't also open the book; re-arm only once the button is up). |
| 49 | if (longPressFired) { |
| 50 | if (!mappedInput.isPressed(MappedInputManager::Button::Confirm)) { |
| 51 | longPressFired = false; |
| 52 | } |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | // Long-press Confirm on the selected book: prompt to remove it from the list. |
| 57 | // Fires when the hold times out while still held (firmware hold-to-act pattern, |
| 58 | // cf. FileBrowserActivity BACK long-press). |
| 59 | if (!recentBooks.empty() && selectorIndex < recentBooks.size() && |
| 60 | mappedInput.isPressed(MappedInputManager::Button::Confirm) && mappedInput.getHeldTime() >= LONG_PRESS_MS) { |
| 61 | longPressFired = true; |
| 62 | promptRemoveBook(recentBooks[selectorIndex].path, recentBooks[selectorIndex].title); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { |
| 67 | if (!recentBooks.empty() && selectorIndex < static_cast<int>(recentBooks.size())) { |
| 68 | LOG_DBG("RBA", "Selected recent book: %s", recentBooks[selectorIndex].path.c_str()); |
| 69 | onSelectBook(recentBooks[selectorIndex].path); |
| 70 | return; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if (mappedInput.wasReleased(MappedInputManager::Button::Back)) { |
| 75 | onGoHome(); |
| 76 | } |
| 77 | |
| 78 | int listSize = static_cast<int>(recentBooks.size()); |
| 79 | |
| 80 | buttonNavigator.onNextRelease([this, listSize] { |
| 81 | selectorIndex = ButtonNavigator::nextIndex(static_cast<int>(selectorIndex), listSize); |
| 82 | requestUpdate(); |
| 83 | }); |
| 84 | |
| 85 | buttonNavigator.onPreviousRelease([this, listSize] { |
| 86 | selectorIndex = ButtonNavigator::previousIndex(static_cast<int>(selectorIndex), listSize); |
| 87 | requestUpdate(); |
| 88 | }); |
| 89 | |
| 90 | buttonNavigator.onNextContinuous([this, listSize, pageItems] { |
| 91 | selectorIndex = ButtonNavigator::nextPageIndex(static_cast<int>(selectorIndex), listSize, pageItems); |
| 92 | requestUpdate(); |
| 93 | }); |
| 94 | |
| 95 | buttonNavigator.onPreviousContinuous([this, listSize, pageItems] { |
| 96 | selectorIndex = ButtonNavigator::previousPageIndex(static_cast<int>(selectorIndex), listSize, pageItems); |
| 97 | requestUpdate(); |
| 98 | }); |
| 99 | } |
| 100 | |
| 101 | void RecentBooksActivity::promptRemoveBook(const std::string& path, const std::string& title) { |
nothing calls this directly
no test coverage detected