mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
File Browser Ordering prototype
This commit is contained in:
@@ -64,7 +64,13 @@ static void
|
||||
archive_add_file_item(browser, is_folder, furi_string_get_cstr(item_path));
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, ArchiveBrowserViewModel * model, { model->list_loading = false; }, true);
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
files_array_special_sort(model->files, ArchiveFile_t_cmp);
|
||||
model->list_loading = false;
|
||||
},
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,13 +76,29 @@ static void ArchiveFile_t_clear(ArchiveFile_t* obj) {
|
||||
furi_string_free(obj->custom_name);
|
||||
}
|
||||
|
||||
static int ArchiveFile_t_cmp(const ArchiveFile_t* a, const ArchiveFile_t* b) {
|
||||
if(a->type == ArchiveFileTypeFolder && b->type != ArchiveFileTypeFolder) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return string_cmp(a->path, b->path);
|
||||
}
|
||||
|
||||
static void ArchiveFile_t_swap(ArchiveFile_t* a, ArchiveFile_t* b) {
|
||||
ArchiveFile_t tmp = *a;
|
||||
*a = *b;
|
||||
*b = tmp;
|
||||
}
|
||||
|
||||
ARRAY_DEF(
|
||||
files_array,
|
||||
ArchiveFile_t,
|
||||
(INIT(API_2(ArchiveFile_t_init)),
|
||||
SET(API_6(ArchiveFile_t_set)),
|
||||
INIT_SET(API_6(ArchiveFile_t_init_set)),
|
||||
CLEAR(API_2(ArchiveFile_t_clear))))
|
||||
CLEAR(API_2(ArchiveFile_t_clear)),
|
||||
CMP(API_6(ArchiveFile_t_cmp)),
|
||||
SWAP(API_6(ArchiveFile_t_swap))))
|
||||
|
||||
void archive_set_file_type(ArchiveFile_t* file, const char* path, bool is_folder, bool is_app);
|
||||
bool archive_get_items(void* context, const char* path);
|
||||
|
||||
@@ -71,13 +71,26 @@ static void BrowserItem_t_clear(BrowserItem_t* obj) {
|
||||
}
|
||||
}
|
||||
|
||||
static int BrowserItem_t_cmp(const BrowserItem_t* a, const BrowserItem_t* b) {
|
||||
// Back indicator comes before everything, then folders, then all other files.
|
||||
if((a->type == BrowserItemTypeBack) ||
|
||||
(a->type == BrowserItemTypeFolder && b->type != BrowserItemTypeFolder &&
|
||||
b->type != BrowserItemTypeBack)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return string_cmp(a->path, b->path);
|
||||
}
|
||||
|
||||
ARRAY_DEF(
|
||||
items_array,
|
||||
BrowserItem_t,
|
||||
(INIT(API_2(BrowserItem_t_init)),
|
||||
SET(API_6(BrowserItem_t_set)),
|
||||
INIT_SET(API_6(BrowserItem_t_init_set)),
|
||||
CLEAR(API_2(BrowserItem_t_clear))))
|
||||
CLEAR(API_2(BrowserItem_t_clear)),
|
||||
CMP(API_6(BrowserItem_t_cmp)),
|
||||
SWAP(M_SWAP_DEFAULT)))
|
||||
|
||||
struct FileBrowser {
|
||||
View* view;
|
||||
@@ -388,7 +401,13 @@ static void
|
||||
}
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, FileBrowserModel * model, { model->list_loading = false; }, true);
|
||||
browser->view,
|
||||
FileBrowserModel * model,
|
||||
{
|
||||
items_array_special_sort(model->items, BrowserItem_t_cmp);
|
||||
model->list_loading = false;
|
||||
},
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user