[FL-2565] Archive: switch to browser worker #1295
This commit is contained in:
@@ -4,9 +4,13 @@
|
||||
#include "../helpers/archive_favorites.h"
|
||||
#include "../helpers/archive_browser.h"
|
||||
#include "../views/archive_browser_view.h"
|
||||
#include "archive/scenes/archive_scene.h"
|
||||
|
||||
#define TAG "ArchiveSceneBrowser"
|
||||
|
||||
#define SCENE_STATE_DEFAULT (0)
|
||||
#define SCENE_STATE_NEED_REFRESH (1)
|
||||
|
||||
static const char* flipper_app_name[] = {
|
||||
[ArchiveFileTypeIButton] = "iButton",
|
||||
[ArchiveFileTypeNFC] = "NFC",
|
||||
@@ -26,7 +30,7 @@ static void archive_loader_callback(const void* message, void* context) {
|
||||
|
||||
if(event->type == LoaderEventTypeApplicationStopped) {
|
||||
view_dispatcher_send_custom_event(
|
||||
archive->view_dispatcher, ArchiveBrowserEventLoaderAppExit);
|
||||
archive->view_dispatcher, ArchiveBrowserEventListRefresh);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,14 +40,14 @@ static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selec
|
||||
|
||||
LoaderStatus status;
|
||||
if(selected->is_app) {
|
||||
char* param = strrchr(string_get_cstr(selected->name), '/');
|
||||
char* param = strrchr(string_get_cstr(selected->path), '/');
|
||||
if(param != NULL) {
|
||||
param++;
|
||||
}
|
||||
status = loader_start(loader, flipper_app_name[selected->type], param);
|
||||
} else {
|
||||
status = loader_start(
|
||||
loader, flipper_app_name[selected->type], string_get_cstr(selected->name));
|
||||
loader, flipper_app_name[selected->type], string_get_cstr(selected->path));
|
||||
}
|
||||
|
||||
if(status != LoaderStatusOk) {
|
||||
@@ -61,6 +65,7 @@ void archive_scene_browser_callback(ArchiveBrowserEvent event, void* context) {
|
||||
void archive_scene_browser_on_enter(void* context) {
|
||||
ArchiveApp* archive = (ArchiveApp*)context;
|
||||
ArchiveBrowserView* browser = archive->browser;
|
||||
browser->is_root = true;
|
||||
|
||||
archive_browser_set_callback(browser, archive_scene_browser_callback, archive);
|
||||
archive_update_focus(browser, archive->text_store);
|
||||
@@ -70,6 +75,16 @@ void archive_scene_browser_on_enter(void* context) {
|
||||
archive->loader_stop_subscription =
|
||||
furi_pubsub_subscribe(loader_get_pubsub(loader), archive_loader_callback, archive);
|
||||
furi_record_close("loader");
|
||||
|
||||
uint32_t state = scene_manager_get_scene_state(archive->scene_manager, ArchiveAppSceneBrowser);
|
||||
|
||||
if(state == SCENE_STATE_NEED_REFRESH) {
|
||||
view_dispatcher_send_custom_event(
|
||||
archive->view_dispatcher, ArchiveBrowserEventListRefresh);
|
||||
}
|
||||
|
||||
scene_manager_set_scene_state(
|
||||
archive->scene_manager, ArchiveAppSceneBrowser, SCENE_STATE_DEFAULT);
|
||||
}
|
||||
|
||||
bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
@@ -95,8 +110,8 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
case ArchiveBrowserEventFileMenuRun:
|
||||
if(known_app) {
|
||||
archive_run_in_app(browser, selected);
|
||||
archive_show_file_menu(browser, false);
|
||||
}
|
||||
archive_show_file_menu(browser, false);
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventFileMenuPin:
|
||||
@@ -115,11 +130,13 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case ArchiveBrowserEventFileMenuAction:
|
||||
case ArchiveBrowserEventFileMenuRename:
|
||||
if(favorites) {
|
||||
browser->callback(ArchiveBrowserEventEnterFavMove, browser->context);
|
||||
} else if((known_app) && (selected->is_app == false)) {
|
||||
archive_show_file_menu(browser, false);
|
||||
scene_manager_set_scene_state(
|
||||
archive->scene_manager, ArchiveAppSceneBrowser, SCENE_STATE_NEED_REFRESH);
|
||||
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneRename);
|
||||
}
|
||||
consumed = true;
|
||||
@@ -131,7 +148,7 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventEnterDir:
|
||||
archive_enter_dir(browser, selected->name);
|
||||
archive_enter_dir(browser, selected->path);
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventFavMoveUp:
|
||||
@@ -143,13 +160,13 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventEnterFavMove:
|
||||
strlcpy(archive->text_store, archive_get_name(browser), MAX_NAME_LEN);
|
||||
string_set(archive->fav_move_str, selected->path);
|
||||
archive_show_file_menu(browser, false);
|
||||
archive_favorites_move_mode(archive->browser, true);
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventExitFavMove:
|
||||
archive_update_focus(browser, archive->text_store);
|
||||
archive_update_focus(browser, string_get_cstr(archive->fav_move_str));
|
||||
archive_favorites_move_mode(archive->browser, false);
|
||||
consumed = true;
|
||||
break;
|
||||
@@ -166,18 +183,17 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
archive_file_array_load(archive->browser, 1);
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventLoaderAppExit:
|
||||
case ArchiveBrowserEventListRefresh:
|
||||
if(!favorites) {
|
||||
archive_enter_dir(browser, browser->path);
|
||||
archive_refresh_dir(browser);
|
||||
} else {
|
||||
archive_favorites_read(browser);
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case ArchiveBrowserEventExit:
|
||||
if(archive_get_depth(browser)) {
|
||||
if(!archive_is_home(browser)) {
|
||||
archive_leave_dir(browser);
|
||||
} else {
|
||||
Loader* loader = furi_record_open("loader");
|
||||
|
@@ -3,6 +3,8 @@
|
||||
#include "../helpers/archive_files.h"
|
||||
#include "../helpers/archive_apps.h"
|
||||
#include "../helpers/archive_browser.h"
|
||||
#include "toolbox/path.h"
|
||||
#include "m-string.h"
|
||||
|
||||
#define SCENE_DELETE_CUSTOM_EVENT (0UL)
|
||||
#define MAX_TEXT_INPUT_LEN 22
|
||||
@@ -24,18 +26,19 @@ void archive_scene_delete_on_enter(void* context) {
|
||||
widget_add_button_element(
|
||||
app->widget, GuiButtonTypeRight, "Delete", archive_scene_delete_widget_callback, app);
|
||||
|
||||
string_t filename;
|
||||
string_init(filename);
|
||||
|
||||
ArchiveFile_t* current = archive_get_current_file(app->browser);
|
||||
strlcpy(app->text_store, string_get_cstr(current->name), MAX_NAME_LEN);
|
||||
char* name = strrchr(app->text_store, '/');
|
||||
if(name != NULL) {
|
||||
name++;
|
||||
}
|
||||
path_extract_filename(current->path, filename, false);
|
||||
|
||||
char delete_str[64];
|
||||
snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", name);
|
||||
snprintf(delete_str, sizeof(delete_str), "\e#Delete %s?\e#", string_get_cstr(filename));
|
||||
widget_add_text_box_element(
|
||||
app->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, delete_str, false);
|
||||
|
||||
string_clear(filename);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, ArchiveViewWidget);
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,8 @@
|
||||
#include "../helpers/archive_favorites.h"
|
||||
#include "../helpers/archive_files.h"
|
||||
#include "../helpers/archive_browser.h"
|
||||
#include "archive/views/archive_browser_view.h"
|
||||
#include "toolbox/path.h"
|
||||
|
||||
#define SCENE_RENAME_CUSTOM_EVENT (0UL)
|
||||
#define MAX_TEXT_INPUT_LEN 22
|
||||
@@ -16,10 +18,13 @@ void archive_scene_rename_on_enter(void* context) {
|
||||
|
||||
TextInput* text_input = archive->text_input;
|
||||
ArchiveFile_t* current = archive_get_current_file(archive->browser);
|
||||
strlcpy(archive->text_store, string_get_cstr(current->name), MAX_NAME_LEN);
|
||||
|
||||
archive_get_file_extension(archive->text_store, archive->file_extension);
|
||||
archive_trim_file_path(archive->text_store, true);
|
||||
string_t filename;
|
||||
string_init(filename);
|
||||
path_extract_filename(current->path, filename, true);
|
||||
strlcpy(archive->text_store, string_get_cstr(filename), MAX_NAME_LEN);
|
||||
|
||||
path_extract_extension(current->path, archive->file_extension, MAX_EXT_LEN);
|
||||
|
||||
text_input_set_header_text(text_input, "Rename:");
|
||||
|
||||
@@ -32,9 +37,11 @@ void archive_scene_rename_on_enter(void* context) {
|
||||
false);
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
archive_get_path(archive->browser), archive->file_extension, NULL);
|
||||
string_get_cstr(archive->browser->path), archive->file_extension, NULL);
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
string_clear(filename);
|
||||
|
||||
view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput);
|
||||
}
|
||||
|
||||
@@ -46,30 +53,22 @@ bool archive_scene_rename_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.event == SCENE_RENAME_CUSTOM_EVENT) {
|
||||
Storage* fs_api = furi_record_open("storage");
|
||||
|
||||
string_t buffer_src;
|
||||
string_t buffer_dst;
|
||||
|
||||
const char* path = archive_get_path(archive->browser);
|
||||
const char* name = archive_get_name(archive->browser);
|
||||
|
||||
string_init_printf(buffer_src, "%s", name);
|
||||
//TODO: take path from src name
|
||||
string_init_printf(buffer_dst, "%s/%s", path, archive->text_store);
|
||||
|
||||
// append extension
|
||||
const char* path_src = archive_get_name(archive->browser);
|
||||
ArchiveFile_t* file = archive_get_current_file(archive->browser);
|
||||
|
||||
string_cat(buffer_dst, known_ext[file->type]);
|
||||
storage_common_rename(
|
||||
fs_api, string_get_cstr(buffer_src), string_get_cstr(buffer_dst));
|
||||
string_t path_dst;
|
||||
string_init(path_dst);
|
||||
path_extract_dirname(path_src, path_dst);
|
||||
string_cat_printf(path_dst, "/%s%s", archive->text_store, known_ext[file->type]);
|
||||
|
||||
storage_common_rename(fs_api, path_src, string_get_cstr(path_dst));
|
||||
furi_record_close("storage");
|
||||
|
||||
if(file->fav) {
|
||||
archive_favorites_rename(name, string_get_cstr(buffer_dst));
|
||||
archive_favorites_rename(path_src, string_get_cstr(path_dst));
|
||||
}
|
||||
|
||||
string_clear(buffer_src);
|
||||
string_clear(buffer_dst);
|
||||
string_clear(path_dst);
|
||||
|
||||
scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneBrowser);
|
||||
consumed = true;
|
||||
|
Reference in New Issue
Block a user