#pragma once #include #include #include #include #include "../Activity.h" #include "OpdsServerStore.h" #include "util/ButtonNavigator.h" /** * Activity for browsing and downloading books from an OPDS server. * Supports navigation through catalog hierarchy and downloading EPUBs. * When WiFi connection fails, launches WiFi selection to let user connect. */ class OpdsBookBrowserActivity final : public Activity { public: enum class BrowserState { CHECK_WIFI, // Checking WiFi connection WIFI_SELECTION, // WiFi selection subactivity is active LOADING, // Fetching OPDS feed BROWSING, // Displaying entries (navigation or books) PICKING_DIRECTORY, // Directory picker subactivity is active DOWNLOADING, // Downloading selected EPUB DOWNLOAD_COMPLETE, // Prompt: open book or go back to listing ERROR // Error state with message }; explicit OpdsBookBrowserActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const OpdsServer* server = nullptr) : Activity("OpdsBookBrowser", renderer, mappedInput), server(server ? *server : OpdsServer{}) {} void onEnter() override; void onExit() override; void loop() override; void render(RenderLock&&) override; private: ButtonNavigator buttonNavigator; BrowserState state = BrowserState::LOADING; std::vector entries; std::vector navigationHistory; // Stack of previous feed paths for back navigation std::string currentPath; // Current feed path being displayed int selectorIndex = 0; std::string errorMessage; std::string statusMessage; size_t downloadProgress = 0; size_t downloadTotal = 0; std::string downloadedFilePath; int promptSelection = 0; // 0 = back to listing, 1 = open book OpdsServer server; // Copied at construction — safe even if the store changes during browsing OpdsEntry pendingBook; void checkAndConnectWifi(); void launchWifiSelection(); void onWifiSelectionComplete(bool connected); void fetchFeed(const std::string& path); void navigateToEntry(const OpdsEntry& entry); void navigateBack(); void launchDirectoryPicker(const OpdsEntry& book); void onDirectoryPickerResult(const ActivityResult& result); void downloadBook(const OpdsEntry& book, const std::string& directory); void executePromptAction(int action); bool preventAutoSleep() override { return true; } };