| 187 | } |
| 188 | |
| 189 | void 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; |
nothing calls this directly
no test coverage detected