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 <cursoragent@cursor.com>
This commit is contained in:
cottongin
2026-02-21 02:55:29 -05:00
parent c44ac0272a
commit 49471e36f1
6 changed files with 30 additions and 15 deletions

View File

@@ -124,7 +124,7 @@ void HomeActivity::loadRecentCovers(int coverHeight) {
} }
void HomeActivity::onEnter() { void HomeActivity::onEnter() {
Activity::onEnter(); ActivityWithSubactivity::onEnter();
// Check if OPDS browser URL is configured // Check if OPDS browser URL is configured
hasOpdsUrl = strlen(SETTINGS.opdsServerUrl) > 0; hasOpdsUrl = strlen(SETTINGS.opdsServerUrl) > 0;
@@ -139,7 +139,7 @@ void HomeActivity::onEnter() {
} }
void HomeActivity::onExit() { void HomeActivity::onExit() {
Activity::onExit(); ActivityWithSubactivity::onExit();
// Free the stored cover buffer if any // Free the stored cover buffer if any
freeCoverBuffer(); freeCoverBuffer();
@@ -188,6 +188,11 @@ void HomeActivity::freeCoverBuffer() {
} }
void HomeActivity::loop() { void HomeActivity::loop() {
if (subActivity) {
subActivity->loop();
return;
}
const int menuCount = getMenuItemCount(); const int menuCount = getMenuItemCount();
buttonNavigator.onNext([this, menuCount] { buttonNavigator.onNext([this, menuCount] {

View File

@@ -2,14 +2,14 @@
#include <functional> #include <functional>
#include <vector> #include <vector>
#include "../Activity.h" #include "../ActivityWithSubactivity.h"
#include "./MyLibraryActivity.h" #include "./MyLibraryActivity.h"
#include "util/ButtonNavigator.h" #include "util/ButtonNavigator.h"
struct RecentBook; struct RecentBook;
struct Rect; struct Rect;
class HomeActivity final : public Activity { class HomeActivity final : public ActivityWithSubactivity {
ButtonNavigator buttonNavigator; ButtonNavigator buttonNavigator;
int selectorIndex = 0; int selectorIndex = 0;
bool recentsLoading = false; bool recentsLoading = false;
@@ -40,7 +40,7 @@ class HomeActivity final : public Activity {
const std::function<void()>& onMyLibraryOpen, const std::function<void()>& onRecentsOpen, const std::function<void()>& onMyLibraryOpen, const std::function<void()>& onRecentsOpen,
const std::function<void()>& onSettingsOpen, const std::function<void()>& onFileTransferOpen, const std::function<void()>& onSettingsOpen, const std::function<void()>& onFileTransferOpen,
const std::function<void()>& onOpdsBrowserOpen) const std::function<void()>& onOpdsBrowserOpen)
: Activity("Home", renderer, mappedInput), : ActivityWithSubactivity("Home", renderer, mappedInput),
onSelectBook(onSelectBook), onSelectBook(onSelectBook),
onMyLibraryOpen(onMyLibraryOpen), onMyLibraryOpen(onMyLibraryOpen),
onRecentsOpen(onRecentsOpen), onRecentsOpen(onRecentsOpen),

View File

@@ -103,7 +103,7 @@ void MyLibraryActivity::loadFiles() {
} }
void MyLibraryActivity::onEnter() { void MyLibraryActivity::onEnter() {
Activity::onEnter(); ActivityWithSubactivity::onEnter();
loadFiles(); loadFiles();
selectorIndex = 0; selectorIndex = 0;
@@ -112,11 +112,16 @@ void MyLibraryActivity::onEnter() {
} }
void MyLibraryActivity::onExit() { void MyLibraryActivity::onExit() {
Activity::onExit(); ActivityWithSubactivity::onExit();
files.clear(); files.clear();
} }
void MyLibraryActivity::loop() { void MyLibraryActivity::loop() {
if (subActivity) {
subActivity->loop();
return;
}
// Long press BACK (1s+) goes to root folder // Long press BACK (1s+) goes to root folder
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= GO_HOME_MS && if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= GO_HOME_MS &&
basepath != "/") { basepath != "/") {

View File

@@ -3,11 +3,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "../Activity.h" #include "../ActivityWithSubactivity.h"
#include "RecentBooksStore.h" #include "RecentBooksStore.h"
#include "util/ButtonNavigator.h" #include "util/ButtonNavigator.h"
class MyLibraryActivity final : public Activity { class MyLibraryActivity final : public ActivityWithSubactivity {
private: private:
ButtonNavigator buttonNavigator; ButtonNavigator buttonNavigator;
@@ -30,7 +30,7 @@ class MyLibraryActivity final : public Activity {
const std::function<void()>& onGoHome, const std::function<void()>& onGoHome,
const std::function<void(const std::string& path)>& onSelectBook, const std::function<void(const std::string& path)>& onSelectBook,
std::string initialPath = "/") std::string initialPath = "/")
: Activity("MyLibrary", renderer, mappedInput), : ActivityWithSubactivity("MyLibrary", renderer, mappedInput),
basepath(initialPath.empty() ? "/" : std::move(initialPath)), basepath(initialPath.empty() ? "/" : std::move(initialPath)),
onSelectBook(onSelectBook), onSelectBook(onSelectBook),
onGoHome(onGoHome) {} onGoHome(onGoHome) {}

View File

@@ -31,7 +31,7 @@ void RecentBooksActivity::loadRecentBooks() {
} }
void RecentBooksActivity::onEnter() { void RecentBooksActivity::onEnter() {
Activity::onEnter(); ActivityWithSubactivity::onEnter();
// Load data // Load data
loadRecentBooks(); loadRecentBooks();
@@ -41,11 +41,16 @@ void RecentBooksActivity::onEnter() {
} }
void RecentBooksActivity::onExit() { void RecentBooksActivity::onExit() {
Activity::onExit(); ActivityWithSubactivity::onExit();
recentBooks.clear(); recentBooks.clear();
} }
void RecentBooksActivity::loop() { void RecentBooksActivity::loop() {
if (subActivity) {
subActivity->loop();
return;
}
const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, true); const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, true);
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {

View File

@@ -5,11 +5,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "../Activity.h" #include "../ActivityWithSubactivity.h"
#include "RecentBooksStore.h" #include "RecentBooksStore.h"
#include "util/ButtonNavigator.h" #include "util/ButtonNavigator.h"
class RecentBooksActivity final : public Activity { class RecentBooksActivity final : public ActivityWithSubactivity {
private: private:
ButtonNavigator buttonNavigator; ButtonNavigator buttonNavigator;
@@ -29,7 +29,7 @@ class RecentBooksActivity final : public Activity {
explicit RecentBooksActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, explicit RecentBooksActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void()>& onGoHome, const std::function<void()>& onGoHome,
const std::function<void(const std::string& path)>& onSelectBook) const std::function<void(const std::string& path)>& onSelectBook)
: Activity("RecentBooks", renderer, mappedInput), onSelectBook(onSelectBook), onGoHome(onGoHome) {} : ActivityWithSubactivity("RecentBooks", renderer, mappedInput), onSelectBook(onSelectBook), onGoHome(onGoHome) {}
void onEnter() override; void onEnter() override;
void onExit() override; void onExit() override;
void loop() override; void loop() override;