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

View File

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

View File

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

View File

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

View File

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