mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-11 06:09:08 -07:00
Re-merge the file browser changes properly
This commit is contained in:
@@ -70,6 +70,7 @@ 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,
|
||||
@@ -96,10 +97,19 @@ static void archive_list_item_cb(
|
||||
model->item_idx = 0;
|
||||
}
|
||||
}
|
||||
model->list_loading = false;
|
||||
if(archive_is_file_list_load_required(model)) {
|
||||
model->list_loading = true;
|
||||
load_again = true;
|
||||
} else {
|
||||
model->list_loading = false;
|
||||
}
|
||||
},
|
||||
true);
|
||||
archive_update_offset(browser);
|
||||
if(load_again) {
|
||||
archive_file_array_load(browser, 0);
|
||||
} else {
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +155,26 @@ 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);
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ 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);
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "archive_browser_view.h"
|
||||
#include "../helpers/archive_browser.h"
|
||||
|
||||
#define TAG "Archive"
|
||||
#define SCROLL_INTERVAL (333)
|
||||
#define SCROLL_DELAY (2)
|
||||
|
||||
@@ -334,24 +333,10 @@ View* archive_browser_get_view(ArchiveBrowserView* browser) {
|
||||
return browser->view;
|
||||
}
|
||||
|
||||
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;
|
||||
static void file_list_rollover(ArchiveBrowserViewModel* model) {
|
||||
if(!model->list_loading && files_array_size(model->files) < model->item_cnt) {
|
||||
files_array_reset(model->files);
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -437,25 +422,19 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
} else {
|
||||
scroll_speed = model->button_held_for_ticks > 9 ? 4 : 2;
|
||||
}
|
||||
} else if(model->button_held_for_ticks < 0) {
|
||||
scroll_speed = 0;
|
||||
}
|
||||
|
||||
if(event->key == InputKeyUp) {
|
||||
if(model->item_idx < scroll_speed) {
|
||||
scroll_speed = model->item_idx;
|
||||
if(scroll_speed == 0) {
|
||||
if(model->button_held_for_ticks > 0) {
|
||||
model->button_held_for_ticks = -1;
|
||||
} else {
|
||||
scroll_speed = 1;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
model->item_idx =
|
||||
((model->item_idx - scroll_speed) + 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;
|
||||
browser->callback(ArchiveBrowserEventLoadPrevItems, browser->context);
|
||||
}
|
||||
@@ -463,26 +442,17 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
browser->callback(ArchiveBrowserEventFavMoveUp, browser->context);
|
||||
}
|
||||
model->scroll_counter = 0;
|
||||
|
||||
if(model->button_held_for_ticks < -1) {
|
||||
model->button_held_for_ticks = 0;
|
||||
}
|
||||
model->button_held_for_ticks += 1;
|
||||
} else if(event->key == InputKeyDown) {
|
||||
int32_t count = model->item_cnt;
|
||||
if(model->item_idx >= (count - scroll_speed)) {
|
||||
scroll_speed = model->item_cnt - model->item_idx - 1;
|
||||
if(scroll_speed == 0) {
|
||||
if(model->button_held_for_ticks > 0) {
|
||||
model->button_held_for_ticks = -1;
|
||||
} else {
|
||||
scroll_speed = 1;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
browser->callback(ArchiveBrowserEventLoadNextItems, browser->context);
|
||||
}
|
||||
@@ -490,10 +460,6 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
browser->callback(ArchiveBrowserEventFavMoveDown, browser->context);
|
||||
}
|
||||
model->scroll_counter = 0;
|
||||
|
||||
if(model->button_held_for_ticks < -1) {
|
||||
model->button_held_for_ticks = 0;
|
||||
}
|
||||
model->button_held_for_ticks += 1;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -115,7 +115,7 @@ typedef struct {
|
||||
int32_t list_offset;
|
||||
size_t scroll_counter;
|
||||
|
||||
int32_t button_held_for_ticks;
|
||||
uint32_t button_held_for_ticks;
|
||||
} ArchiveBrowserViewModel;
|
||||
|
||||
void archive_browser_set_callback(
|
||||
|
||||
@@ -144,7 +144,7 @@ typedef struct {
|
||||
bool hide_ext;
|
||||
size_t scroll_counter;
|
||||
|
||||
int32_t button_held_for_ticks;
|
||||
uint32_t button_held_for_ticks;
|
||||
} FileBrowserModel;
|
||||
|
||||
static const Icon* BrowserItemIcons[] = {
|
||||
@@ -332,6 +332,12 @@ 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);
|
||||
|
||||
@@ -354,7 +360,7 @@ static void browser_update_offset(FileBrowser* browser) {
|
||||
CLAMP(model->item_idx - 1, (int32_t)model->item_cnt - bounds, 0);
|
||||
}
|
||||
},
|
||||
true);
|
||||
false);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -459,20 +465,23 @@ 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);
|
||||
// TODO: calculate if element is visible
|
||||
},
|
||||
false);
|
||||
{ items_array_push_back(model->items, item); },
|
||||
instant_update);
|
||||
|
||||
furi_string_free(item.display_name);
|
||||
furi_string_free(item.path);
|
||||
if(item.custom_icon_data) {
|
||||
free(item.custom_icon_data);
|
||||
}
|
||||
} else {
|
||||
bool load_again = false;
|
||||
int32_t load_offset = 0;
|
||||
with_view_model(
|
||||
browser->view,
|
||||
FileBrowserModel * model,
|
||||
@@ -495,10 +504,21 @@ static void browser_list_item_cb(
|
||||
}
|
||||
}
|
||||
}
|
||||
model->list_loading = false;
|
||||
if(browser_is_list_load_required(model)) {
|
||||
model->list_loading = true;
|
||||
load_again = true;
|
||||
load_offset = CLAMP(
|
||||
model->item_idx - ITEM_LIST_LEN_MAX / 2, (int32_t)model->item_cnt, 0);
|
||||
} else {
|
||||
model->list_loading = false;
|
||||
}
|
||||
},
|
||||
false);
|
||||
browser_update_offset(browser);
|
||||
if(load_again) {
|
||||
file_browser_worker_load(browser->worker, load_offset, ITEM_LIST_LEN_MAX);
|
||||
} else {
|
||||
browser_update_offset(browser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -665,24 +685,19 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
|
||||
} else {
|
||||
scroll_speed = model->button_held_for_ticks > 9 ? 5 : 3;
|
||||
}
|
||||
} else if(model->button_held_for_ticks < 0) {
|
||||
scroll_speed = 0;
|
||||
}
|
||||
|
||||
if(event->key == InputKeyUp) {
|
||||
if(model->item_idx < scroll_speed) {
|
||||
scroll_speed = model->item_idx;
|
||||
if(scroll_speed == 0) {
|
||||
if(model->button_held_for_ticks > 0) {
|
||||
model->button_held_for_ticks = -1;
|
||||
} else {
|
||||
scroll_speed = 1;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -694,24 +709,16 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
|
||||
}
|
||||
model->scroll_counter = 0;
|
||||
|
||||
if(model->button_held_for_ticks < -1) {
|
||||
model->button_held_for_ticks = 0;
|
||||
}
|
||||
model->button_held_for_ticks += 1;
|
||||
} else if(event->key == InputKeyDown) {
|
||||
int32_t count = model->item_cnt;
|
||||
if(model->item_idx + scroll_speed >= count) {
|
||||
scroll_speed = count - model->item_idx - 1;
|
||||
if(scroll_speed == 0) {
|
||||
if(model->button_held_for_ticks > 0) {
|
||||
model->button_held_for_ticks = -1;
|
||||
} else {
|
||||
scroll_speed = 1;
|
||||
}
|
||||
}
|
||||
if(model->item_idx + scroll_speed >= (int32_t)model->item_cnt) {
|
||||
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;
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -723,9 +730,6 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
|
||||
}
|
||||
model->scroll_counter = 0;
|
||||
|
||||
if(model->button_held_for_ticks < -1) {
|
||||
model->button_held_for_ticks = 0;
|
||||
}
|
||||
model->button_held_for_ticks += 1;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user