revert archive fixes temporarily

This commit is contained in:
MX
2023-07-14 04:40:22 +03:00
parent dd26ec22c3
commit 523f522de0
4 changed files with 28 additions and 54 deletions

View File

@@ -70,23 +70,16 @@ static void archive_list_item_cb(
if(!is_last) {
archive_add_file_item(browser, is_folder, furi_string_get_cstr(item_path));
} else {
bool load_again = false;
with_view_model(
browser->view,
ArchiveBrowserViewModel * model,
{
model->list_loading = false;
if(model->item_cnt <= BROWSER_SORT_THRESHOLD) {
files_array_sort(model->files);
}
if(archive_is_file_list_load_required(model)) {
load_again = true;
}
model->list_loading = false;
},
true);
if(load_again) {
archive_file_array_load(browser, 0);
}
}
}
@@ -132,26 +125,6 @@ bool archive_is_item_in_array(ArchiveBrowserViewModel* model, uint32_t idx) {
return true;
}
bool archive_is_file_list_load_required(ArchiveBrowserViewModel* model) {
size_t array_size = files_array_size(model->files);
if((model->list_loading) || (array_size >= model->item_cnt)) {
return false;
}
if((model->array_offset > 0) &&
(model->item_idx < (model->array_offset + FILE_LIST_BUF_LEN / 4))) {
return true;
}
if(((model->array_offset + array_size) < model->item_cnt) &&
(model->item_idx > (int32_t)(model->array_offset + array_size - FILE_LIST_BUF_LEN / 4))) {
return true;
}
return false;
}
void archive_update_offset(ArchiveBrowserView* browser) {
furi_assert(browser);

View File

@@ -66,7 +66,6 @@ inline bool archive_is_known_app(ArchiveFileTypeEnum type) {
}
bool archive_is_item_in_array(ArchiveBrowserViewModel* model, uint32_t idx);
bool archive_is_file_list_load_required(ArchiveBrowserViewModel* model);
void archive_update_offset(ArchiveBrowserView* browser);
void archive_update_focus(ArchiveBrowserView* browser, const char* target);

View File

@@ -370,10 +370,24 @@ View* archive_browser_get_view(ArchiveBrowserView* browser) {
return browser->view;
}
static void file_list_rollover(ArchiveBrowserViewModel* model) {
if(!model->list_loading && files_array_size(model->files) < model->item_cnt) {
files_array_reset(model->files);
static bool is_file_list_load_required(ArchiveBrowserViewModel* model) {
size_t array_size = files_array_size(model->files);
if((model->list_loading) || (array_size >= model->item_cnt)) {
return false;
}
if((model->array_offset > 0) &&
(model->item_idx < (model->array_offset + FILE_LIST_BUF_LEN / 4))) {
return true;
}
if(((model->array_offset + array_size) < model->item_cnt) &&
(model->item_idx > (int32_t)(model->array_offset + array_size - FILE_LIST_BUF_LEN / 4))) {
return true;
}
return false;
}
static bool archive_view_input(InputEvent* event, void* context) {
@@ -463,13 +477,12 @@ static bool archive_view_input(InputEvent* event, void* context) {
if(model->item_idx < scroll_speed) {
model->button_held_for_ticks = 0;
model->item_idx = model->item_cnt - 1;
file_list_rollover(model);
} else {
model->item_idx =
((model->item_idx - scroll_speed) + model->item_cnt) %
model->item_cnt;
}
if(archive_is_file_list_load_required(model)) {
if(is_file_list_load_required(model)) {
model->list_loading = true;
browser->callback(ArchiveBrowserEventLoadPrevItems, browser->context);
}
@@ -483,11 +496,10 @@ static bool archive_view_input(InputEvent* event, void* context) {
if(model->item_idx + scroll_speed >= count) {
model->button_held_for_ticks = 0;
model->item_idx = 0;
file_list_rollover(model);
} else {
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
}
if(archive_is_file_list_load_required(model)) {
if(is_file_list_load_required(model)) {
model->list_loading = true;
browser->callback(ArchiveBrowserEventLoadNextItems, browser->context);
}

View File

@@ -335,12 +335,6 @@ static bool browser_is_list_load_required(FileBrowserModel* model) {
return false;
}
static void browser_list_rollover(FileBrowserModel* model) {
if(!model->list_loading && items_array_size(model->items) < model->item_cnt) {
items_array_reset(model->items);
}
}
static void browser_update_offset(FileBrowser* browser) {
furi_assert(browser);
@@ -423,7 +417,7 @@ static void browser_list_load_cb(void* context, uint32_t list_load_offset) {
}
}
},
false);
true);
BrowserItem_t_clear(&back_item);
}
@@ -468,15 +462,14 @@ static void browser_list_item_cb(
(browser->hide_ext) && (item.type == BrowserItemTypeFile));
}
// We shouldn't update screen on each item if custom callback is not set
// Otherwise it will cause screen flickering
bool instant_update = (browser->item_callback != NULL);
with_view_model(
browser->view,
FileBrowserModel * model,
{ items_array_push_back(model->items, item); },
instant_update);
{
items_array_push_back(model->items, item);
// TODO: calculate if element is visible
},
false);
furi_string_free(item.display_name);
furi_string_free(item.path);
if(item.custom_icon_data) {
@@ -689,13 +682,11 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
if(model->item_idx < scroll_speed) {
model->button_held_for_ticks = 0;
model->item_idx = model->item_cnt - 1;
browser_list_rollover(model);
} else {
model->item_idx =
((model->item_idx - scroll_speed) + model->item_cnt) %
model->item_cnt;
}
if(browser_is_list_load_required(model)) {
model->list_loading = true;
int32_t load_offset = CLAMP(
@@ -709,14 +700,13 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
model->button_held_for_ticks += 1;
} else if(event->key == InputKeyDown) {
if(model->item_idx + scroll_speed >= (int32_t)model->item_cnt) {
int32_t count = model->item_cnt;
if(model->item_idx + scroll_speed >= count) {
model->button_held_for_ticks = 0;
model->item_idx = 0;
browser_list_rollover(model);
} else {
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
}
if(browser_is_list_load_required(model)) {
model->list_loading = true;
int32_t load_offset = CLAMP(