From 2f62c0bcc44830ce338e0c115f137339f4e0991b Mon Sep 17 00:00:00 2001 From: Kenneth Date: Tue, 13 Jan 2026 14:36:37 -0500 Subject: [PATCH] Clean up unused files --- src/activities/home/MyLibraryActivity.cpp | 19 -- src/activities/home/MyLibraryActivity.h | 2 +- src/activities/home/RecentBooksActivity.cpp | 184 -------------------- src/activities/home/RecentBooksActivity.h | 37 ---- 4 files changed, 1 insertion(+), 241 deletions(-) delete mode 100644 src/activities/home/RecentBooksActivity.cpp delete mode 100644 src/activities/home/RecentBooksActivity.h diff --git a/src/activities/home/MyLibraryActivity.cpp b/src/activities/home/MyLibraryActivity.cpp index 0feee15d..01b34a4f 100644 --- a/src/activities/home/MyLibraryActivity.cpp +++ b/src/activities/home/MyLibraryActivity.cpp @@ -1,6 +1,5 @@ #include "MyLibraryActivity.h" -#include #include #include @@ -97,24 +96,6 @@ void MyLibraryActivity::loadRecentBooks() { title = title.substr(lastSlash + 1); } - const std::string ext5 = - title.length() >= 5 ? title.substr(title.length() - 5) : ""; - const std::string ext4 = - title.length() >= 4 ? title.substr(title.length() - 4) : ""; - - // If epub, try to load the metadata for title - if (ext5 == ".epub") { - Epub epub(path, "/.crosspoint"); - epub.load(false); - if (!epub.getTitle().empty()) { - title = std::string(epub.getTitle()); - } - } else if (ext5 == ".xtch") { - title.resize(title.length() - 5); - } else if (ext4 == ".xtc") { - title.resize(title.length() - 4); - } - bookTitles.push_back(title); bookPaths.push_back(path); } diff --git a/src/activities/home/MyLibraryActivity.h b/src/activities/home/MyLibraryActivity.h index 8e01c666..ccea820a 100644 --- a/src/activities/home/MyLibraryActivity.h +++ b/src/activities/home/MyLibraryActivity.h @@ -21,7 +21,7 @@ private: int selectorIndex = 0; bool updateRequired = false; - // Recent tab state (from RecentBooksActivity) + // Recent tab state std::vector bookTitles; // Display titles for each book std::vector bookPaths; // Paths for each visible book (excludes missing) diff --git a/src/activities/home/RecentBooksActivity.cpp b/src/activities/home/RecentBooksActivity.cpp deleted file mode 100644 index b5d081ec..00000000 --- a/src/activities/home/RecentBooksActivity.cpp +++ /dev/null @@ -1,184 +0,0 @@ -#include "RecentBooksActivity.h" - -#include -#include -#include - -#include "MappedInputManager.h" -#include "RecentBooksStore.h" -#include "fontIds.h" - -namespace { -// Time threshold for treating a long press as a page-up/page-down -constexpr int SKIP_PAGE_MS = 700; -} // namespace - -int RecentBooksActivity::getPageItems() const { - // Layout constants used in render - constexpr int startY = 60; - constexpr int lineHeight = 30; - - const int screenHeight = renderer.getScreenHeight(); - const int availableHeight = screenHeight - startY; - int items = availableHeight / lineHeight; - - // Ensure we always have at least one item per page to avoid division by zero - if (items < 1) { - items = 1; - } - return items; -} - -void RecentBooksActivity::taskTrampoline(void* param) { - auto* self = static_cast(param); - self->displayTaskLoop(); -} - -void RecentBooksActivity::onEnter() { - Activity::onEnter(); - - renderingMutex = xSemaphoreCreateMutex(); - - // Load book titles from recent books list - bookTitles.clear(); - bookPaths.clear(); - const auto& books = RECENT_BOOKS.getBooks(); - bookTitles.reserve(books.size()); - bookPaths.reserve(books.size()); - - for (const auto& path : books) { - // Skip if file no longer exists - if (!SdMan.exists(path.c_str())) { - continue; - } - - // Extract filename from path for display - std::string title = path; - const size_t lastSlash = title.find_last_of('/'); - if (lastSlash != std::string::npos) { - title = title.substr(lastSlash + 1); - } - - const std::string ext5 = title.length() >= 5 ? title.substr(title.length() - 5) : ""; - const std::string ext4 = title.length() >= 4 ? title.substr(title.length() - 4) : ""; - - // If epub, try to load the metadata for title - if (ext5 == ".epub") { - Epub epub(path, "/.crosspoint"); - epub.load(false); - if (!epub.getTitle().empty()) { - title = std::string(epub.getTitle()); - } - } else if (ext5 == ".xtch") { - title.resize(title.length() - 5); - } else if (ext4 == ".xtc") { - title.resize(title.length() - 4); - } - - bookTitles.push_back(title); - bookPaths.push_back(path); - } - - selectorIndex = 0; - - // Trigger first update - updateRequired = true; - - xTaskCreate(&RecentBooksActivity::taskTrampoline, "RecentBooksActivityTask", - 4096, // Stack size - this, // Parameters - 1, // Priority - &displayTaskHandle // Task handle - ); -} - -void RecentBooksActivity::onExit() { - Activity::onExit(); - - // Wait until not rendering to delete task to avoid killing mid-instruction to EPD - xSemaphoreTake(renderingMutex, portMAX_DELAY); - if (displayTaskHandle) { - vTaskDelete(displayTaskHandle); - displayTaskHandle = nullptr; - } - vSemaphoreDelete(renderingMutex); - renderingMutex = nullptr; - bookTitles.clear(); - bookPaths.clear(); -} - -void RecentBooksActivity::loop() { - const bool prevReleased = mappedInput.wasReleased(MappedInputManager::Button::Up) || - mappedInput.wasReleased(MappedInputManager::Button::Left); - const bool nextReleased = mappedInput.wasReleased(MappedInputManager::Button::Down) || - mappedInput.wasReleased(MappedInputManager::Button::Right); - - const bool skipPage = mappedInput.getHeldTime() > SKIP_PAGE_MS; - const int pageItems = getPageItems(); - const int bookCount = static_cast(bookTitles.size()); - - if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) { - if (bookCount > 0 && selectorIndex < bookCount) { - onSelectBook(bookPaths[selectorIndex]); - } - } else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) { - onGoBack(); - } else if (prevReleased && bookCount > 0) { - if (skipPage) { - selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + bookCount) % bookCount; - } else { - selectorIndex = (selectorIndex + bookCount - 1) % bookCount; - } - updateRequired = true; - } else if (nextReleased && bookCount > 0) { - if (skipPage) { - selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % bookCount; - } else { - selectorIndex = (selectorIndex + 1) % bookCount; - } - updateRequired = true; - } -} - -void RecentBooksActivity::displayTaskLoop() { - while (true) { - if (updateRequired) { - updateRequired = false; - xSemaphoreTake(renderingMutex, portMAX_DELAY); - render(); - xSemaphoreGive(renderingMutex); - } - vTaskDelay(10 / portTICK_PERIOD_MS); - } -} - -void RecentBooksActivity::render() const { - renderer.clearScreen(); - - const auto pageWidth = renderer.getScreenWidth(); - const int pageItems = getPageItems(); - const int bookCount = static_cast(bookTitles.size()); - - // Draw header - renderer.drawCenteredText(UI_12_FONT_ID, 15, "Recent Books", true, EpdFontFamily::BOLD); - - // Help text - const auto labels = mappedInput.mapLabels("« Back", "Open", "", ""); - renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3, labels.btn4); - - if (bookCount == 0) { - renderer.drawText(UI_10_FONT_ID, 20, 60, "No recent books"); - renderer.displayBuffer(); - return; - } - - const auto pageStartIndex = selectorIndex / pageItems * pageItems; - renderer.fillRect(0, 60 + (selectorIndex % pageItems) * 30 - 2, pageWidth - 1, 30); - - for (int i = pageStartIndex; i < bookCount && i < pageStartIndex + pageItems; i++) { - auto item = renderer.truncatedText(UI_10_FONT_ID, bookTitles[i].c_str(), pageWidth - 40); - renderer.drawText(UI_10_FONT_ID, 20, 60 + (i % pageItems) * 30, item.c_str(), i != selectorIndex); - } - - renderer.displayBuffer(); -} diff --git a/src/activities/home/RecentBooksActivity.h b/src/activities/home/RecentBooksActivity.h deleted file mode 100644 index 3e386787..00000000 --- a/src/activities/home/RecentBooksActivity.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once -#include -#include -#include - -#include -#include -#include - -#include "../Activity.h" - -class RecentBooksActivity final : public Activity { - TaskHandle_t displayTaskHandle = nullptr; - SemaphoreHandle_t renderingMutex = nullptr; - int selectorIndex = 0; - bool updateRequired = false; - std::vector bookTitles; // Display titles for each book - std::vector bookPaths; // Paths for each visible book (excludes missing) - const std::function onGoBack; - const std::function onSelectBook; - - // Number of items that fit on a page - int getPageItems() const; - - static void taskTrampoline(void* param); - [[noreturn]] void displayTaskLoop(); - void render() const; - - public: - explicit RecentBooksActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, - const std::function& onGoBack, - const std::function& onSelectBook) - : Activity("RecentBooks", renderer, mappedInput), onGoBack(onGoBack), onSelectBook(onSelectBook) {} - void onEnter() override; - void onExit() override; - void loop() override; -};