From 49471e36f1fea259f6a5ff8e3a7486712f8db00f Mon Sep 17 00:00:00 2001 From: cottongin Date: Sat, 21 Feb 2026 02:55:29 -0500 Subject: [PATCH] refactor: change browse activities to ActivityWithSubactivity Change HomeActivity, MyLibraryActivity, and RecentBooksActivity base class from Activity to ActivityWithSubactivity. Adds subActivity guard at top of each loop(). No new behavior, just enabling sub-activity hosting for the upcoming BookManageMenuActivity integration. Co-authored-by: Cursor --- src/activities/home/HomeActivity.cpp | 9 +++++++-- src/activities/home/HomeActivity.h | 6 +++--- src/activities/home/MyLibraryActivity.cpp | 9 +++++++-- src/activities/home/MyLibraryActivity.h | 6 +++--- src/activities/home/RecentBooksActivity.cpp | 9 +++++++-- src/activities/home/RecentBooksActivity.h | 6 +++--- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/activities/home/HomeActivity.cpp b/src/activities/home/HomeActivity.cpp index ac731eec..b6cd5745 100644 --- a/src/activities/home/HomeActivity.cpp +++ b/src/activities/home/HomeActivity.cpp @@ -124,7 +124,7 @@ void HomeActivity::loadRecentCovers(int coverHeight) { } void HomeActivity::onEnter() { - Activity::onEnter(); + ActivityWithSubactivity::onEnter(); // Check if OPDS browser URL is configured hasOpdsUrl = strlen(SETTINGS.opdsServerUrl) > 0; @@ -139,7 +139,7 @@ void HomeActivity::onEnter() { } void HomeActivity::onExit() { - Activity::onExit(); + ActivityWithSubactivity::onExit(); // Free the stored cover buffer if any freeCoverBuffer(); @@ -188,6 +188,11 @@ void HomeActivity::freeCoverBuffer() { } void HomeActivity::loop() { + if (subActivity) { + subActivity->loop(); + return; + } + const int menuCount = getMenuItemCount(); buttonNavigator.onNext([this, menuCount] { diff --git a/src/activities/home/HomeActivity.h b/src/activities/home/HomeActivity.h index 5359bf79..b462280c 100644 --- a/src/activities/home/HomeActivity.h +++ b/src/activities/home/HomeActivity.h @@ -2,14 +2,14 @@ #include #include -#include "../Activity.h" +#include "../ActivityWithSubactivity.h" #include "./MyLibraryActivity.h" #include "util/ButtonNavigator.h" struct RecentBook; struct Rect; -class HomeActivity final : public Activity { +class HomeActivity final : public ActivityWithSubactivity { ButtonNavigator buttonNavigator; int selectorIndex = 0; bool recentsLoading = false; @@ -40,7 +40,7 @@ class HomeActivity final : public Activity { const std::function& onMyLibraryOpen, const std::function& onRecentsOpen, const std::function& onSettingsOpen, const std::function& onFileTransferOpen, const std::function& onOpdsBrowserOpen) - : Activity("Home", renderer, mappedInput), + : ActivityWithSubactivity("Home", renderer, mappedInput), onSelectBook(onSelectBook), onMyLibraryOpen(onMyLibraryOpen), onRecentsOpen(onRecentsOpen), diff --git a/src/activities/home/MyLibraryActivity.cpp b/src/activities/home/MyLibraryActivity.cpp index ed64215e..a299a8fe 100644 --- a/src/activities/home/MyLibraryActivity.cpp +++ b/src/activities/home/MyLibraryActivity.cpp @@ -103,7 +103,7 @@ void MyLibraryActivity::loadFiles() { } void MyLibraryActivity::onEnter() { - Activity::onEnter(); + ActivityWithSubactivity::onEnter(); loadFiles(); selectorIndex = 0; @@ -112,11 +112,16 @@ void MyLibraryActivity::onEnter() { } void MyLibraryActivity::onExit() { - Activity::onExit(); + ActivityWithSubactivity::onExit(); files.clear(); } void MyLibraryActivity::loop() { + if (subActivity) { + subActivity->loop(); + return; + } + // Long press BACK (1s+) goes to root folder if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= GO_HOME_MS && basepath != "/") { diff --git a/src/activities/home/MyLibraryActivity.h b/src/activities/home/MyLibraryActivity.h index 748b7eea..96f5c185 100644 --- a/src/activities/home/MyLibraryActivity.h +++ b/src/activities/home/MyLibraryActivity.h @@ -3,11 +3,11 @@ #include #include -#include "../Activity.h" +#include "../ActivityWithSubactivity.h" #include "RecentBooksStore.h" #include "util/ButtonNavigator.h" -class MyLibraryActivity final : public Activity { +class MyLibraryActivity final : public ActivityWithSubactivity { private: ButtonNavigator buttonNavigator; @@ -30,7 +30,7 @@ class MyLibraryActivity final : public Activity { const std::function& onGoHome, const std::function& onSelectBook, std::string initialPath = "/") - : Activity("MyLibrary", renderer, mappedInput), + : ActivityWithSubactivity("MyLibrary", renderer, mappedInput), basepath(initialPath.empty() ? "/" : std::move(initialPath)), onSelectBook(onSelectBook), onGoHome(onGoHome) {} diff --git a/src/activities/home/RecentBooksActivity.cpp b/src/activities/home/RecentBooksActivity.cpp index 2ea9ff01..e2d54b4a 100644 --- a/src/activities/home/RecentBooksActivity.cpp +++ b/src/activities/home/RecentBooksActivity.cpp @@ -31,7 +31,7 @@ void RecentBooksActivity::loadRecentBooks() { } void RecentBooksActivity::onEnter() { - Activity::onEnter(); + ActivityWithSubactivity::onEnter(); // Load data loadRecentBooks(); @@ -41,11 +41,16 @@ void RecentBooksActivity::onEnter() { } void RecentBooksActivity::onExit() { - Activity::onExit(); + ActivityWithSubactivity::onExit(); recentBooks.clear(); } void RecentBooksActivity::loop() { + if (subActivity) { + subActivity->loop(); + return; + } + const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, true); if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { diff --git a/src/activities/home/RecentBooksActivity.h b/src/activities/home/RecentBooksActivity.h index 9ad44213..381aa9fb 100644 --- a/src/activities/home/RecentBooksActivity.h +++ b/src/activities/home/RecentBooksActivity.h @@ -5,11 +5,11 @@ #include #include -#include "../Activity.h" +#include "../ActivityWithSubactivity.h" #include "RecentBooksStore.h" #include "util/ButtonNavigator.h" -class RecentBooksActivity final : public Activity { +class RecentBooksActivity final : public ActivityWithSubactivity { private: ButtonNavigator buttonNavigator; @@ -29,7 +29,7 @@ class RecentBooksActivity final : public Activity { explicit RecentBooksActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::function& onGoHome, const std::function& onSelectBook) - : Activity("RecentBooks", renderer, mappedInput), onSelectBook(onSelectBook), onGoHome(onGoHome) {} + : ActivityWithSubactivity("RecentBooks", renderer, mappedInput), onSelectBook(onSelectBook), onGoHome(onGoHome) {} void onEnter() override; void onExit() override; void loop() override;