[FL-2565] Archive: switch to browser worker #1295
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include "assets_icons.h"
|
||||
#include "toolbox/path.h"
|
||||
#include <furi.h>
|
||||
#include "../archive_i.h"
|
||||
#include "archive_browser_view.h"
|
||||
@@ -26,7 +28,7 @@ static const Icon* ArchiveItemIcons[] = {
|
||||
[ArchiveFileTypeUpdateManifest] = &I_update_10px,
|
||||
[ArchiveFileTypeFolder] = &I_dir_10px,
|
||||
[ArchiveFileTypeUnknown] = &I_unknown_10px,
|
||||
[ArchiveFileTypeLoading] = &I_unknown_10px, // TODO loading icon
|
||||
[ArchiveFileTypeLoading] = &I_loading_10px,
|
||||
};
|
||||
|
||||
void archive_browser_set_callback(
|
||||
@@ -100,6 +102,22 @@ static void archive_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar, boo
|
||||
canvas_draw_dot(canvas, scrollbar ? 121 : 126, (15 + idx * FRAME_HEIGHT) + 11);
|
||||
}
|
||||
|
||||
static void archive_draw_loading(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
furi_assert(model);
|
||||
|
||||
uint8_t width = 49;
|
||||
uint8_t height = 47;
|
||||
uint8_t x = 128 / 2 - width / 2;
|
||||
uint8_t y = 64 / 2 - height / 2 + 6;
|
||||
|
||||
elements_bold_rounded_frame(canvas, x, y, width, height);
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_multiline_text(canvas, x + 7, y + 13, "Loading...");
|
||||
|
||||
canvas_draw_icon(canvas, x + 13, y + 19, &A_Loading_24);
|
||||
}
|
||||
|
||||
static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
furi_assert(model);
|
||||
|
||||
@@ -107,8 +125,8 @@ static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
bool scrollbar = model->item_cnt > 4;
|
||||
|
||||
for(uint32_t i = 0; i < MIN(model->item_cnt, MENU_ITEMS); ++i) {
|
||||
string_t str_buff;
|
||||
char cstr_buff[MAX_NAME_LEN];
|
||||
string_t str_buf;
|
||||
string_init(str_buf);
|
||||
int32_t idx = CLAMP((uint32_t)(i + model->list_offset), model->item_cnt, 0u);
|
||||
uint8_t x_offset = (model->move_fav && model->item_idx == idx) ? MOVE_OFFSET : 0;
|
||||
|
||||
@@ -117,16 +135,14 @@ static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
if(archive_is_item_in_array(model, idx)) {
|
||||
ArchiveFile_t* file = files_array_get(
|
||||
model->files, CLAMP(idx - model->array_offset, (int32_t)(array_size - 1), 0));
|
||||
strlcpy(cstr_buff, string_get_cstr(file->name), string_size(file->name) + 1);
|
||||
archive_trim_file_path(cstr_buff, archive_is_known_app(file->type));
|
||||
string_init_set_str(str_buff, cstr_buff);
|
||||
path_extract_filename(file->path, str_buf, archive_is_known_app(file->type));
|
||||
file_type = file->type;
|
||||
} else {
|
||||
string_init_set_str(str_buff, "---");
|
||||
string_set_str(str_buf, "---");
|
||||
}
|
||||
|
||||
elements_string_fit_width(
|
||||
canvas, str_buff, (scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX) - x_offset);
|
||||
canvas, str_buf, (scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX) - x_offset);
|
||||
|
||||
if(model->item_idx == idx) {
|
||||
archive_draw_frame(canvas, i, scrollbar, model->move_fav);
|
||||
@@ -135,9 +151,9 @@ static void draw_list(Canvas* canvas, ArchiveBrowserViewModel* model) {
|
||||
}
|
||||
|
||||
canvas_draw_icon(canvas, 2 + x_offset, 16 + i * FRAME_HEIGHT, ArchiveItemIcons[file_type]);
|
||||
canvas_draw_str(canvas, 15 + x_offset, 24 + i * FRAME_HEIGHT, string_get_cstr(str_buff));
|
||||
canvas_draw_str(canvas, 15 + x_offset, 24 + i * FRAME_HEIGHT, string_get_cstr(str_buf));
|
||||
|
||||
string_clear(str_buff);
|
||||
string_clear(str_buf);
|
||||
}
|
||||
|
||||
if(scrollbar) {
|
||||
@@ -190,7 +206,9 @@ void archive_view_render(Canvas* canvas, void* mdl) {
|
||||
|
||||
archive_render_status_bar(canvas, mdl);
|
||||
|
||||
if(model->item_cnt > 0) {
|
||||
if(model->folder_loading) {
|
||||
archive_draw_loading(canvas, model);
|
||||
} else if(model->item_cnt > 0) {
|
||||
draw_list(canvas, model);
|
||||
} else {
|
||||
canvas_draw_str_aligned(
|
||||
@@ -350,25 +368,31 @@ ArchiveBrowserView* browser_alloc() {
|
||||
view_set_draw_callback(browser->view, archive_view_render);
|
||||
view_set_input_callback(browser->view, archive_view_input);
|
||||
|
||||
string_init(browser->path);
|
||||
string_init_set_str(browser->path, archive_get_default_path(TAB_DEFAULT));
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_init(model->files);
|
||||
idx_last_array_init(model->idx_last);
|
||||
model->tab_idx = TAB_DEFAULT;
|
||||
return true;
|
||||
});
|
||||
|
||||
browser->worker = file_browser_worker_alloc(browser->path, "*", false);
|
||||
archive_file_browser_set_callbacks(browser);
|
||||
|
||||
file_browser_worker_set_callback_context(browser->worker, browser);
|
||||
|
||||
return browser;
|
||||
}
|
||||
|
||||
void browser_free(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
file_browser_worker_free(browser->worker);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_clear(model->files);
|
||||
idx_last_array_clear(model->idx_last);
|
||||
return false;
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user