diff --git a/src/activities/reader/XtcReaderActivity.cpp b/src/activities/reader/XtcReaderActivity.cpp index d65bab38..b918c711 100644 --- a/src/activities/reader/XtcReaderActivity.cpp +++ b/src/activities/reader/XtcReaderActivity.cpp @@ -12,13 +12,14 @@ #include #include +#include + #include "CrossPointSettings.h" #include "CrossPointState.h" #include "MappedInputManager.h" #include "ReaderUtils.h" #include "RecentBooksStore.h" #include "XtcReaderChapterSelectionActivity.h" -#include "components/UITheme.h" #include "fontIds.h" namespace { @@ -462,24 +463,24 @@ void XtcReaderActivity::onButtonAction(const CrossPointSettings::BUTTON_ACTION a case BA::BTN_NEXT_SECTION: if (xtc->hasChapters()) { const auto& chapters = xtc->getChapters(); - for (const auto& ch : chapters) { - if (ch.startPage > currentPage) { - currentPage = ch.startPage; - requestUpdate(); - break; - } + const auto nextChapter = std::find_if(chapters.begin(), chapters.end(), + [this](const auto& ch) { return ch.startPage > currentPage; }); + + if (nextChapter != chapters.end()) { + currentPage = nextChapter->startPage; + requestUpdate(); } } break; case BA::BTN_PREV_SECTION: if (xtc->hasChapters()) { const auto& chapters = xtc->getChapters(); - for (int i = static_cast(chapters.size()) - 1; i >= 0; i--) { - if (chapters[i].startPage < currentPage) { - currentPage = chapters[i].startPage; - requestUpdate(); - break; - } + const auto prevChapter = std::find_if(chapters.rbegin(), chapters.rend(), + [this](const auto& ch) { return ch.startPage < currentPage; }); + + if (prevChapter != chapters.rend()) { + currentPage = prevChapter->startPage; + requestUpdate(); } } break;