| 450 | } |
| 451 | |
| 452 | void View::update(size_t start_index) { |
| 453 | const bool is_root = (state->getCurrentPath() == "/"); |
| 454 | |
| 455 | auto scoped_lockable = lvgl::getSyncLock()->asScopedLock(); |
| 456 | if (!scoped_lockable.lock(lvgl::defaultLockTime)) { |
| 457 | LOGGER.error(LOG_MESSAGE_MUTEX_LOCK_FAILED_FMT, "lvgl"); |
| 458 | return; |
| 459 | } |
| 460 | |
| 461 | lv_obj_clean(dir_entry_list); |
| 462 | |
| 463 | current_start_index = start_index; |
| 464 | |
| 465 | state->withEntries([this, is_root](const std::vector<dirent>& entries) { |
| 466 | size_t total_entries = entries.size(); |
| 467 | if (current_start_index >= total_entries) { |
| 468 | current_start_index = (total_entries > MAX_BATCH) |
| 469 | ? (total_entries - MAX_BATCH) |
| 470 | : 0; |
| 471 | } |
| 472 | size_t count = 0; |
| 473 | |
| 474 | if (!is_root && current_start_index > 0) { |
| 475 | auto* back_btn = lv_list_add_btn(dir_entry_list, LV_SYMBOL_LEFT, "Back"); |
| 476 | lv_obj_add_event_cb(back_btn, [](lv_event_t* event) { |
| 477 | auto* view = static_cast<View*>(lv_event_get_user_data(event)); |
| 478 | size_t new_index = (view->current_start_index >= view->MAX_BATCH) ? |
| 479 | view->current_start_index - view->MAX_BATCH : 0; |
| 480 | view->update(new_index); }, LV_EVENT_SHORT_CLICKED, this); |
| 481 | } |
| 482 | |
| 483 | for (size_t i = current_start_index; i < total_entries; ++i) { |
| 484 | auto entry = entries[i]; |
| 485 | |
| 486 | createDirEntryWidget(dir_entry_list, entry); |
| 487 | count++; |
| 488 | |
| 489 | if (count >= MAX_BATCH) { |
| 490 | break; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | last_loaded_index = std::min(current_start_index + count, total_entries); |
| 495 | |
| 496 | if (!is_root && last_loaded_index < total_entries) { |
| 497 | if (total_entries > current_start_index && |
| 498 | (total_entries - current_start_index) > MAX_BATCH) { |
| 499 | auto* next_btn = lv_list_add_btn(dir_entry_list, LV_SYMBOL_RIGHT, "Next"); |
| 500 | lv_obj_add_event_cb(next_btn, [](lv_event_t* event) { |
| 501 | auto* view = static_cast<View*>(lv_event_get_user_data(event)); |
| 502 | view->update(view->last_loaded_index); }, LV_EVENT_SHORT_CLICKED, this); |
| 503 | } |
| 504 | } else { |
| 505 | last_loaded_index = total_entries; |
| 506 | } |
| 507 | }); |
| 508 | |
| 509 | if (is_root) { |
nothing calls this directly
no test coverage detected