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

68 lines
2.0 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 {
2026-01-13 14:43:19 -05:00
public:
2026-01-13 12:44:54 -05:00
enum class Tab { Recent, Files };
2026-01-13 14:43:19 -05:00
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;
2026-01-13 14:36:37 -05:00
// Recent tab state
2026-01-13 14:43:19 -05:00
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;
2026-01-13 14:43:19 -05:00
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();
size_t findEntry(const std::string& name) const;
2026-01-13 12:44:54 -05:00
// Rendering
2026-01-13 14:43:19 -05:00
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;
2026-01-13 14:43:19 -05:00
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, std::string initialPath = "/")
2026-01-13 14:43:19 -05:00
: Activity("MyLibrary", renderer, mappedInput),
currentTab(initialTab),
basepath(initialPath.empty() ? "/" : std::move(initialPath)),
2026-01-13 14:43:19 -05:00
onGoHome(onGoHome),
onSelectBook(onSelectBook) {}
2026-01-13 12:44:54 -05:00
void onEnter() override;
void onExit() override;
void loop() override;
};