MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / loop

Method loop

src/activities/home/FileBrowserActivity.cpp:189–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187}
188
189void FileBrowserActivity::loop() {
190 // Long press BACK (1s+) goes to root folder (Books mode only).
191 // In firmware-pick mode we keep navigation simple: short Back = up dir / cancel.
192 if (mode == Mode::Books && mappedInput.isPressed(MappedInputManager::Button::Back) &&
193 mappedInput.getHeldTime() >= GO_HOME_MS && basepath != "/" && !lockLongPressBack) {
194 basepath = "/";
195 loadFiles();
196 selectorIndex = 0;
197 requestUpdate();
198 return;
199 }
200
201 if (lockLongPressBack && mappedInput.wasReleased(MappedInputManager::Button::Back)) {
202 lockLongPressBack = false;
203 return;
204 }
205
206 const int pathReserved = renderer.getLineHeight(SMALL_FONT_ID) + UITheme::getInstance().getMetrics().verticalSpacing;
207 const int pageItems = UITheme::getNumberOfItemsPerPage(renderer, true, false, true, false, pathReserved);
208
209 if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
210 if (lockNextConfirmRelease) {
211 lockNextConfirmRelease = false;
212 return;
213 }
214 if (files.empty()) return;
215
216 const std::string& entry = files[selectorIndex];
217 bool isDirectory = (entry.back() == '/');
218
219 // Firmware picker: select file -> return path; navigate into directories normally.
220 if (mode == Mode::PickFirmware && !isDirectory) {
221 std::string cleanBasePath = basepath;
222 if (cleanBasePath.back() != '/') cleanBasePath += "/";
223 ActivityResult res{FilePathResult{cleanBasePath + entry}};
224 res.isCancelled = false;
225 setResult(std::move(res));
226 finish();
227 return;
228 }
229
230 if (mode == Mode::Books && mappedInput.getHeldTime() >= GO_HOME_MS) {
231 // --- LONG PRESS ACTION: DELETE FILE OR DIRECTORY ---
232 std::string cleanBasePath = basepath;
233 if (cleanBasePath.back() != '/') cleanBasePath += "/";
234 const std::string fullPath = cleanBasePath + entry;
235
236 auto handler = [this, fullPath](const ActivityResult& res) {
237 if (!res.isCancelled) {
238 LOG_DBG("FileBrowser", "Attempting to delete: %s", fullPath.c_str());
239 if (removeDirFile(fullPath)) {
240 LOG_DBG("FileBrowser", "Deleted successfully");
241 loadFiles();
242 if (files.empty()) {
243 selectorIndex = 0;
244 } else if (selectorIndex >= files.size()) {
245 // Move selection to the new "last" item
246 selectorIndex = files.size() - 1;

Callers

nothing calls this directly

Calls 10

getLineHeightMethod · 0.80
onNextReleaseMethod · 0.80
onPreviousReleaseMethod · 0.80
onNextContinuousMethod · 0.80
onPreviousContinuousMethod · 0.80
isPressedMethod · 0.45
getHeldTimeMethod · 0.45
wasReleasedMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected