crosspoint-reader/src/activities/home/MyLibraryActivity.h

66 lines
1.8 KiB
C
Raw Normal View History

2026-01-13 12:44:54 -05:00
#pragma once
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <freertos/task.h>
#include <functional>
#include <string>
#include <vector>
#include "../Activity.h"
class MyLibraryActivity final : public Activity {
public:
2026-01-13 12:44:54 -05:00
enum class Tab { Recent, Files };
private:
2026-01-13 12:44:54 -05:00
TaskHandle_t displayTaskHandle = nullptr;
SemaphoreHandle_t renderingMutex = nullptr;
Tab currentTab = Tab::Recent;
int selectorIndex = 0;
bool updateRequired = false;
// Recent tab state (from RecentBooksActivity)
std::vector<std::string> bookTitles; // Display titles for each book
std::vector<std::string>
bookPaths; // Paths for each visible book (excludes missing)
2026-01-13 12:44:54 -05:00
// Files tab state (from FileSelectionActivity)
std::string basepath = "/";
std::vector<std::string> files;
// Callbacks
const std::function<void()> onGoHome;
const std::function<void(const std::string &path)> onSelectBook;
2026-01-13 12:44:54 -05:00
// Number of items that fit on a page
int getPageItems() const;
int getCurrentItemCount() const;
int getTotalPages() const;
int getCurrentPage() const;
// Data loading
void loadRecentBooks();
void loadFiles();
// Rendering
static void taskTrampoline(void *param);
2026-01-13 12:44:54 -05:00
[[noreturn]] void displayTaskLoop();
void render() const;
void renderRecentTab() const;
void renderFilesTab() const;
public:
explicit MyLibraryActivity(
GfxRenderer &renderer, MappedInputManager &mappedInput,
const std::function<void()> &onGoHome,
const std::function<void(const std::string &path)> &onSelectBook,
Tab initialTab = Tab::Recent)
: Activity("MyLibrary", renderer, mappedInput), currentTab(initialTab),
onGoHome(onGoHome), onSelectBook(onSelectBook) {}
2026-01-13 12:44:54 -05:00
void onEnter() override;
void onExit() override;
void loop() override;
};