Remap buttons
This commit is contained in:
@@ -130,14 +130,15 @@ void FileBrowserActivity::clearFileMetadata(const std::string& fullPath) {
|
|||||||
void FileBrowserActivity::loop() {
|
void FileBrowserActivity::loop() {
|
||||||
const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, false);
|
const int pageItems = UITheme::getInstance().getNumberOfItemsPerPage(renderer, true, false, true, false);
|
||||||
|
|
||||||
// Back always navigates to the home screen
|
// Long press BACK always navigates to home
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
if (mappedInput.isPressed(MappedInputManager::Button::Back) && mappedInput.getHeldTime() >= GO_HOME_MS) {
|
||||||
onGoHome();
|
onGoHome();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confirm navigates up one directory (labelled "Back" when in a subdir)
|
// Short press BACK goes up one directory (if not root) or home (at root)
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm) && basepath != "/") {
|
if (mappedInput.wasReleased(MappedInputManager::Button::Back) && mappedInput.getHeldTime() < GO_HOME_MS) {
|
||||||
|
if (basepath != "/") {
|
||||||
const std::string oldPath = basepath;
|
const std::string oldPath = basepath;
|
||||||
basepath.replace(basepath.find_last_of('/'), std::string::npos, "");
|
basepath.replace(basepath.find_last_of('/'), std::string::npos, "");
|
||||||
if (basepath.empty()) basepath = "/";
|
if (basepath.empty()) basepath = "/";
|
||||||
@@ -146,18 +147,43 @@ void FileBrowserActivity::loop() {
|
|||||||
const std::string dirName = oldPath.substr(pos + 1) + "/";
|
const std::string dirName = oldPath.substr(pos + 1) + "/";
|
||||||
selectorIndex = findEntry(dirName);
|
selectorIndex = findEntry(dirName);
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
|
} else {
|
||||||
|
onGoHome();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Left opens the selected entry; long press deletes files
|
// Confirm short press opens selected entry; long press does nothing
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Left)) {
|
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm) && mappedInput.getHeldTime() < GO_HOME_MS) {
|
||||||
if (files.empty()) return;
|
if (files.empty()) return;
|
||||||
|
|
||||||
const std::string& entry = files[selectorIndex];
|
const std::string& entry = files[selectorIndex];
|
||||||
const bool isDirectory = (entry.back() == '/');
|
const bool isDirectory = (entry.back() == '/');
|
||||||
|
|
||||||
if (mappedInput.getHeldTime() >= GO_HOME_MS && !isDirectory) {
|
if (basepath.back() != '/') basepath += "/";
|
||||||
// Long press: delete file
|
if (isDirectory) {
|
||||||
|
basepath += entry.substr(0, entry.length() - 1);
|
||||||
|
loadFiles();
|
||||||
|
selectorIndex = 0;
|
||||||
|
requestUpdate();
|
||||||
|
} else {
|
||||||
|
onSelectBook(basepath + entry);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Left short press does nothing; long press deletes selected file after confirmation
|
||||||
|
if (mappedInput.wasReleased(MappedInputManager::Button::Left)) {
|
||||||
|
if (mappedInput.getHeldTime() < GO_HOME_MS || files.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& entry = files[selectorIndex];
|
||||||
|
const bool isDirectory = (entry.back() == '/');
|
||||||
|
if (isDirectory) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::string cleanBase = basepath;
|
std::string cleanBase = basepath;
|
||||||
if (cleanBase.back() != '/') cleanBase += "/";
|
if (cleanBase.back() != '/') cleanBase += "/";
|
||||||
const std::string fullPath = cleanBase + entry;
|
const std::string fullPath = cleanBase + entry;
|
||||||
@@ -189,19 +215,6 @@ void FileBrowserActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Short press: enter directory or open file
|
|
||||||
if (basepath.back() != '/') basepath += "/";
|
|
||||||
if (isDirectory) {
|
|
||||||
basepath += entry.substr(0, entry.length() - 1);
|
|
||||||
loadFiles();
|
|
||||||
selectorIndex = 0;
|
|
||||||
requestUpdate();
|
|
||||||
} else {
|
|
||||||
onSelectBook(basepath + entry);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Right opens the info page for epub files
|
// Right opens the info page for epub files
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Right)) {
|
if (mappedInput.wasReleased(MappedInputManager::Button::Right)) {
|
||||||
if (files.empty()) return;
|
if (files.empty()) return;
|
||||||
@@ -270,12 +283,12 @@ void FileBrowserActivity::render(RenderLock&&) {
|
|||||||
// Side buttons (Up/Down) navigate; show their hints on the side
|
// Side buttons (Up/Down) navigate; show their hints on the side
|
||||||
GUI.drawSideButtonHints(renderer, tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
GUI.drawSideButtonHints(renderer, tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
||||||
|
|
||||||
// Front buttons: Back=Home, Confirm=Back(subdir)/empty(root), Left=Open, Right=Info(epub only)
|
// Front buttons: Back=Back(subdir)/Home(root), Confirm=Open, Left=hidden long-press delete, Right=Info
|
||||||
const bool hasInfo =
|
const bool hasInfo =
|
||||||
!files.empty() && files[selectorIndex].back() != '/' &&
|
!files.empty() && files[selectorIndex].back() != '/' &&
|
||||||
(FsHelpers::hasEpubExtension(files[selectorIndex]) || FsHelpers::hasXtcExtension(files[selectorIndex]));
|
(FsHelpers::hasEpubExtension(files[selectorIndex]) || FsHelpers::hasXtcExtension(files[selectorIndex]));
|
||||||
const auto labels = mappedInput.mapLabels(tr(STR_HOME), basepath == "/" ? "" : tr(STR_BACK),
|
const auto labels = mappedInput.mapLabels(basepath == "/" ? tr(STR_HOME) : tr(STR_BACK),
|
||||||
files.empty() ? "" : tr(STR_OPEN), hasInfo ? tr(STR_INFO) : "");
|
files.empty() ? "" : tr(STR_OPEN), "", hasInfo ? tr(STR_INFO) : "");
|
||||||
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||||
|
|
||||||
renderer.displayBuffer();
|
renderer.displayBuffer();
|
||||||
|
|||||||
Reference in New Issue
Block a user