Use new method to decide button press
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "../ActivityManager.h"
|
#include "../ActivityManager.h"
|
||||||
#include "../reader/ReaderUtils.h"
|
|
||||||
#include "../util/ConfirmationActivity.h"
|
#include "../util/ConfirmationActivity.h"
|
||||||
#include "BookInfoActivity.h"
|
#include "BookInfoActivity.h"
|
||||||
#include "CrossPointState.h"
|
#include "CrossPointState.h"
|
||||||
@@ -54,11 +53,16 @@ void RecentBooksActivity::onExit() {
|
|||||||
void RecentBooksActivity::loop() {
|
void RecentBooksActivity::loop() {
|
||||||
const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, true);
|
const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, true);
|
||||||
|
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm) && !recentBooks.empty() &&
|
ButtonEventManager::ButtonEvent ev;
|
||||||
selectorIndex < static_cast<int>(recentBooks.size())) {
|
while (buttonEvents.consumeEvent(ev)) {
|
||||||
|
if (ev.button == MappedInputManager::Button::Confirm &&
|
||||||
|
(ev.type == ButtonEventManager::PressType::Short || ev.type == ButtonEventManager::PressType::Long)) {
|
||||||
|
if (recentBooks.empty() || selectorIndex >= recentBooks.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Long-press Confirm signals "open with KOReader sync" only for EPUBs.
|
// Long-press Confirm signals "open with KOReader sync" only for EPUBs.
|
||||||
// Short-press is unchanged direct open.
|
// Short-press is unchanged direct open.
|
||||||
const bool longPress = mappedInput.getHeldTime() >= ReaderUtils::GO_HOME_MS && KOREADER_STORE.hasCredentials();
|
const bool longPress = (ev.type == ButtonEventManager::PressType::Long) && KOREADER_STORE.hasCredentials();
|
||||||
const std::string& selectedPath = recentBooks[selectorIndex].path;
|
const std::string& selectedPath = recentBooks[selectorIndex].path;
|
||||||
const bool isEpubBook = FsHelpers::hasEpubExtension(selectedPath);
|
const bool isEpubBook = FsHelpers::hasEpubExtension(selectedPath);
|
||||||
LOG_DBG("RBA", "Selected recent book: %s (sync=%d epub=%d)", selectedPath.c_str(), longPress ? 1 : 0,
|
LOG_DBG("RBA", "Selected recent book: %s (sync=%d epub=%d)", selectedPath.c_str(), longPress ? 1 : 0,
|
||||||
@@ -76,13 +80,13 @@ void RecentBooksActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
if (ev.button == MappedInputManager::Button::Back && ev.type == ButtonEventManager::PressType::Short) {
|
||||||
onGoHome();
|
onGoHome();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Left button: remove selected book from recent list
|
if (ev.button == MappedInputManager::Button::Left && ev.type == ButtonEventManager::PressType::Short) {
|
||||||
if (!recentBooks.empty() && selectorIndex < recentBooks.size() &&
|
if (recentBooks.empty() || selectorIndex >= recentBooks.size()) return;
|
||||||
mappedInput.wasReleased(MappedInputManager::Button::Left)) {
|
|
||||||
const std::string bookPath = recentBooks[selectorIndex].path;
|
const std::string bookPath = recentBooks[selectorIndex].path;
|
||||||
const std::string bookTitle = recentBooks[selectorIndex].title;
|
const std::string bookTitle = recentBooks[selectorIndex].title;
|
||||||
|
|
||||||
@@ -103,12 +107,13 @@ void RecentBooksActivity::loop() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string heading = tr(STR_REMOVE) + std::string("? ");
|
std::string heading = tr(STR_REMOVE) + std::string("? ");
|
||||||
startActivityForResult(std::make_unique<ConfirmationActivity>(renderer, mappedInput, heading, bookTitle), handler);
|
startActivityForResult(std::make_unique<ConfirmationActivity>(renderer, mappedInput, heading, bookTitle),
|
||||||
|
handler);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Right) && !recentBooks.empty() &&
|
if (ev.button == MappedInputManager::Button::Right && ev.type == ButtonEventManager::PressType::Short) {
|
||||||
selectorIndex < static_cast<int>(recentBooks.size())) {
|
if (recentBooks.empty() || selectorIndex >= recentBooks.size()) return;
|
||||||
const std::string& path = recentBooks[selectorIndex].path;
|
const std::string& path = recentBooks[selectorIndex].path;
|
||||||
if (FsHelpers::hasEpubExtension(path) || FsHelpers::hasXtcExtension(path)) {
|
if (FsHelpers::hasEpubExtension(path) || FsHelpers::hasXtcExtension(path)) {
|
||||||
startActivityForResult(std::make_unique<BookInfoActivity>(renderer, mappedInput, path),
|
startActivityForResult(std::make_unique<BookInfoActivity>(renderer, mappedInput, path),
|
||||||
@@ -116,6 +121,7 @@ void RecentBooksActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int listSize = static_cast<int>(recentBooks.size());
|
int listSize = static_cast<int>(recentBooks.size());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user