mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 07:07:38 +03:00
Enhance RecentBooksActivity to manage book paths
- Added a new vector to store book paths alongside titles, ensuring that missing files are handled correctly. - Updated methods to utilize the new bookPaths vector for selecting and rendering recent books. - Cleared bookPaths during activity exit to prevent memory leaks.
This commit is contained in:
parent
067a36a7b4
commit
6401f099f4
@ -41,13 +41,14 @@ void RecentBooksActivity::onEnter() {
|
||||
|
||||
// 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())) {
|
||||
bookTitles.emplace_back("[Missing]");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -75,6 +76,7 @@ void RecentBooksActivity::onEnter() {
|
||||
}
|
||||
|
||||
bookTitles.push_back(title);
|
||||
bookPaths.push_back(path);
|
||||
}
|
||||
|
||||
selectorIndex = 0;
|
||||
@ -102,6 +104,7 @@ void RecentBooksActivity::onExit() {
|
||||
vSemaphoreDelete(renderingMutex);
|
||||
renderingMutex = nullptr;
|
||||
bookTitles.clear();
|
||||
bookPaths.clear();
|
||||
}
|
||||
|
||||
void RecentBooksActivity::loop() {
|
||||
@ -112,12 +115,11 @@ void RecentBooksActivity::loop() {
|
||||
|
||||
const bool skipPage = mappedInput.getHeldTime() > SKIP_PAGE_MS;
|
||||
const int pageItems = getPageItems();
|
||||
const int bookCount = RECENT_BOOKS.getCount();
|
||||
const int bookCount = static_cast<int>(bookTitles.size());
|
||||
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
if (bookCount > 0 && selectorIndex < bookCount) {
|
||||
const auto& books = RECENT_BOOKS.getBooks();
|
||||
onSelectBook(books[selectorIndex]);
|
||||
onSelectBook(bookPaths[selectorIndex]);
|
||||
}
|
||||
} else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||
onGoBack();
|
||||
@ -155,7 +157,7 @@ void RecentBooksActivity::render() const {
|
||||
|
||||
const auto pageWidth = renderer.getScreenWidth();
|
||||
const int pageItems = getPageItems();
|
||||
const int bookCount = RECENT_BOOKS.getCount();
|
||||
const int bookCount = static_cast<int>(bookTitles.size());
|
||||
|
||||
// Draw header
|
||||
renderer.drawCenteredText(UI_12_FONT_ID, 15, "Recent Books", true, EpdFontFamily::BOLD);
|
||||
|
||||
@ -15,6 +15,7 @@ class RecentBooksActivity final : public Activity {
|
||||
int selectorIndex = 0;
|
||||
bool updateRequired = false;
|
||||
std::vector<std::string> bookTitles; // Display titles for each book
|
||||
std::vector<std::string> bookPaths; // Paths for each visible book (excludes missing)
|
||||
const std::function<void()> onGoBack;
|
||||
const std::function<void(const std::string& path)> onSelectBook;
|
||||
|
||||
|
||||
@ -224,7 +224,6 @@ void onGoToSettings() {
|
||||
enterNewActivity(new SettingsActivity(renderer, mappedInputManager, onGoHome));
|
||||
}
|
||||
|
||||
void onGoHome();
|
||||
void onGoToRecentBooks() {
|
||||
exitActivity();
|
||||
enterNewActivity(new RecentBooksActivity(renderer, mappedInputManager, onGoHome, onGoToReader));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user