Fix file browser back history

This commit is contained in:
Willy-JL 2023-02-12 11:15:11 +00:00
parent 80b8a0dddb
commit 82f77edc70
4 changed files with 26 additions and 9 deletions

View file

@ -58,8 +58,9 @@ static void archive_list_load_cb(void* context, uint32_t list_load_offset) {
}
static void
archive_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
archive_list_item_cb(void* context, FuriString* item_path, uint32_t idx, bool is_folder, bool is_last) {
furi_assert(context);
UNUSED(idx);
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
if(!is_last) {

View file

@ -34,6 +34,7 @@ typedef enum {
} BrowserItemType;
typedef struct {
uint32_t unsorted_idx;
FuriString* path;
BrowserItemType type;
uint8_t* custom_icon_data;
@ -41,6 +42,7 @@ typedef struct {
} BrowserItem_t;
static void BrowserItem_t_init(BrowserItem_t* obj) {
obj->unsorted_idx = 0;
obj->type = BrowserItemTypeLoading;
obj->path = furi_string_alloc();
obj->display_name = furi_string_alloc();
@ -48,6 +50,7 @@ static void BrowserItem_t_init(BrowserItem_t* obj) {
}
static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src) {
obj->unsorted_idx = src->unsorted_idx;
obj->type = src->type;
obj->path = furi_string_alloc_set(src->path);
obj->display_name = furi_string_alloc_set(src->display_name);
@ -60,6 +63,7 @@ static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src)
}
static void BrowserItem_t_set(BrowserItem_t* obj, const BrowserItem_t* src) {
obj->unsorted_idx = src->unsorted_idx;
obj->type = src->type;
furi_string_set(obj->path, src->path);
furi_string_set(obj->display_name, src->display_name);
@ -158,7 +162,7 @@ static void
browser_folder_open_cb(void* context, uint32_t item_cnt, int32_t file_idx, bool is_root);
static void browser_list_load_cb(void* context, uint32_t list_load_offset);
static void
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last);
browser_list_item_cb(void* context, FuriString* item_path, uint32_t idx, bool is_folder, bool is_last);
static void browser_long_load_cb(void* context);
static void file_browser_scroll_timer_callback(void* context) {
@ -413,12 +417,13 @@ static void browser_list_load_cb(void* context, uint32_t list_load_offset) {
}
static void
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
browser_list_item_cb(void* context, FuriString* item_path, uint32_t idx, bool is_folder, bool is_last) {
furi_assert(context);
FileBrowser* browser = (FileBrowser*)context;
BrowserItem_t item;
item.custom_icon_data = NULL;
item.unsorted_idx = idx;
if(!is_last) {
item.path = furi_string_alloc_set(item_path);
@ -465,10 +470,23 @@ static void
browser->view,
FileBrowserModel * model,
{
FuriString* selected = NULL;
if(model->item_idx > 0) {
selected = furi_string_alloc_set(items_array_get(model->items, model->item_idx)->path);
}
items_array_sort(model->items);
if(selected) {
for(uint32_t i = 0; i < model->item_cnt; i++) {
if(!furi_string_cmp(items_array_get(model->items, i)->path, selected)) {
model->item_idx = i;
break;
}
}
}
model->list_loading = false;
},
true);
browser_update_offset(browser);
}
}
@ -667,10 +685,7 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
if(browser_is_item_in_array(model, model->item_idx)) {
selected_item =
items_array_get(model->items, model->item_idx - model->array_offset);
select_index = model->item_idx;
if((!model->is_root) && (select_index > 0)) {
select_index -= 1;
}
select_index = selected_item->unsorted_idx;
}
},
false);

View file

@ -247,13 +247,13 @@ static bool
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
if(browser->list_item_cb) {
browser->list_item_cb(
browser->cb_ctx, name_str, (file_info.flags & FSF_DIRECTORY), false);
browser->cb_ctx, name_str, items_cnt, (file_info.flags & FSF_DIRECTORY), false);
}
items_cnt++;
}
}
if(browser->list_item_cb) {
browser->list_item_cb(browser->cb_ctx, NULL, false, true);
browser->list_item_cb(browser->cb_ctx, NULL, 0, false, true);
}
ret = true;
} while(0);

View file

@ -17,6 +17,7 @@ typedef void (*BrowserWorkerListLoadCallback)(void* context, uint32_t list_load_
typedef void (*BrowserWorkerListItemCallback)(
void* context,
FuriString* item_path,
uint32_t idx,
bool is_folder,
bool is_last);
typedef void (*BrowserWorkerLongLoadCallback)(void* context);