Refactor ActivityManager calls

This commit is contained in:
jpirnay
2026-04-17 20:23:42 +02:00
parent ef088db789
commit b4881e1563
12 changed files with 156 additions and 45 deletions
+36 -4
View File
@@ -15,6 +15,21 @@
class Activity; // forward declaration
class RenderLock; // forward declaration
// Where a "child" activity (launched via one of the replaceWith* helpers) should route
// control when it exits successfully. See ActivityManager::returnFromChild().
enum class ReturnTo : uint8_t { Home, FileBrowser, RecentBooks };
// Minimal state the returning parent needs to restore its previous view (directory,
// focused item, list index). Kept as a plain struct stored by value on the
// ActivityManager — single instance, overwritten per transition, no heap churn
// beyond the two small std::strings.
struct ReturnHint {
ReturnTo target = ReturnTo::Home;
std::string path; // FileBrowser directory to restore
std::string selectName; // item to re-focus in a list (file name, book title)
int selectIndex = -1; // e.g. Recents index
};
/**
* ActivityManager
*
@@ -68,6 +83,12 @@ class ActivityManager {
// into the next one.
bool drainInput = false;
// Where returnFromChild() should route to. Set by replaceWith*() helpers, cleared
// in returnFromChild(). Cleared on any manual goHome()/goTo*() to avoid stale hints
// outliving the flow they were recorded for.
ReturnHint returnHint;
bool hasReturnHint = false;
public:
explicit ActivityManager(GfxRenderer& renderer, MappedInputManager& mappedInput)
: renderer(renderer), mappedInput(mappedInput), renderingMutex(xSemaphoreCreateMutex()) {
@@ -85,18 +106,29 @@ class ActivityManager {
// goTo... functions are convenient wrapper for replaceActivity()
void goToFileTransfer();
void goToSettings();
void goToFileBrowser(std::string path = {});
void goToRecentBooks();
void goToFileBrowser(std::string path = {}, std::string focusName = {});
void goToRecentBooks(int focusIndex = -1);
void goToGlobalBookmarks();
void goToBrowser();
void goToReader(std::string path);
void goToKOReaderSync();
void pushReader(std::string path);
void goToSleep();
void goToBoot();
void goToFullScreenMessage(std::string message, EpdFontFamily::Style style = EpdFontFamily::REGULAR);
void goToWeather();
void goHome();
void goHome(std::string focusBookPath = {});
// Replace-with-hint helpers: destroy the current activity before launching the new
// one (freeing its memory) and record where to route control when the new activity
// exits. Consumed by returnFromChild().
void replaceWithReader(std::string path, ReturnHint hint);
void replaceWithFileBrowser(std::string path, ReturnHint hint, std::string focusName = {});
void replaceWithRecentBooks(ReturnHint hint);
// Called by a "child" activity on successful exit. Consults the stored ReturnHint,
// clears it, and dispatches to the corresponding parent with restoration args. If
// no hint is set, defaults to goHome().
void returnFromChild();
// This will move current activity to stack instead of deleting it
void pushActivity(std::unique_ptr<Activity>&& activity);