style: use std::find_if instead of raw loop

Address cppcheck useStlAlgorithm warning in HomeActivity.
This commit is contained in:
Brackyt 2026-01-29 13:42:01 +01:00
parent fea92fd235
commit 1803cdc389

View File

@ -7,6 +7,7 @@
#include <ThemeManager.h> #include <ThemeManager.h>
#include <Xtc.h> #include <Xtc.h>
#include <algorithm>
#include <cstring> #include <cstring>
#include <vector> #include <vector>
@ -58,19 +59,16 @@ void HomeActivity::onEnter() {
cachedProgressPercent = 0; cachedProgressPercent = 0;
// Check if current book is in recent books - use cached data instead of reloading // Check if current book is in recent books - use cached data instead of reloading
bool foundInRecent = false; const auto& openPath = APP_STATE.openEpubPath;
for (const auto& book : cachedRecentBooks) { auto it = std::find_if(cachedRecentBooks.begin(), cachedRecentBooks.end(),
if (book.path == APP_STATE.openEpubPath) { [&openPath](const CachedBookInfo& book) { return book.path == openPath; });
lastBookTitle = book.title;
coverBmpPath = book.coverPath;
hasCoverImage = !book.coverPath.empty();
cachedProgressPercent = book.progressPercent;
foundInRecent = true;
break;
}
}
if (!foundInRecent) { if (it != cachedRecentBooks.end()) {
lastBookTitle = it->title;
coverBmpPath = it->coverPath;
hasCoverImage = !it->coverPath.empty();
cachedProgressPercent = it->progressPercent;
} else {
// Book not in recent list, need to load it // Book not in recent list, need to load it
lastBookTitle = APP_STATE.openEpubPath; lastBookTitle = APP_STATE.openEpubPath;
const size_t lastSlash = lastBookTitle.find_last_of('/'); const size_t lastSlash = lastBookTitle.find_last_of('/');