mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 22:57:50 +03:00
* **What is the goal of this PR?** Implement a metadata viewer for the Recents screen * **What changes are included?** | Recents | Files | | --- | --- | | <img alt="image" src="https://github.com/user-attachments/assets/e0f2d816-ddce-4a2e-bd4a-cd431d0e6532" /> | <img alt="image" src="https://github.com/user-attachments/assets/3225cdce-d501-4175-bc92-73cb8bfe7a41" /> | For the Files screen, I have not made any changes on purpose. For the Recents screen, we now display the Book title and author. If it is a file with no epub metadata like txt or md, we display the file name without the file extension. --- Did you use AI tools to help write this code? _**< YES >**_ Although I went trough all the code manually and made changes as well, please be aware the majority of the code is AI generated. --------- Co-authored-by: Eliz Kilic <elizk@google.com>
68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
#pragma once
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/semphr.h>
|
|
#include <freertos/task.h>
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../Activity.h"
|
|
#include "RecentBooksStore.h"
|
|
|
|
class MyLibraryActivity final : public Activity {
|
|
public:
|
|
enum class Tab { Recent, Files };
|
|
|
|
private:
|
|
TaskHandle_t displayTaskHandle = nullptr;
|
|
SemaphoreHandle_t renderingMutex = nullptr;
|
|
|
|
Tab currentTab = Tab::Recent;
|
|
int selectorIndex = 0;
|
|
bool updateRequired = false;
|
|
|
|
// Recent tab state
|
|
std::vector<RecentBook> recentBooks;
|
|
|
|
// 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, Tab fromTab)> onSelectBook;
|
|
|
|
// 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;
|
|
|
|
// Rendering
|
|
static void taskTrampoline(void* param);
|
|
[[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, Tab fromTab)>& onSelectBook,
|
|
Tab initialTab = Tab::Recent, std::string initialPath = "/")
|
|
: Activity("MyLibrary", renderer, mappedInput),
|
|
currentTab(initialTab),
|
|
basepath(initialPath.empty() ? "/" : std::move(initialPath)),
|
|
onGoHome(onGoHome),
|
|
onSelectBook(onSelectBook) {}
|
|
void onEnter() override;
|
|
void onExit() override;
|
|
void loop() override;
|
|
};
|