Remember which tab you were on when opening a book

This commit is contained in:
Kenneth 2026-01-14 13:12:21 -05:00
parent fc50460c35
commit 4ced80fe39
5 changed files with 19 additions and 16 deletions

View File

@ -207,7 +207,7 @@ void MyLibraryActivity::loop() {
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
if (currentTab == Tab::Recent) {
if (!bookPaths.empty() && selectorIndex < static_cast<int>(bookPaths.size())) {
onSelectBook(bookPaths[selectorIndex]);
onSelectBook(bookPaths[selectorIndex], currentTab);
}
} else {
// Files tab
@ -221,7 +221,7 @@ void MyLibraryActivity::loop() {
updateRequired = true;
} else {
// Open file
onSelectBook(basepath + files[selectorIndex]);
onSelectBook(basepath + files[selectorIndex], currentTab);
}
}
}

View File

@ -31,7 +31,7 @@ class MyLibraryActivity final : public Activity {
// Callbacks
const std::function<void()> onGoHome;
const std::function<void(const std::string& path)> onSelectBook;
const std::function<void(const std::string& path, Tab fromTab)> onSelectBook;
// Number of items that fit on a page
int getPageItems() const;
@ -54,7 +54,7 @@ class MyLibraryActivity final : public Activity {
public:
explicit MyLibraryActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
const std::function<void()>& onGoHome,
const std::function<void(const std::string& path)>& onSelectBook,
const std::function<void(const std::string& path, Tab fromTab)>& onSelectBook,
Tab initialTab = Tab::Recent, std::string initialPath = "/")
: Activity("MyLibrary", renderer, mappedInput),
currentTab(initialTab),

View File

@ -119,7 +119,7 @@ void ReaderActivity::onSelectBookFile(const std::string& path) {
void ReaderActivity::goToLibrary(const std::string& fromBookPath) {
// If coming from a book, start in that book's folder; otherwise start from root
const auto initialPath = fromBookPath.empty() ? "/" : extractFolderPath(fromBookPath);
onGoToLibrary(initialPath);
onGoToLibrary(initialPath, libraryTab);
}
void ReaderActivity::onGoToEpubReader(std::unique_ptr<Epub> epub) {

View File

@ -2,6 +2,7 @@
#include <memory>
#include "../ActivityWithSubactivity.h"
#include "activities/home/MyLibraryActivity.h"
class Epub;
class Xtc;
@ -10,8 +11,9 @@ class Txt;
class ReaderActivity final : public ActivityWithSubactivity {
std::string initialBookPath;
std::string currentBookPath; // Track current book path for navigation
MyLibraryActivity::Tab libraryTab; // Track which tab to return to
const std::function<void()> onGoBack;
const std::function<void(const std::string&)> onGoToLibrary;
const std::function<void(const std::string&, MyLibraryActivity::Tab)> onGoToLibrary;
static std::unique_ptr<Epub> loadEpub(const std::string& path);
static std::unique_ptr<Xtc> loadXtc(const std::string& path);
static std::unique_ptr<Txt> loadTxt(const std::string& path);
@ -27,10 +29,11 @@ class ReaderActivity final : public ActivityWithSubactivity {
public:
explicit ReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::string initialBookPath,
const std::function<void()>& onGoBack,
const std::function<void(const std::string&)>& onGoToLibrary)
MyLibraryActivity::Tab libraryTab, const std::function<void()>& onGoBack,
const std::function<void(const std::string&, MyLibraryActivity::Tab)>& onGoToLibrary)
: ActivityWithSubactivity("Reader", renderer, mappedInput),
initialBookPath(std::move(initialBookPath)),
libraryTab(libraryTab),
onGoBack(onGoBack),
onGoToLibrary(onGoToLibrary) {}
void onEnter() override;

View File

@ -212,12 +212,13 @@ void enterDeepSleep() {
}
void onGoHome();
void onGoToMyLibraryAtPath(const std::string& path);
void onGoToReader(const std::string& initialEpubPath) {
void onGoToMyLibraryWithTab(const std::string& path, MyLibraryActivity::Tab tab);
void onGoToReader(const std::string& initialEpubPath, MyLibraryActivity::Tab fromTab) {
exitActivity();
enterNewActivity(new ReaderActivity(renderer, mappedInputManager, initialEpubPath, onGoHome, onGoToMyLibraryAtPath));
enterNewActivity(
new ReaderActivity(renderer, mappedInputManager, initialEpubPath, fromTab, onGoHome, onGoToMyLibraryWithTab));
}
void onContinueReading() { onGoToReader(APP_STATE.openEpubPath); }
void onContinueReading() { onGoToReader(APP_STATE.openEpubPath, MyLibraryActivity::Tab::Recent); }
void onGoToFileTransfer() {
exitActivity();
@ -234,10 +235,9 @@ void onGoToMyLibrary() {
enterNewActivity(new MyLibraryActivity(renderer, mappedInputManager, onGoHome, onGoToReader));
}
void onGoToMyLibraryAtPath(const std::string& path) {
void onGoToMyLibraryWithTab(const std::string& path, MyLibraryActivity::Tab tab) {
exitActivity();
enterNewActivity(
new MyLibraryActivity(renderer, mappedInputManager, onGoHome, onGoToReader, MyLibraryActivity::Tab::Files, path));
enterNewActivity(new MyLibraryActivity(renderer, mappedInputManager, onGoHome, onGoToReader, tab, path));
}
void onGoToBrowser() {
@ -325,7 +325,7 @@ void setup() {
APP_STATE.openEpubPath = "";
APP_STATE.lastSleepImage = 0;
APP_STATE.saveToFile();
onGoToReader(path);
onGoToReader(path, MyLibraryActivity::Tab::Recent);
}
// Ensure we're not still holding the power button before leaving setup