From 8915c0c66c7747967262f732793f57f2821e3aaa Mon Sep 17 00:00:00 2001 From: Der Skythe Date: Fri, 16 Sep 2022 03:16:46 +0400 Subject: [PATCH] Fix bugs with new model --- applications/main/archive/archive.c | 49 +++++++++++++++++++ applications/main/archive/archive_i.h | 6 +++ .../main/archive/scenes/archive_scene_info.c | 2 +- .../archive/scenes/archive_scene_rename.c | 4 +- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/applications/main/archive/archive.c b/applications/main/archive/archive.c index 2ac2bf0f6..a74e28ca7 100644 --- a/applications/main/archive/archive.c +++ b/applications/main/archive/archive.c @@ -1,5 +1,29 @@ #include "archive_i.h" +static const NotificationSequence sequence_blink_set_yellow = { + &message_blink_set_color_yellow, + NULL, +}; + +static const NotificationSequence sequence_blink_set_magenta = { + &message_blink_set_color_magenta, + NULL, +}; + +static const NotificationSequence* archive_notification_sequences[] = { + &sequence_error, + &sequence_success, + &sequence_blink_start_cyan, + &sequence_blink_start_magenta, + &sequence_blink_set_yellow, + &sequence_blink_set_magenta, + &sequence_set_red_255, + &sequence_reset_red, + &sequence_set_green_255, + &sequence_reset_green, + &sequence_blink_stop, +}; + static bool archive_custom_event_callback(void* context, uint32_t event) { furi_assert(context); ArchiveApp* archive = context; @@ -27,6 +51,7 @@ static ArchiveApp* archive_alloc() { archive->view_dispatcher = view_dispatcher_alloc(); archive->gui = furi_record_open(RECORD_GUI); + archive->notifications = furi_record_open(RECORD_NOTIFICATION); ViewDispatcher* view_dispatcher = archive->view_dispatcher; view_dispatcher_enable_queue(view_dispatcher); @@ -73,6 +98,9 @@ void archive_free(ArchiveApp* archive) { view_dispatcher_remove_view(view_dispatcher, ArchiveViewWidget); widget_free(archive->widget); + view_dispatcher_remove_view(view_dispatcher, ArchiveViewStack); + view_stack_free(archive->view_stack); + view_dispatcher_remove_view(view_dispatcher, ArchiveViewBrowser); view_dispatcher_free(archive->view_dispatcher); @@ -81,6 +109,9 @@ void archive_free(ArchiveApp* archive) { browser_free(archive->browser); string_clear(archive->fav_move_str); + furi_record_close(RECORD_NOTIFICATION); + archive->notifications = NULL; + furi_record_close(RECORD_DIALOGS); archive->dialogs = NULL; @@ -106,6 +137,24 @@ void archive_show_loading_popup(ArchiveApp* context, bool show) { } } +void archive_text_store_set(ArchiveApp* context, const char* text, ...) { + va_list args; + va_start(args, text); + + vsnprintf(context->text_store, MAX_NAME_LEN, text, args); + + va_end(args); +} + +void archive_text_store_clear(ArchiveApp* context) { + memset(context->text_store, 0, MAX_NAME_LEN); +} + +void archive_notification_message(ArchiveApp* context, uint32_t message) { + furi_assert(message < sizeof(archive_notification_sequences) / sizeof(NotificationSequence*)); + notification_message(context->notifications, archive_notification_sequences[message]); +} + int32_t archive_app(void* p) { UNUSED(p); diff --git a/applications/main/archive/archive_i.h b/applications/main/archive/archive_i.h index 0c5b337e6..c72f746c4 100644 --- a/applications/main/archive/archive_i.h +++ b/applications/main/archive/archive_i.h @@ -23,6 +23,7 @@ typedef enum { ArchiveViewTotal, ArchiveViewLoading, ArchiveViewStack, + ArchiveViewDialogEx, } ArchiveViewEnum; struct ArchiveApp { @@ -35,6 +36,8 @@ struct ArchiveApp { Widget* widget; DialogsApp* dialogs; Loading* loading; + NotificationApp* notifications; + FuriPubSubSubscription* loader_stop_subscription; string_t fav_move_str; @@ -42,4 +45,7 @@ struct ArchiveApp { char file_extension[MAX_EXT_LEN + 1]; }; +void archive_text_store_set(iButton* ibutton, const char* text, ...); +void archive_text_store_clear(iButton* ibutton); +void archive_notification_message(iButton* ibutton, uint32_t message); void archive_show_loading_popup(ArchiveApp* context, bool show); \ No newline at end of file diff --git a/applications/main/archive/scenes/archive_scene_info.c b/applications/main/archive/scenes/archive_scene_info.c index b6fae4bca..705557377 100644 --- a/applications/main/archive/scenes/archive_scene_info.c +++ b/applications/main/archive/scenes/archive_scene_info.c @@ -64,7 +64,7 @@ void archive_scene_info_on_enter(void* context) { // This one to return and cursor select this file path_extract_filename_no_ext(string_get_cstr(current->path), filename); - strlcpy(instance->text_store, string_get_cstr(filename), MAX_NAME_LEN); + archive_text_store_set(instance, instance->text_store); string_clear(filename); string_clear(dirname); diff --git a/applications/main/archive/scenes/archive_scene_rename.c b/applications/main/archive/scenes/archive_scene_rename.c index ca15ee88e..4128cb7c0 100644 --- a/applications/main/archive/scenes/archive_scene_rename.c +++ b/applications/main/archive/scenes/archive_scene_rename.c @@ -27,11 +27,11 @@ void archive_scene_rename_on_enter(void* context) { if(current->type == ArchiveFileTypeFolder) { path_extract_basename(string_get_cstr(current->path), path_name); - strlcpy(archive->text_store, string_get_cstr(path_name), MAX_NAME_LEN); + archive_text_store_set(archive, string_get_cstr(path_name)); text_input_set_header_text(text_input, "Rename directory:"); } else /*if(current->type != ArchiveFileTypeUnknown) */ { path_extract_filename(current->path, path_name, true); - strlcpy(archive->text_store, string_get_cstr(path_name), MAX_NAME_LEN); + archive_text_store_set(archive, string_get_cstr(path_name)); path_extract_extension(current->path, archive->file_extension, MAX_EXT_LEN); text_input_set_header_text(text_input, "Rename file:");