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