mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 22:57:50 +03:00
refactor: my library activity
This commit is contained in:
parent
bde92c288f
commit
3c727dd8f9
@ -21,7 +21,6 @@ constexpr int LEFT_MARGIN = 20;
|
|||||||
constexpr int RIGHT_MARGIN = 40; // Extra space for scroll indicator
|
constexpr int RIGHT_MARGIN = 40; // Extra space for scroll indicator
|
||||||
|
|
||||||
// Timing thresholds
|
// Timing thresholds
|
||||||
constexpr int SKIP_PAGE_MS = 700;
|
|
||||||
constexpr unsigned long GO_HOME_MS = 1000;
|
constexpr unsigned long GO_HOME_MS = 1000;
|
||||||
|
|
||||||
void sortFileList(std::vector<std::string>& strs) {
|
void sortFileList(std::vector<std::string>& strs) {
|
||||||
@ -178,13 +177,9 @@ void MyLibraryActivity::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool upReleased = mappedInput.wasReleased(MappedInputManager::Button::Up);
|
|
||||||
const bool downReleased = mappedInput.wasReleased(MappedInputManager::Button::Down);
|
|
||||||
const bool leftReleased = mappedInput.wasReleased(MappedInputManager::Button::Left);
|
const bool leftReleased = mappedInput.wasReleased(MappedInputManager::Button::Left);
|
||||||
const bool rightReleased = mappedInput.wasReleased(MappedInputManager::Button::Right);
|
const bool rightReleased = mappedInput.wasReleased(MappedInputManager::Button::Right);
|
||||||
|
|
||||||
const bool skipPage = mappedInput.getHeldTime() > SKIP_PAGE_MS;
|
|
||||||
|
|
||||||
// Confirm button - open selected item
|
// Confirm button - open selected item
|
||||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||||
if (currentTab == Tab::Recent) {
|
if (currentTab == Tab::Recent) {
|
||||||
@ -249,24 +244,28 @@ void MyLibraryActivity::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Navigation: Up/Down moves through items only
|
// Navigation: Up/Down moves through items only
|
||||||
const bool prevReleased = upReleased;
|
constexpr auto upButton = MappedInputManager::Button::Up;
|
||||||
const bool nextReleased = downReleased;
|
constexpr auto downButton = MappedInputManager::Button::Down;
|
||||||
|
|
||||||
if (prevReleased && itemCount > 0) {
|
buttonNavigator.onRelease({downButton}, [this, itemCount] {
|
||||||
if (skipPage) {
|
selectorIndex = ButtonNavigator::nextIndex(selectorIndex, itemCount);
|
||||||
selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + itemCount) % itemCount;
|
|
||||||
} else {
|
|
||||||
selectorIndex = (selectorIndex + itemCount - 1) % itemCount;
|
|
||||||
}
|
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
} else if (nextReleased && itemCount > 0) {
|
});
|
||||||
if (skipPage) {
|
|
||||||
selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % itemCount;
|
buttonNavigator.onRelease({upButton}, [this, itemCount] {
|
||||||
} else {
|
selectorIndex = ButtonNavigator::previousIndex(selectorIndex, itemCount);
|
||||||
selectorIndex = (selectorIndex + 1) % itemCount;
|
|
||||||
}
|
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
}
|
});
|
||||||
|
|
||||||
|
buttonNavigator.onContinuous({downButton}, [this, itemCount, pageItems] {
|
||||||
|
selectorIndex = ButtonNavigator::nextPageIndex(selectorIndex, itemCount, pageItems);
|
||||||
|
updateRequired = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonNavigator.onContinuous({upButton}, [this, itemCount, pageItems] {
|
||||||
|
selectorIndex = ButtonNavigator::previousPageIndex(selectorIndex, itemCount, pageItems);
|
||||||
|
updateRequired = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyLibraryActivity::displayTaskLoop() {
|
void MyLibraryActivity::displayTaskLoop() {
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "../Activity.h"
|
#include "../Activity.h"
|
||||||
#include "RecentBooksStore.h"
|
#include "RecentBooksStore.h"
|
||||||
|
#include "util/ButtonNavigator.h"
|
||||||
|
|
||||||
class MyLibraryActivity final : public Activity {
|
class MyLibraryActivity final : public Activity {
|
||||||
public:
|
public:
|
||||||
@ -17,6 +18,7 @@ class MyLibraryActivity final : public Activity {
|
|||||||
private:
|
private:
|
||||||
TaskHandle_t displayTaskHandle = nullptr;
|
TaskHandle_t displayTaskHandle = nullptr;
|
||||||
SemaphoreHandle_t renderingMutex = nullptr;
|
SemaphoreHandle_t renderingMutex = nullptr;
|
||||||
|
ButtonNavigator buttonNavigator;
|
||||||
|
|
||||||
Tab currentTab = Tab::Recent;
|
Tab currentTab = Tab::Recent;
|
||||||
int selectorIndex = 0;
|
int selectorIndex = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user