diff --git a/application.fam b/application.fam index 899db4de8d4..ed955cb2cdb 100644 --- a/application.fam +++ b/application.fam @@ -8,7 +8,7 @@ App( fap_category="NFC", fap_author="@acegoal07", fap_weburl="https://github.com/acegoal07/FlipperZero_NFC_Playlist/tree/main", - fap_version="1.4", + fap_version="1.6", fap_icon="assets/icon.png", fap_private_libs=[ Lib( diff --git a/nfc_playlist.c b/nfc_playlist.c index a2f43e046f2..d3df5a9589b 100644 --- a/nfc_playlist.c +++ b/nfc_playlist.c @@ -7,7 +7,8 @@ static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = { nfc_playlist_emulation_scene_on_enter, nfc_playlist_file_select_scene_on_enter, nfc_playlist_file_edit_scene_on_enter, - nfc_playlist_text_input_scene_on_enter + nfc_playlist_file_rename_scene_on_enter, + nfc_playlist_confirm_delete_scene_on_enter }; static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = { @@ -16,7 +17,8 @@ static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerE nfc_playlist_emulation_scene_on_event, nfc_playlist_file_select_scene_on_event, nfc_playlist_file_edit_scene_on_event, - nfc_playlist_text_input_scene_on_event + nfc_playlist_file_rename_scene_on_event, + nfc_playlist_confirm_delete_scene_on_event }; static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = { @@ -25,7 +27,8 @@ static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = { nfc_playlist_emulation_scene_on_exit, nfc_playlist_file_select_scene_on_exit, nfc_playlist_file_edit_scene_on_exit, - nfc_playlist_text_input_scene_on_exit + nfc_playlist_file_rename_scene_on_exit, + nfc_playlist_confirm_delete_scene_on_exit }; static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = { @@ -55,6 +58,7 @@ static NfcPlaylist* nfc_playlist_alloc() { view_dispatcher_enable_queue(nfc_playlist->view_dispatcher); nfc_playlist->variable_item_list = variable_item_list_alloc(); nfc_playlist->submenu = submenu_alloc(); + nfc_playlist->widget= widget_alloc(); nfc_playlist->settings.base_file_path = furi_string_alloc_set_str("/ext/apps_data/nfc_playlist/"); nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path; @@ -77,7 +81,8 @@ static NfcPlaylist* nfc_playlist_alloc() { view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(nfc_playlist->popup)); view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect, file_browser_get_view(nfc_playlist->file_browser)); view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit, submenu_get_view(nfc_playlist->submenu)); - view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput, text_input_get_view(nfc_playlist->text_input)); + view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename, text_input_get_view(nfc_playlist->text_input)); + view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete, widget_get_view(nfc_playlist->widget)); Storage* storage = furi_record_open(RECORD_STORAGE); if (!storage_common_exists(storage, "/ext/apps_data/nfc_playlist")) { @@ -90,20 +95,26 @@ static NfcPlaylist* nfc_playlist_alloc() { static void nfc_playlist_free(NfcPlaylist* nfc_playlist) { furi_assert(nfc_playlist); - scene_manager_free(nfc_playlist->scene_manager); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu); view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings); view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup); view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileSelect); view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit); - view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename); + view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete); + + scene_manager_free(nfc_playlist->scene_manager); view_dispatcher_free(nfc_playlist->view_dispatcher); variable_item_list_free(nfc_playlist->variable_item_list); submenu_free(nfc_playlist->submenu); + widget_free(nfc_playlist->widget); + + furi_record_close(RECORD_NOTIFICATION); file_browser_free(nfc_playlist->file_browser); text_input_free(nfc_playlist->text_input); popup_free(nfc_playlist->popup); - furi_record_close(RECORD_NOTIFICATION); + furi_string_free(nfc_playlist->settings.base_file_path); furi_string_free(nfc_playlist->settings.file_path); free(nfc_playlist->playlist_name); diff --git a/nfc_playlist.h b/nfc_playlist.h index 79da11448c2..a5a86acaa26 100644 --- a/nfc_playlist.h +++ b/nfc_playlist.h @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include @@ -20,7 +22,8 @@ typedef enum { NfcPlaylistView_Popup, NfcPlaylistView_FileSelect, NfcPlaylistView_FileEdit, - NfcPlaylistView_TextInput + NfcPlaylistView_FileRename, + NfcPlaylistView_ConfirmDelete } NfcPlayScenesView; typedef enum { @@ -29,7 +32,8 @@ typedef enum { NfcPlaylistScene_EmulatingPopup, NfcPlaylistScene_FileSelect, NfcPlaylistScene_FileEdit, - NfcPlaylistScene_TextInput, + NfcPlaylistScene_FileRename, + NfcPlaylistScene_ConfirmDelete, NfcPlaylistScene_count } NfcPlaylistScene; @@ -51,6 +55,7 @@ typedef struct { TextInput* text_input; Submenu* submenu; Popup* popup; + Widget* widget; NotificationApp* notification; FuriThread* thread; NfcPlaylistWorker* nfc_playlist_worker; diff --git a/nfc_playlist_i.h b/nfc_playlist_i.h index c2a156906cc..42749ad0010 100644 --- a/nfc_playlist_i.h +++ b/nfc_playlist_i.h @@ -4,4 +4,5 @@ #include "scences/emulation.h" #include "scences/file_select.h" #include "scences/file_edit.h" -#include "scences/text_input.h" \ No newline at end of file +#include "scences/file_rename.h" +#include "scences/confirm_delete.h" \ No newline at end of file diff --git a/scences/confirm_delete.c b/scences/confirm_delete.c new file mode 100644 index 00000000000..90890c59ed5 --- /dev/null +++ b/scences/confirm_delete.c @@ -0,0 +1,51 @@ +#include "nfc_playlist.h" +#include "scences/confirm_delete.h" + +void nfc_playlist_confirm_delete_menu_callback(GuiButtonType result, InputType type, void* context) { + NfcPlaylist* nfc_playlist = context; + if(type == InputTypeShort) { + view_dispatcher_send_custom_event(nfc_playlist->view_dispatcher, result); + } +} + +void nfc_playlist_confirm_delete_scene_on_enter(void* context) { + NfcPlaylist* nfc_playlist = context; + + FuriString* temp_str = furi_string_alloc(); + char* file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path); + furi_string_printf(temp_str, "\e#Delete %s?\e#", strchr(file_path, '/') != NULL ? &strrchr(file_path, '/')[1] : file_path); + + widget_add_text_box_element(nfc_playlist->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(temp_str), false); + widget_add_button_element(nfc_playlist->widget, GuiButtonTypeLeft, "Cancel", nfc_playlist_confirm_delete_menu_callback, nfc_playlist); + widget_add_button_element(nfc_playlist->widget, GuiButtonTypeRight, "Delete", nfc_playlist_confirm_delete_menu_callback, nfc_playlist); + + furi_string_free(temp_str); + + view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete); +} + +bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent event) { + NfcPlaylist* nfc_playlist = context; + bool consumed = false; + Storage* storage = furi_record_open(RECORD_STORAGE); + if(event.type == SceneManagerEventTypeCustom) { + switch(event.event) { + case GuiButtonTypeRight: { + storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.file_path)); + nfc_playlist->settings.file_selected = false; + nfc_playlist->settings.file_selected_check = false; + nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path; + break; + } + default: + break; + } + scene_manager_previous_scene(nfc_playlist->scene_manager); + } + return consumed; +} + +void nfc_playlist_confirm_delete_scene_on_exit(void* context) { + NfcPlaylist* nfc_playlist = context; + widget_reset(nfc_playlist->widget); +} \ No newline at end of file diff --git a/scences/confirm_delete.h b/scences/confirm_delete.h new file mode 100644 index 00000000000..6a990db97f2 --- /dev/null +++ b/scences/confirm_delete.h @@ -0,0 +1,10 @@ +#pragma once +#include +#include +#include +#include +#include + +void nfc_playlist_confirm_delete_scene_on_enter(void* context); +bool nfc_playlist_confirm_delete_scene_on_event(void* context, SceneManagerEvent event); +void nfc_playlist_confirm_delete_scene_on_exit(void* context); \ No newline at end of file diff --git a/scences/emulation.c b/scences/emulation.c index d9914e97f96..d61d006cbcf 100644 --- a/scences/emulation.c +++ b/scences/emulation.c @@ -56,6 +56,8 @@ int32_t nfc_playlist_emulation_task(void* context) { Storage* storage = furi_record_open(RECORD_STORAGE); Stream* stream = file_stream_alloc(storage); FuriString* line = furi_string_alloc(); + FuriString* temp_header_str = furi_string_alloc(); + FuriString* temp_counter_str = furi_string_alloc(); popup_reset(nfc_playlist->popup); popup_set_context(nfc_playlist->popup, nfc_playlist); @@ -75,9 +77,8 @@ int32_t nfc_playlist_emulation_task(void* context) { start_blink(nfc_playlist, NfcPlaylistLedState_Error); int time_counter_delay_ms = (options_emulate_delay[nfc_playlist->settings.emulate_delay]*1000); do { - char display_text[10]; - snprintf(display_text, 10, "%ds", (time_counter_delay_ms/1000)); - popup_set_text(nfc_playlist->popup, display_text, 64, 50, AlignCenter, AlignTop); + furi_string_printf(temp_counter_str, "%ds", (time_counter_delay_ms/1000)); + popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop); furi_delay_ms(50); time_counter_delay_ms -= 50; } while(time_counter_delay_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); @@ -92,43 +93,34 @@ int32_t nfc_playlist_emulation_task(void* context) { int time_counter_ms = (options_emulate_timeout[nfc_playlist->settings.emulate_timeout]*1000); if (storage_file_exists(storage, file_path) == false) { - int popup_header_text_size = strlen(file_name) + 18; - char popup_header_text[popup_header_text_size]; - snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR not found:", file_name); - popup_set_header(nfc_playlist->popup, popup_header_text, 64, 10, AlignCenter, AlignTop); + furi_string_printf(temp_header_str, "ERROR not found:\n %s", file_name); + popup_set_header(nfc_playlist->popup, furi_string_get_cstr(temp_header_str), 64, 10, AlignCenter, AlignTop); start_blink(nfc_playlist, NfcPlaylistLedState_Error); do { - char popup_text[10]; - snprintf(popup_text, 10, "%ds", (time_counter_ms/1000)); - popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop); + furi_string_printf(temp_counter_str, "%ds", (time_counter_ms/1000)); + popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop); furi_delay_ms(50); time_counter_ms -= 50; } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); } else if (strcasestr(file_ext, "nfc") == NULL) { - int popup_header_text_size = strlen(file_name) + 21; - char popup_header_text[popup_header_text_size]; - snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "ERROR invalid file:", file_name); - popup_set_header(nfc_playlist->popup, popup_header_text, 64, 10, AlignCenter, AlignTop); + furi_string_printf(temp_header_str, "ERROR invalid file:\n %s", file_name); + popup_set_header(nfc_playlist->popup, furi_string_get_cstr(temp_header_str), 64, 10, AlignCenter, AlignTop); start_blink(nfc_playlist, NfcPlaylistLedState_Error); do { - char popup_text[10]; - snprintf(popup_text, 10, "%ds", (time_counter_ms/1000)); - popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop); + furi_string_printf(temp_counter_str, "%ds", (time_counter_ms/1000)); + popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop); furi_delay_ms(50); time_counter_ms -= 50; } while(time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); } else { - int popup_header_text_size = strlen(file_name) + 12; - char popup_header_text[popup_header_text_size]; - snprintf(popup_header_text, popup_header_text_size, "%s\n%s", "Emulating:", file_name); - popup_set_header(nfc_playlist->popup, popup_header_text, 64, 10, AlignCenter, AlignTop); + furi_string_printf(temp_header_str, "Emulating:\n %s", file_name); + popup_set_header(nfc_playlist->popup, furi_string_get_cstr(temp_header_str), 64, 10, AlignCenter, AlignTop); nfc_playlist_worker_set_nfc_data(nfc_playlist->nfc_playlist_worker, file_path); nfc_playlist_worker_start(nfc_playlist->nfc_playlist_worker); start_blink(nfc_playlist, NfcPlaylistLedState_Normal); do { - char popup_text[10]; - snprintf(popup_text, 10, "%ds", (time_counter_ms/1000)); - popup_set_text(nfc_playlist->popup, popup_text, 64, 50, AlignCenter, AlignTop); + furi_string_printf(temp_counter_str, "%ds", (time_counter_ms/1000)); + popup_set_text(nfc_playlist->popup, furi_string_get_cstr(temp_counter_str), 64, 50, AlignCenter, AlignTop); furi_delay_ms(50); time_counter_ms -= 50; } while(nfc_playlist_worker_is_emulating(nfc_playlist->nfc_playlist_worker) && time_counter_ms > 0 && EmulationState == NfcPlaylistEmulationState_Emulating); @@ -148,6 +140,8 @@ int32_t nfc_playlist_emulation_task(void* context) { } furi_string_free(line); + furi_string_free(temp_header_str); + furi_string_free(temp_counter_str); file_stream_close(stream); furi_record_close(RECORD_STORAGE); stream_free(stream); diff --git a/scences/emulation.h b/scences/emulation.h index b2a4e507243..e99d5b6d292 100644 --- a/scences/emulation.h +++ b/scences/emulation.h @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include diff --git a/scences/file_edit.c b/scences/file_edit.c index 55f3284f787..9d43a3cb90f 100644 --- a/scences/file_edit.c +++ b/scences/file_edit.c @@ -8,30 +8,23 @@ typedef enum { void nfc_playlist_file_edit_menu_callback(void* context, uint32_t index) { NfcPlaylist* nfc_playlist = context; - Storage* storage = furi_record_open(RECORD_STORAGE); switch(index) { case NfcPlaylistMenuSelection_DeletePlaylist: { - storage_simply_remove(storage, furi_string_get_cstr(nfc_playlist->settings.file_path)); - nfc_playlist->settings.file_selected = false; - nfc_playlist->settings.file_selected_check = false; - nfc_playlist->settings.file_path = nfc_playlist->settings.base_file_path; - scene_manager_previous_scene(nfc_playlist->scene_manager); + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_ConfirmDelete); break; } case NfcPlaylistMenuSelection_RenamePlaylist: { - scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_TextInput); + scene_manager_next_scene(nfc_playlist->scene_manager, NfcPlaylistScene_FileRename); break; } - default: { + default: break; - } } - furi_record_close(RECORD_STORAGE); } void nfc_playlist_file_edit_scene_on_enter(void* context) { NfcPlaylist* nfc_playlist = context; - + submenu_set_header(nfc_playlist->submenu, "Edit Playlist"); submenu_add_lockable_item( diff --git a/scences/file_edit.h b/scences/file_edit.h index 685e9c50300..08dca0ef3ca 100644 --- a/scences/file_edit.h +++ b/scences/file_edit.h @@ -1,12 +1,8 @@ #pragma once #include -#include #include #include #include -#include -#include -#include void nfc_playlist_file_edit_scene_on_enter(void* context); bool nfc_playlist_file_edit_scene_on_event(void* context, SceneManagerEvent event); diff --git a/scences/text_input.c b/scences/file_rename.c similarity index 58% rename from scences/text_input.c rename to scences/file_rename.c index f93a6c29af3..9a42d4e672e 100644 --- a/scences/text_input.c +++ b/scences/file_rename.c @@ -1,9 +1,10 @@ #include "nfc_playlist.h" -#include "scences/text_input.h" +#include "scences/file_rename.h" -void nfc_playlist_text_input_menu_callback(void* context) { +void nfc_playlist_file_rename_menu_callback(void* context) { NfcPlaylist* nfc_playlist = context; Storage* storage = furi_record_open(RECORD_STORAGE); + FuriString* new_file_path = furi_string_alloc(); char const* old_file_path = (char*)furi_string_get_cstr(nfc_playlist->settings.file_path); char const* old_file_name = strchr(old_file_path, '/') != NULL ? &strrchr(old_file_path, '/')[1] : old_file_path; @@ -13,40 +14,36 @@ void nfc_playlist_text_input_menu_callback(void* context) { char* file_path = (char*)malloc(file_path_size); snprintf(file_path, file_path_size, "%s", old_file_path); - int new_file_path_size = (strlen(nfc_playlist->playlist_name) + strlen(".txt") + file_path_size + 1); + furi_string_printf(new_file_path, "%s%s.txt", file_path, nfc_playlist->playlist_name); - char* new_file_name = (char*)malloc(new_file_path_size); - snprintf(new_file_name, new_file_path_size, "%s%s%s", file_path, nfc_playlist->playlist_name, ".txt"); - - if (!storage_file_exists(storage, new_file_name)) { - storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), new_file_name); - nfc_playlist->settings.file_path = furi_string_alloc_set_str(new_file_name); + if (!storage_file_exists(storage, furi_string_get_cstr(new_file_path))) { + storage_common_rename_safe(storage, furi_string_get_cstr(nfc_playlist->settings.file_path), furi_string_get_cstr(new_file_path)); + nfc_playlist->settings.file_path = new_file_path; } - - free(new_file_name); free(file_path); free(nfc_playlist->playlist_name); furi_record_close(RECORD_STORAGE); + furi_string_free(new_file_path); scene_manager_previous_scene(nfc_playlist->scene_manager); } -void nfc_playlist_text_input_scene_on_enter(void* context) { +void nfc_playlist_file_rename_scene_on_enter(void* context) { NfcPlaylist* nfc_playlist = context; nfc_playlist->playlist_name = (char*)malloc(50); text_input_set_header_text(nfc_playlist->text_input, "Enter new file name"); text_input_set_minimum_length(nfc_playlist->text_input, 1); - text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_text_input_menu_callback, nfc_playlist, nfc_playlist->playlist_name, 50, true); - view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_TextInput); + text_input_set_result_callback(nfc_playlist->text_input, nfc_playlist_file_rename_menu_callback, nfc_playlist, nfc_playlist->playlist_name, 50, true); + view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename); } -bool nfc_playlist_text_input_scene_on_event(void* context, SceneManagerEvent event) { +bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent event) { UNUSED(context); UNUSED(event); return false; } -void nfc_playlist_text_input_scene_on_exit(void* context) { +void nfc_playlist_file_rename_scene_on_exit(void* context) { NfcPlaylist* nfc_playlist = context; text_input_reset(nfc_playlist->text_input); } \ No newline at end of file diff --git a/scences/file_rename.h b/scences/file_rename.h new file mode 100644 index 00000000000..b4ff8aa23e3 --- /dev/null +++ b/scences/file_rename.h @@ -0,0 +1,10 @@ +#pragma once +#include +#include +#include +#include +#include + +void nfc_playlist_file_rename_scene_on_enter(void* context); +bool nfc_playlist_file_rename_scene_on_event(void* context, SceneManagerEvent event); +void nfc_playlist_file_rename_scene_on_exit(void* context); \ No newline at end of file diff --git a/scences/file_select.h b/scences/file_select.h index c948ed35fb0..12147c73189 100644 --- a/scences/file_select.h +++ b/scences/file_select.h @@ -1,6 +1,5 @@ #pragma once #include -#include #include #include #include diff --git a/scences/main_menu.h b/scences/main_menu.h index 4fa0215024e..8644d2e16eb 100644 --- a/scences/main_menu.h +++ b/scences/main_menu.h @@ -1,6 +1,5 @@ #pragma once #include -#include #include #include #include diff --git a/scences/settings.c b/scences/settings.c index a7e337e2eb3..640beda0d16 100644 --- a/scences/settings.c +++ b/scences/settings.c @@ -10,26 +10,26 @@ typedef enum { void nfc_playlist_settings_menu_callback(void* context, uint32_t index) { NfcPlaylist* nfc_playlist = context; + FuriString* temp_str = furi_string_alloc(); if (index == NfcPlaylistSettings_Reset) { nfc_playlist->settings.emulate_timeout = default_emulate_timeout; VariableItem* emulation_timeout_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Timeout); variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout); - char emulation_timeout_settings_text[3]; - snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); - variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text); + furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); + variable_item_set_current_value_text(emulation_timeout_settings, furi_string_get_cstr(temp_str)); nfc_playlist->settings.emulate_delay = default_emulate_delay; VariableItem* emulation_delay_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Delay); variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay); - char emulation_delay_settings_text[3]; - snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); - variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text); + furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); + variable_item_set_current_value_text(emulation_delay_settings, furi_string_get_cstr(temp_str)); nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator; VariableItem* emulation_led_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_LedIndicator); variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator); variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF"); } + furi_string_free(temp_str); } void nfc_playlist_settings_options_change_callback(VariableItem* item) { @@ -37,20 +37,18 @@ void nfc_playlist_settings_options_change_callback(VariableItem* item) { uint8_t current_option = variable_item_list_get_selected_item_index(nfc_playlist->variable_item_list); uint8_t option_value_index = variable_item_get_current_value_index(item); - + FuriString* temp_str = furi_string_alloc(); switch(current_option) { case NfcPlaylistSettings_Timeout: { nfc_playlist->settings.emulate_timeout = option_value_index; - char emulate_timeout_text[3]; - snprintf(emulate_timeout_text, 3, "%ds", options_emulate_timeout[option_value_index]); - variable_item_set_current_value_text(item, (char*)emulate_timeout_text); + furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); + variable_item_set_current_value_text(item, furi_string_get_cstr(temp_str)); break; } case NfcPlaylistSettings_Delay: { nfc_playlist->settings.emulate_delay = option_value_index; - char emulate_delay_text[3]; - snprintf(emulate_delay_text, 3, "%ds", options_emulate_delay[option_value_index]); - variable_item_set_current_value_text(item, (char*)emulate_delay_text); + furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); + variable_item_set_current_value_text(item, furi_string_get_cstr(temp_str)); break; } case NfcPlaylistSettings_LedIndicator: @@ -60,10 +58,12 @@ void nfc_playlist_settings_options_change_callback(VariableItem* item) { default: break; } + furi_string_free(temp_str); } void nfc_playlist_settings_scene_on_enter(void* context) { NfcPlaylist* nfc_playlist = context; + FuriString* temp_str = furi_string_alloc(); variable_item_list_set_header(nfc_playlist->variable_item_list, "Settings"); @@ -74,9 +74,8 @@ void nfc_playlist_settings_scene_on_enter(void* context) { nfc_playlist_settings_options_change_callback, nfc_playlist); variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout); - char emulation_timeout_settings_text[3]; - snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); - variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text); + furi_string_printf(temp_str, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]); + variable_item_set_current_value_text(emulation_timeout_settings, furi_string_get_cstr(temp_str)); VariableItem* emulation_delay_settings = variable_item_list_add( nfc_playlist->variable_item_list, @@ -85,9 +84,8 @@ void nfc_playlist_settings_scene_on_enter(void* context) { nfc_playlist_settings_options_change_callback, nfc_playlist); variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay); - char emulation_delay_settings_text[3]; - snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); - variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text); + furi_string_printf(temp_str, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]); + variable_item_set_current_value_text(emulation_delay_settings, furi_string_get_cstr(temp_str)); VariableItem* emulation_led_indicator_settings = variable_item_list_add( nfc_playlist->variable_item_list, @@ -101,6 +99,8 @@ void nfc_playlist_settings_scene_on_enter(void* context) { variable_item_list_add(nfc_playlist->variable_item_list, "Reset settings", 0, NULL, NULL); variable_item_list_set_enter_callback(nfc_playlist->variable_item_list, nfc_playlist_settings_menu_callback, nfc_playlist); + + furi_string_free(temp_str); view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings); } diff --git a/scences/settings.h b/scences/settings.h index 31c93498054..2372b0b69c4 100644 --- a/scences/settings.h +++ b/scences/settings.h @@ -1,6 +1,5 @@ #pragma once #include -#include #include #include #include diff --git a/scences/text_input.h b/scences/text_input.h deleted file mode 100644 index 9acfaa90306..00000000000 --- a/scences/text_input.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include - -void nfc_playlist_text_input_scene_on_enter(void* context); -bool nfc_playlist_text_input_scene_on_event(void* context, SceneManagerEvent event); -void nfc_playlist_text_input_scene_on_exit(void* context); \ No newline at end of file