[FL-3383, FL-3413] Archive and file browser fixes (#2862)
* File browser: flickering and reload fixes * The same for archive browser
This commit is contained in:
parent
a4b4802897
commit
92c0baa461
@ -64,8 +64,20 @@ static void
|
|||||||
if(!is_last) {
|
if(!is_last) {
|
||||||
archive_add_file_item(browser, is_folder, furi_string_get_cstr(item_path));
|
archive_add_file_item(browser, is_folder, furi_string_get_cstr(item_path));
|
||||||
} else {
|
} else {
|
||||||
|
bool load_again = false;
|
||||||
with_view_model(
|
with_view_model(
|
||||||
browser->view, ArchiveBrowserViewModel * model, { model->list_loading = false; }, true);
|
browser->view,
|
||||||
|
ArchiveBrowserViewModel * model,
|
||||||
|
{
|
||||||
|
model->list_loading = false;
|
||||||
|
if(archive_is_file_list_load_required(model)) {
|
||||||
|
load_again = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
if(load_again) {
|
||||||
|
archive_file_array_load(browser, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +123,26 @@ bool archive_is_item_in_array(ArchiveBrowserViewModel* model, uint32_t idx) {
|
|||||||
return true;
|
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) {
|
void archive_update_offset(ArchiveBrowserView* browser) {
|
||||||
furi_assert(browser);
|
furi_assert(browser);
|
||||||
|
|
||||||
|
|||||||
@ -64,6 +64,7 @@ inline bool archive_is_known_app(ArchiveFileTypeEnum type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool archive_is_item_in_array(ArchiveBrowserViewModel* model, uint32_t idx);
|
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_offset(ArchiveBrowserView* browser);
|
||||||
void archive_update_focus(ArchiveBrowserView* browser, const char* target);
|
void archive_update_focus(ArchiveBrowserView* browser, const char* target);
|
||||||
|
|
||||||
|
|||||||
@ -248,24 +248,10 @@ View* archive_browser_get_view(ArchiveBrowserView* browser) {
|
|||||||
return browser->view;
|
return browser->view;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_file_list_load_required(ArchiveBrowserViewModel* model) {
|
static void file_list_rollover(ArchiveBrowserViewModel* model) {
|
||||||
size_t array_size = files_array_size(model->files);
|
if(!model->list_loading && files_array_size(model->files) < model->item_cnt) {
|
||||||
|
files_array_reset(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) {
|
static bool archive_view_input(InputEvent* event, void* context) {
|
||||||
@ -347,12 +333,13 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
|||||||
if(model->item_idx < scroll_speed) {
|
if(model->item_idx < scroll_speed) {
|
||||||
model->button_held_for_ticks = 0;
|
model->button_held_for_ticks = 0;
|
||||||
model->item_idx = model->item_cnt - 1;
|
model->item_idx = model->item_cnt - 1;
|
||||||
|
file_list_rollover(model);
|
||||||
} else {
|
} else {
|
||||||
model->item_idx =
|
model->item_idx =
|
||||||
((model->item_idx - scroll_speed) + model->item_cnt) %
|
((model->item_idx - scroll_speed) + model->item_cnt) %
|
||||||
model->item_cnt;
|
model->item_cnt;
|
||||||
}
|
}
|
||||||
if(is_file_list_load_required(model)) {
|
if(archive_is_file_list_load_required(model)) {
|
||||||
model->list_loading = true;
|
model->list_loading = true;
|
||||||
browser->callback(ArchiveBrowserEventLoadPrevItems, browser->context);
|
browser->callback(ArchiveBrowserEventLoadPrevItems, browser->context);
|
||||||
}
|
}
|
||||||
@ -366,10 +353,11 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
|||||||
if(model->item_idx + scroll_speed >= count) {
|
if(model->item_idx + scroll_speed >= count) {
|
||||||
model->button_held_for_ticks = 0;
|
model->button_held_for_ticks = 0;
|
||||||
model->item_idx = 0;
|
model->item_idx = 0;
|
||||||
|
file_list_rollover(model);
|
||||||
} else {
|
} else {
|
||||||
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
|
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
|
||||||
}
|
}
|
||||||
if(is_file_list_load_required(model)) {
|
if(archive_is_file_list_load_required(model)) {
|
||||||
model->list_loading = true;
|
model->list_loading = true;
|
||||||
browser->callback(ArchiveBrowserEventLoadNextItems, browser->context);
|
browser->callback(ArchiveBrowserEventLoadNextItems, browser->context);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -303,6 +303,12 @@ static bool browser_is_list_load_required(FileBrowserModel* model) {
|
|||||||
return false;
|
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) {
|
static void browser_update_offset(FileBrowser* browser) {
|
||||||
furi_assert(browser);
|
furi_assert(browser);
|
||||||
|
|
||||||
@ -385,7 +391,7 @@ static void browser_list_load_cb(void* context, uint32_t list_load_offset) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true);
|
false);
|
||||||
|
|
||||||
BrowserItem_t_clear(&back_item);
|
BrowserItem_t_clear(&back_item);
|
||||||
}
|
}
|
||||||
@ -425,14 +431,15 @@ static void
|
|||||||
(browser->hide_ext) && (item.type == BrowserItemTypeFile));
|
(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(
|
with_view_model(
|
||||||
browser->view,
|
browser->view,
|
||||||
FileBrowserModel * model,
|
FileBrowserModel * model,
|
||||||
{
|
{ items_array_push_back(model->items, item); },
|
||||||
items_array_push_back(model->items, item);
|
instant_update);
|
||||||
// TODO: calculate if element is visible
|
|
||||||
},
|
|
||||||
true);
|
|
||||||
furi_string_free(item.display_name);
|
furi_string_free(item.display_name);
|
||||||
furi_string_free(item.path);
|
furi_string_free(item.path);
|
||||||
if(item.custom_icon_data) {
|
if(item.custom_icon_data) {
|
||||||
@ -440,7 +447,18 @@ static void
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
with_view_model(
|
with_view_model(
|
||||||
browser->view, FileBrowserModel * model, { model->list_loading = false; }, true);
|
browser->view,
|
||||||
|
FileBrowserModel * model,
|
||||||
|
{
|
||||||
|
model->list_loading = false;
|
||||||
|
if(browser_is_list_load_required(model)) {
|
||||||
|
model->list_loading = true;
|
||||||
|
int32_t load_offset = CLAMP(
|
||||||
|
model->item_idx - ITEM_LIST_LEN_MAX / 2, (int32_t)model->item_cnt, 0);
|
||||||
|
file_browser_worker_load(browser->worker, load_offset, ITEM_LIST_LEN_MAX);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,11 +622,13 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
|
|||||||
if(model->item_idx < scroll_speed) {
|
if(model->item_idx < scroll_speed) {
|
||||||
model->button_held_for_ticks = 0;
|
model->button_held_for_ticks = 0;
|
||||||
model->item_idx = model->item_cnt - 1;
|
model->item_idx = model->item_cnt - 1;
|
||||||
|
browser_list_rollover(model);
|
||||||
} else {
|
} else {
|
||||||
model->item_idx =
|
model->item_idx =
|
||||||
((model->item_idx - scroll_speed) + model->item_cnt) %
|
((model->item_idx - scroll_speed) + model->item_cnt) %
|
||||||
model->item_cnt;
|
model->item_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(browser_is_list_load_required(model)) {
|
if(browser_is_list_load_required(model)) {
|
||||||
model->list_loading = true;
|
model->list_loading = true;
|
||||||
int32_t load_offset = CLAMP(
|
int32_t load_offset = CLAMP(
|
||||||
@ -622,13 +642,14 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
|
|||||||
|
|
||||||
model->button_held_for_ticks += 1;
|
model->button_held_for_ticks += 1;
|
||||||
} else if(event->key == InputKeyDown) {
|
} else if(event->key == InputKeyDown) {
|
||||||
int32_t count = model->item_cnt;
|
if(model->item_idx + scroll_speed >= (int32_t)model->item_cnt) {
|
||||||
if(model->item_idx + scroll_speed >= count) {
|
|
||||||
model->button_held_for_ticks = 0;
|
model->button_held_for_ticks = 0;
|
||||||
model->item_idx = 0;
|
model->item_idx = 0;
|
||||||
|
browser_list_rollover(model);
|
||||||
} else {
|
} else {
|
||||||
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
|
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(browser_is_list_load_required(model)) {
|
if(browser_is_list_load_required(model)) {
|
||||||
model->list_loading = true;
|
model->list_loading = true;
|
||||||
int32_t load_offset = CLAMP(
|
int32_t load_offset = CLAMP(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user