After an OPDS download completes, show a prompt screen instead of immediately returning to the catalog. The user can choose to open the book for reading or go back to the listing. A live countdown (5s, fast refresh) auto-selects the configured default; any button press cancels the timer. A per-server "After Download" setting controls the default action (back to listing for backward compatibility). Made-with: Cursor
80 lines
3.0 KiB
C++
80 lines
3.0 KiB
C++
#pragma once
|
|
#include <OpdsParser.h>
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../ActivityWithSubactivity.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 ActivityWithSubactivity {
|
|
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 std::function<void()>& onGoHome,
|
|
const std::function<void(const std::string&)>& onGoToReader,
|
|
const OpdsServer& server)
|
|
: ActivityWithSubactivity("OpdsBookBrowser", renderer, mappedInput),
|
|
onGoHome(onGoHome),
|
|
onGoToReader(onGoToReader),
|
|
server(server) {}
|
|
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
void render(Activity::RenderLock&&) override;
|
|
|
|
private:
|
|
ButtonNavigator buttonNavigator;
|
|
BrowserState state = BrowserState::LOADING;
|
|
std::vector<OpdsEntry> entries;
|
|
std::vector<std::string> 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;
|
|
unsigned long downloadCompleteTime = 0;
|
|
int promptSelection = 0; // 0 = back to listing, 1 = open book
|
|
bool countdownActive = false;
|
|
int lastCountdownSecond = -1;
|
|
|
|
const std::function<void()> onGoHome;
|
|
const std::function<void(const std::string&)> onGoToReader;
|
|
OpdsServer server; // Copied at construction — safe even if the store changes during browsing
|
|
|
|
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 onDirectorySelected(const std::string& directory);
|
|
void onDirectoryPickerCancelled();
|
|
void downloadBook(const OpdsEntry& book, const std::string& directory);
|
|
void executePromptAction(int action);
|
|
bool preventAutoSleep() override { return true; }
|
|
|
|
OpdsEntry pendingBook;
|
|
};
|