From df53faab9100916effd21f4d6fd7be7342c1022b Mon Sep 17 00:00:00 2001 From: KemoNine Date: Mon, 18 May 2026 22:16:33 -0400 Subject: [PATCH] feat: allow removing book from recent list (#2045) ## Summary Add ability to long press 'confirm' on a book in the recent books list to be prompted to remove it from the list. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? *Yes, Claude* --------- --- lib/I18n/translations/belarusian.yaml | 1 + lib/I18n/translations/catalan.yaml | 1 + lib/I18n/translations/czech.yaml | 1 + lib/I18n/translations/danish.yaml | 1 + lib/I18n/translations/dutch.yaml | 1 + lib/I18n/translations/english.yaml | 1 + lib/I18n/translations/finnish.yaml | 1 + lib/I18n/translations/french.yaml | 1 + lib/I18n/translations/german.yaml | 1 + lib/I18n/translations/hungarian.yaml | 1 + lib/I18n/translations/italian.yaml | 1 + lib/I18n/translations/kazakh.yaml | 1 + lib/I18n/translations/lithuanian.yaml | 1 + lib/I18n/translations/polish.yaml | 1 + lib/I18n/translations/portuguese.yaml | 1 + lib/I18n/translations/romanian.yaml | 1 + lib/I18n/translations/russian.yaml | 1 + lib/I18n/translations/slovenian.yaml | 1 + lib/I18n/translations/spanish.yaml | 1 + lib/I18n/translations/swedish.yaml | 1 + lib/I18n/translations/turkish.yaml | 1 + lib/I18n/translations/ukrainian.yaml | 1 + src/RecentBooksStore.cpp | 3 +- src/RecentBooksStore.h | 2 +- src/activities/home/RecentBooksActivity.cpp | 47 ++++++++++++++++++++- src/activities/home/RecentBooksActivity.h | 7 +++ 26 files changed, 77 insertions(+), 4 deletions(-) diff --git a/lib/I18n/translations/belarusian.yaml b/lib/I18n/translations/belarusian.yaml index 7411592d..8e2b2102 100644 --- a/lib/I18n/translations/belarusian.yaml +++ b/lib/I18n/translations/belarusian.yaml @@ -209,6 +209,7 @@ STR_REMAP_FRONT_BUTTONS: "Пераназначыць пярэднія кнопк STR_OPDS_BROWSER: "OPDS браўзер" STR_COVER_CUSTOM: "Вокладка + Свой" STR_MENU_RECENT_BOOKS: "Нядаўнія кнігі" +STR_REMOVE_FROM_RECENTS: "Выдаліць з нядаўніх кніг?" STR_NO_RECENT_BOOKS: "Няма нядаўніх кніг" STR_CALIBRE_DESC: "Выкарыстоўваць бесправадную перадачу Calibre" STR_FORGET_AND_REMOVE: "Забыць сетку і выдаліць захаваны пароль?" diff --git a/lib/I18n/translations/catalan.yaml b/lib/I18n/translations/catalan.yaml index b2f936a1..30fa6503 100644 --- a/lib/I18n/translations/catalan.yaml +++ b/lib/I18n/translations/catalan.yaml @@ -237,6 +237,7 @@ STR_REMAP_FRONT_BUTTONS: "Reassigna els botons frontals" STR_OPDS_BROWSER: "Navegador OPDS" STR_COVER_CUSTOM: "Portada + Personalitzat" STR_MENU_RECENT_BOOKS: "Llibres recents" +STR_REMOVE_FROM_RECENTS: "Voleu suprimir-lo de Llibres recents?" STR_NO_RECENT_BOOKS: "No hi ha llibres recents" STR_CALIBRE_DESC: "Usa les transferències sense fils de Calibre" STR_FORGET_AND_REMOVE: "Voleu suprimir la contrasenya desada?" diff --git a/lib/I18n/translations/czech.yaml b/lib/I18n/translations/czech.yaml index 44f65bdc..775b9e47 100644 --- a/lib/I18n/translations/czech.yaml +++ b/lib/I18n/translations/czech.yaml @@ -215,6 +215,7 @@ STR_REMAP_FRONT_BUTTONS: "Přemapovat přední tlačítka" STR_OPDS_BROWSER: "Prohlížeč OPDS" STR_COVER_CUSTOM: "Obálka + Vlastní" STR_MENU_RECENT_BOOKS: "Nedávné knihy" +STR_REMOVE_FROM_RECENTS: "Odebrat z nedávných knih?" STR_NO_RECENT_BOOKS: "Žádné nedávné knihy" STR_CALIBRE_DESC: "Používat přenosy bezdrátových zařízení Calibre" STR_FORGET_AND_REMOVE: "Zapomenout síť a odstranit uložené heslo?" diff --git a/lib/I18n/translations/danish.yaml b/lib/I18n/translations/danish.yaml index b89993d7..4c7f3232 100644 --- a/lib/I18n/translations/danish.yaml +++ b/lib/I18n/translations/danish.yaml @@ -237,6 +237,7 @@ STR_REMAP_FRONT_BUTTONS: "Omtildel frontknapper" STR_OPDS_BROWSER: "OPDS Browser" STR_COVER_CUSTOM: "Omslag + Brugerdefineret" STR_MENU_RECENT_BOOKS: "Seneste bøger" +STR_REMOVE_FROM_RECENTS: "Fjern fra Seneste bøger?" STR_NO_RECENT_BOOKS: "Ingen seneste bøger" STR_CALIBRE_DESC: "Brug Calibre trådløs enhedsoverførelse" STR_FORGET_AND_REMOVE: "Glem netværk og fjern gemt adgangskode?" diff --git a/lib/I18n/translations/dutch.yaml b/lib/I18n/translations/dutch.yaml index 2211d6b4..fa10d57b 100644 --- a/lib/I18n/translations/dutch.yaml +++ b/lib/I18n/translations/dutch.yaml @@ -237,6 +237,7 @@ STR_REMAP_FRONT_BUTTONS: "Knoppen voorzijde wijzigen" STR_OPDS_BROWSER: "OPDS-browser" STR_COVER_CUSTOM: "Omslag + Aangepast" STR_MENU_RECENT_BOOKS: "Recente boeken" +STR_REMOVE_FROM_RECENTS: "Verwijderen uit Recente boeken?" STR_NO_RECENT_BOOKS: "Geen recente boeken" STR_CALIBRE_DESC: "Gebruik Calibre draadloze overdracht" STR_FORGET_AND_REMOVE: "Netwerk vergeten en wachtwoord verwijderen?" diff --git a/lib/I18n/translations/english.yaml b/lib/I18n/translations/english.yaml index 39f64244..d5aa1bf6 100644 --- a/lib/I18n/translations/english.yaml +++ b/lib/I18n/translations/english.yaml @@ -261,6 +261,7 @@ STR_OPDS_BROWSER: "OPDS Browser" STR_SEARCH: "Search" STR_COVER_CUSTOM: "Cover + Custom" STR_MENU_RECENT_BOOKS: "Recent Books" +STR_REMOVE_FROM_RECENTS: "Remove from Recent Books?" STR_NO_RECENT_BOOKS: "No recent books" STR_CALIBRE_DESC: "Use Calibre wireless device transfers" STR_FORGET_AND_REMOVE: "Forget network and remove saved password?" diff --git a/lib/I18n/translations/finnish.yaml b/lib/I18n/translations/finnish.yaml index 0448ae84..2965a222 100644 --- a/lib/I18n/translations/finnish.yaml +++ b/lib/I18n/translations/finnish.yaml @@ -214,6 +214,7 @@ STR_REMAP_FRONT_BUTTONS: "Uudelleenmääritä etupainikkeet" STR_OPDS_BROWSER: "OPDS-selain" STR_COVER_CUSTOM: "Kansi + mukautettu" STR_MENU_RECENT_BOOKS: "Viimeisimmät kirjat" +STR_REMOVE_FROM_RECENTS: "Poista viimeisimmistä kirjoista?" STR_NO_RECENT_BOOKS: "Ei viimeisimpiä kirjoja" STR_CALIBRE_DESC: "Käytä Calibren langatonta laiteyhteyttä" STR_FORGET_AND_REMOVE: "Unohda verkko ja poista tallennettu salasana?" diff --git a/lib/I18n/translations/french.yaml b/lib/I18n/translations/french.yaml index 25d25a29..0720dd62 100644 --- a/lib/I18n/translations/french.yaml +++ b/lib/I18n/translations/french.yaml @@ -238,6 +238,7 @@ STR_REMAP_FRONT_BUTTONS: "Configurer boutons façade" STR_OPDS_BROWSER: "Navigateur OPDS" STR_COVER_CUSTOM: "Couverture + Perso" STR_MENU_RECENT_BOOKS: "Livres récents" +STR_REMOVE_FROM_RECENTS: "Retirer des Livres récents ?" STR_NO_RECENT_BOOKS: "Aucun livre récent" STR_CALIBRE_DESC: "Utiliser transfert sans fil Calibre" STR_FORGET_AND_REMOVE: "Oublier le réseau et le mot de passe ?" diff --git a/lib/I18n/translations/german.yaml b/lib/I18n/translations/german.yaml index 1612957d..d29b82c8 100644 --- a/lib/I18n/translations/german.yaml +++ b/lib/I18n/translations/german.yaml @@ -236,6 +236,7 @@ STR_REMAP_FRONT_BUTTONS: "Vordere Tasten belegen" STR_OPDS_BROWSER: "OPDS-Browser" STR_COVER_CUSTOM: "Umschlag + Eigenes" STR_MENU_RECENT_BOOKS: "Zuletzt gelesen" +STR_REMOVE_FROM_RECENTS: "Aus Zuletzt gelesen entfernen?" STR_NO_RECENT_BOOKS: "Keine Bücher" STR_CALIBRE_DESC: "Calibre-Übertragung (WLAN)" STR_FORGET_AND_REMOVE: "WLAN entfernen & Passwort löschen?" diff --git a/lib/I18n/translations/hungarian.yaml b/lib/I18n/translations/hungarian.yaml index e4474d28..d6e00442 100644 --- a/lib/I18n/translations/hungarian.yaml +++ b/lib/I18n/translations/hungarian.yaml @@ -234,6 +234,7 @@ STR_REMAP_FRONT_BUTTONS: "Elülső gombok átállítása" STR_OPDS_BROWSER: "OPDS böngésző" STR_COVER_CUSTOM: "Borító + Egyéni" STR_MENU_RECENT_BOOKS: "Legutóbbi könyvek" +STR_REMOVE_FROM_RECENTS: "Eltávolítás a legutóbbi könyvek közül?" STR_NO_RECENT_BOOKS: "Nincsenek legutóbbi könyvek" STR_CALIBRE_DESC: "Calibre wireless eszköz átvitel használata" STR_FORGET_AND_REMOVE: "Hálózat elfelejtése és mentett jelszó törlése?" diff --git a/lib/I18n/translations/italian.yaml b/lib/I18n/translations/italian.yaml index 7b5a894a..0c264a3c 100644 --- a/lib/I18n/translations/italian.yaml +++ b/lib/I18n/translations/italian.yaml @@ -246,6 +246,7 @@ STR_OPDS_BROWSER: "Browser OPDS" STR_SEARCH: "Cerca" STR_COVER_CUSTOM: "Copertina + Wallpaper" STR_MENU_RECENT_BOOKS: "Libri recenti" +STR_REMOVE_FROM_RECENTS: "Rimuovere da Libri recenti?" STR_NO_RECENT_BOOKS: "Nessun libro recente" STR_CALIBRE_DESC: "Trasferimento wireless con Calibre" STR_FORGET_AND_REMOVE: "Eliminare la rete e la password salvata?" diff --git a/lib/I18n/translations/kazakh.yaml b/lib/I18n/translations/kazakh.yaml index a5fb5ccd..48ce163b 100644 --- a/lib/I18n/translations/kazakh.yaml +++ b/lib/I18n/translations/kazakh.yaml @@ -210,6 +210,7 @@ STR_REMAP_FRONT_BUTTONS: "Алдыңғы түймелерді қайта бап STR_OPDS_BROWSER: "OPDS шолғышы" STR_COVER_CUSTOM: "Мұқаба + Өзгертілген" STR_MENU_RECENT_BOOKS: "Жуырда оқылған кітаптар" +STR_REMOVE_FROM_RECENTS: "Жуырда оқылған кітаптардан жою?" STR_NO_RECENT_BOOKS: "Жуырда оқылған кітаптар жоқ" STR_CALIBRE_DESC: "Calibre сымсыз тасымалдауын пайдалану" STR_FORGET_AND_REMOVE: "Желіні ұмыту және сақталған құпия сөзді жою керек пе?" diff --git a/lib/I18n/translations/lithuanian.yaml b/lib/I18n/translations/lithuanian.yaml index 88870d9d..8fc16786 100644 --- a/lib/I18n/translations/lithuanian.yaml +++ b/lib/I18n/translations/lithuanian.yaml @@ -234,6 +234,7 @@ STR_REMAP_FRONT_BUTTONS: "Keisti mygtukus" STR_OPDS_BROWSER: "OPDS naršyklė" STR_COVER_CUSTOM: "Viršelis + Kita" STR_MENU_RECENT_BOOKS: "Paskutinės" +STR_REMOVE_FROM_RECENTS: "Pašalinti iš paskutinių?" STR_NO_RECENT_BOOKS: "Paskutinių nėra" STR_CALIBRE_DESC: "Calibre belaidis ryšys" STR_FORGET_AND_REMOVE: "Pamiršti tinklą?" diff --git a/lib/I18n/translations/polish.yaml b/lib/I18n/translations/polish.yaml index a187b011..638991af 100644 --- a/lib/I18n/translations/polish.yaml +++ b/lib/I18n/translations/polish.yaml @@ -246,6 +246,7 @@ STR_OPDS_BROWSER: "OPDS Browser" STR_SEARCH: "Szukaj" STR_COVER_CUSTOM: "Okładka + Własne" STR_MENU_RECENT_BOOKS: "Ostatnio czytane" +STR_REMOVE_FROM_RECENTS: "Usunąć z ostatnio czytanych?" STR_NO_RECENT_BOOKS: "Brak ostatnio czytanych" STR_CALIBRE_DESC: "Przesyłaj bezprzewodowo do Calibre" STR_FORGET_AND_REMOVE: "Zapomnieć zapisane sieci oraz hasła?" diff --git a/lib/I18n/translations/portuguese.yaml b/lib/I18n/translations/portuguese.yaml index d2289014..f51011dc 100644 --- a/lib/I18n/translations/portuguese.yaml +++ b/lib/I18n/translations/portuguese.yaml @@ -215,6 +215,7 @@ STR_REMAP_FRONT_BUTTONS: "Remapear botões frontais" STR_OPDS_BROWSER: "Navegador OPDS" STR_COVER_CUSTOM: "Capa + personalizado" STR_MENU_RECENT_BOOKS: "Livros recentes" +STR_REMOVE_FROM_RECENTS: "Remover dos Livros recentes?" STR_NO_RECENT_BOOKS: "Sem livros recentes" STR_CALIBRE_DESC: "Usar transferências sem fio Calibre" STR_FORGET_AND_REMOVE: "Esquecer a rede e remover a senha salva?" diff --git a/lib/I18n/translations/romanian.yaml b/lib/I18n/translations/romanian.yaml index 0daf3c6f..5e65da18 100644 --- a/lib/I18n/translations/romanian.yaml +++ b/lib/I18n/translations/romanian.yaml @@ -237,6 +237,7 @@ STR_REMAP_FRONT_BUTTONS: "Remapare butoane frontale" STR_OPDS_BROWSER: "Browser OPDS" STR_COVER_CUSTOM: "Copertă + Personalizat" STR_MENU_RECENT_BOOKS: "Cărţi recente" +STR_REMOVE_FROM_RECENTS: "Eliminați din Cărţi recente?" STR_NO_RECENT_BOOKS: "Nicio carte recentă" STR_CALIBRE_DESC: "Utilizaţi transferurile wireless ale dispozitivului Calibre" STR_FORGET_AND_REMOVE: "Uitaţi reţeaua şi eliminaţi parola salvată?" diff --git a/lib/I18n/translations/russian.yaml b/lib/I18n/translations/russian.yaml index f5e95054..81c1ec01 100644 --- a/lib/I18n/translations/russian.yaml +++ b/lib/I18n/translations/russian.yaml @@ -246,6 +246,7 @@ STR_OPDS_BROWSER: "OPDS браузер" STR_SEARCH: "Поиск" STR_COVER_CUSTOM: "Обложка + Свой" STR_MENU_RECENT_BOOKS: "Недавние книги" +STR_REMOVE_FROM_RECENTS: "Удалить из недавних книг?" STR_NO_RECENT_BOOKS: "Нет недавних книг" STR_CALIBRE_DESC: "Использовать беспроводную передачу Calibre" STR_FORGET_AND_REMOVE: "Забыть сеть и удалить сохранённый пароль?" diff --git a/lib/I18n/translations/slovenian.yaml b/lib/I18n/translations/slovenian.yaml index f9abf855..70ebfad1 100644 --- a/lib/I18n/translations/slovenian.yaml +++ b/lib/I18n/translations/slovenian.yaml @@ -234,6 +234,7 @@ STR_REMAP_FRONT_BUTTONS: "Prenastavi sprednje gumbe" STR_OPDS_BROWSER: "OPDS brskalnik" STR_COVER_CUSTOM: "Naslovnica + po meri" STR_MENU_RECENT_BOOKS: "Zadnje knjige" +STR_REMOVE_FROM_RECENTS: "Odstrani iz zadnjih knjig?" STR_NO_RECENT_BOOKS: "Ni zadnjih knjig" STR_CALIBRE_DESC: "Uporabi brezžični prenos Calibre" STR_FORGET_AND_REMOVE: "Pozabi omrežje in odstrani shranjeno geslo?" diff --git a/lib/I18n/translations/spanish.yaml b/lib/I18n/translations/spanish.yaml index 0fceae4e..fbdf3fb3 100644 --- a/lib/I18n/translations/spanish.yaml +++ b/lib/I18n/translations/spanish.yaml @@ -246,6 +246,7 @@ STR_OPDS_BROWSER: "Navegador OPDS" STR_SEARCH: "Buscar" STR_COVER_CUSTOM: "Portada + Pers." STR_MENU_RECENT_BOOKS: "Libros recientes" +STR_REMOVE_FROM_RECENTS: "¿Eliminar de Libros recientes?" STR_NO_RECENT_BOOKS: "No hay libros recientes" STR_CALIBRE_DESC: "Transferir contenido a este dispositivo" STR_FORGET_AND_REMOVE: "¿Desea olvidar la red y la contraseña guardada?" diff --git a/lib/I18n/translations/swedish.yaml b/lib/I18n/translations/swedish.yaml index 14811162..e5f1a0bf 100644 --- a/lib/I18n/translations/swedish.yaml +++ b/lib/I18n/translations/swedish.yaml @@ -246,6 +246,7 @@ STR_OPDS_BROWSER: "OPDS-webbläsare" STR_SEARCH: "Sök" STR_COVER_CUSTOM: "Omslag + Valfri" STR_MENU_RECENT_BOOKS: "Senaste böckerna" +STR_REMOVE_FROM_RECENTS: "Ta bort från Senaste böckerna?" STR_NO_RECENT_BOOKS: "Inga senaste böcker" STR_CALIBRE_DESC: "Använd Calibres trådlösa enhetsöverföring" STR_FORGET_AND_REMOVE: "Glöm nätverk och ta bort sparat lösenord?" diff --git a/lib/I18n/translations/turkish.yaml b/lib/I18n/translations/turkish.yaml index 5c5cdada..5777eaad 100644 --- a/lib/I18n/translations/turkish.yaml +++ b/lib/I18n/translations/turkish.yaml @@ -214,6 +214,7 @@ STR_REMAP_FRONT_BUTTONS: "Ön Tuşları Yeniden Ata" STR_OPDS_BROWSER: "OPDS Tarayıcı" STR_COVER_CUSTOM: "Kapak + Özel" STR_MENU_RECENT_BOOKS: "Son Kitaplar" +STR_REMOVE_FROM_RECENTS: "Son Kitaplar listesinden kaldırılsın mı?" STR_NO_RECENT_BOOKS: "Son okunan kitap yok" STR_CALIBRE_DESC: "Calibre kablosuz cihaz transferini kullan" STR_FORGET_AND_REMOVE: "Ağı unut ve kayıtlı şifreyi sil?" diff --git a/lib/I18n/translations/ukrainian.yaml b/lib/I18n/translations/ukrainian.yaml index 4f9e9915..c43f2615 100644 --- a/lib/I18n/translations/ukrainian.yaml +++ b/lib/I18n/translations/ukrainian.yaml @@ -246,6 +246,7 @@ STR_OPDS_BROWSER: "Браузер OPDS" STR_SEARCH: "Пошук" STR_COVER_CUSTOM: "Обкл. + власне" STR_MENU_RECENT_BOOKS: "Останні книги" +STR_REMOVE_FROM_RECENTS: "Видалити з останніх книг?" STR_NO_RECENT_BOOKS: "Немає останніх книг" STR_CALIBRE_DESC: "Бездротова передача на пристрій із Calibre" STR_FORGET_AND_REMOVE: "Забути мережу та видалити збережений пароль?" diff --git a/src/RecentBooksStore.cpp b/src/RecentBooksStore.cpp index c9df55d8..3853975a 100644 --- a/src/RecentBooksStore.cpp +++ b/src/RecentBooksStore.cpp @@ -9,6 +9,7 @@ #include #include +#include namespace { constexpr uint8_t RECENT_BOOKS_FILE_VERSION = 3; @@ -64,8 +65,6 @@ bool RecentBooksStore::removeByPath(const std::string& path) { } recentBooks.erase(it); if (!saveToFile()) { - // In-memory removal succeeded; persistence is best-effort here (consistent with - // addBook/updateBook). Log the failure but still report the entry as removed. LOG_ERR("RBS", "Failed to persist removal of recent book: %s", path.c_str()); } return true; diff --git a/src/RecentBooksStore.h b/src/RecentBooksStore.h index e063f9cf..f3a8391e 100644 --- a/src/RecentBooksStore.h +++ b/src/RecentBooksStore.h @@ -37,7 +37,7 @@ class RecentBooksStore { void updateBook(const std::string& path, const std::string& title, const std::string& author, const std::string& coverBmpPath); - // Remove the entry whose path matches (used when a book is finished/read). + // Remove the entry whose path matches (used when a book is removed from recents or finished/read). // Returns true if an entry was found and removed (no-op + false otherwise). // Persistence is best-effort: a failed save is logged, not reflected in the return. bool removeByPath(const std::string& path); diff --git a/src/activities/home/RecentBooksActivity.cpp b/src/activities/home/RecentBooksActivity.cpp index 56c6c6fb..7b4a0117 100644 --- a/src/activities/home/RecentBooksActivity.cpp +++ b/src/activities/home/RecentBooksActivity.cpp @@ -5,14 +5,17 @@ #include #include +#include #include "MappedInputManager.h" #include "RecentBooksStore.h" +#include "activities/util/ConfirmationActivity.h" #include "components/UITheme.h" #include "fontIds.h" namespace { -constexpr unsigned long GO_HOME_MS = 1000; +// Hold threshold for the long-press "remove from list" action (firmware convention). +constexpr unsigned long LONG_PRESS_MS = 1000; } // namespace void RecentBooksActivity::loadRecentBooks() { recentBooks = RECENT_BOOKS.getBooks(); } @@ -41,6 +44,25 @@ void RecentBooksActivity::onExit() { void RecentBooksActivity::loop() { const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, true); + // After a long-press has fired, swallow input until Confirm is physically released + // (so the release doesn't also open the book; re-arm only once the button is up). + if (longPressFired) { + if (!mappedInput.isPressed(MappedInputManager::Button::Confirm)) { + longPressFired = false; + } + return; + } + + // Long-press Confirm on the selected book: prompt to remove it from the list. + // Fires when the hold times out while still held (firmware hold-to-act pattern, + // cf. FileBrowserActivity BACK long-press). + if (!recentBooks.empty() && selectorIndex < recentBooks.size() && + mappedInput.isPressed(MappedInputManager::Button::Confirm) && mappedInput.getHeldTime() >= LONG_PRESS_MS) { + longPressFired = true; + promptRemoveBook(recentBooks[selectorIndex].path, recentBooks[selectorIndex].title); + return; + } + if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { if (!recentBooks.empty() && selectorIndex < static_cast(recentBooks.size())) { LOG_DBG("RBA", "Selected recent book: %s", recentBooks[selectorIndex].path.c_str()); @@ -76,6 +98,29 @@ void RecentBooksActivity::loop() { }); } +void RecentBooksActivity::promptRemoveBook(const std::string& path, const std::string& title) { + auto handler = [this, path](const ActivityResult& res) { + if (res.isCancelled) { + LOG_DBG("RBA", "Remove from recents cancelled"); + return; + } + if (RECENT_BOOKS.removeByPath(path)) { + LOG_DBG("RBA", "Removed from recents: %s", path.c_str()); + loadRecentBooks(); + if (recentBooks.empty()) { + selectorIndex = 0; + } else if (selectorIndex >= recentBooks.size()) { + selectorIndex = recentBooks.size() - 1; + } + requestUpdate(true); + } + }; + + startActivityForResult( + std::make_unique(renderer, mappedInput, tr(STR_REMOVE_FROM_RECENTS), title), + std::move(handler)); +} + void RecentBooksActivity::render(RenderLock&&) { renderer.clearScreen(); diff --git a/src/activities/home/RecentBooksActivity.h b/src/activities/home/RecentBooksActivity.h index c9c70b36..0ccc07cc 100644 --- a/src/activities/home/RecentBooksActivity.h +++ b/src/activities/home/RecentBooksActivity.h @@ -15,12 +15,19 @@ class RecentBooksActivity final : public Activity { size_t selectorIndex = 0; + // Set when a long-press has fired; input is swallowed until Confirm is released + // again so the release doesn't also open the book. + bool longPressFired = false; + // Recent tab state std::vector recentBooks; // Data loading void loadRecentBooks(); + // Show an OK/Cancel prompt to remove the given book from the Recent Books list. + void promptRemoveBook(const std::string& path, const std::string& title); + public: explicit RecentBooksActivity(GfxRenderer& renderer, MappedInputManager& mappedInput) : Activity("RecentBooks", renderer, mappedInput) {}