From 5c8557f396fe8e402409c00ceb6a682b13369b46 Mon Sep 17 00:00:00 2001 From: Zachary Weiss Date: Tue, 27 Dec 2022 17:12:22 -0500 Subject: [PATCH] Remove unused file, name input boilerplate --- README.md | 2 +- mag.h | 0 scenes/mag_scene_save_name.c | 78 +++++++++++++++++++++++++++++++++--- 3 files changed, 74 insertions(+), 6 deletions(-) delete mode 100644 mag.h diff --git a/README.md b/README.md index 967b0773156..50efd3f3f1c 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,4 @@ Other misc things to investigate / build: - Precomputing bit output, and then sending ("RedSpoof" by devBioS does this, as they say they had timing issues when computing the bits live) - Reverse-track emulate? - Tuning of parameters like pre-signal zeros? -- "Interpacket delay" like the RedSpoof implementation? \ No newline at end of file +- "Interpacket delay" like the RedSpoof implementation? diff --git a/mag.h b/mag.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/scenes/mag_scene_save_name.c b/scenes/mag_scene_save_name.c index 70fc6a82b56..36f6c79cd7e 100644 --- a/scenes/mag_scene_save_name.c +++ b/scenes/mag_scene_save_name.c @@ -1,20 +1,88 @@ +#include #include "../mag_i.h" void mag_scene_save_name_on_enter(void* context) { Mag* mag = context; - UNUSED(mag); + TextInput* text_input = mag->text_input; + FuriString* folder_path; + folder_path = furi_string_alloc(); + + bool key_name_is_empty = furi_string_empty(mag->file_name); + + if(key_name_is_empty) { + furi_string_set(mag->file_path, MAG_APP_FOLDER); + set_random_name(mag->text_store, MAG_TEXT_STORE_SIZE); + furi_string_set(folder_path, MAG_APP_FOLDER); + } else { + mag_text_store_set(mag, "%s", furi_string_get_cstr(mag->file_name)); + path_extract_dirname(furi_string_get_cstr(mag->file_path), folder_path); + } + + text_input_set_header_text(text_input, "Name the card"); + text_input_set_result_callback( + text_input, + mag_text_input_callback, + mag, + mag->text_store, + MAG_KEY_NAME_SIZE, + key_name_is_empty); + + FURI_LOG_I("", "%s %s", furi_string_get_cstr(folder_path), mag->text_store); + + ValidatorIsFile* validator_is_file = validator_is_file_alloc_init( + furi_string_get_cstr(folder_path), + MAG_APP_EXTENSION, + furi_string_get_cstr(mag->file_name)); + text_input_set_validator(text_input, validator_is_file_callback, validator_is_file); + + furi_string_free(folder_path); + + view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewTextInput); } bool mag_scene_save_name_on_event(void* context, SceneManagerEvent event) { Mag* mag = context; - UNUSED(mag); - UNUSED(event); + SceneManager* scene_manager = mag->scene_manager; bool consumed = false; + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == MagEventNext) { + consumed = true; + if(!furi_string_empty(mag->file_name)) { + mag_delete_key(mag); + } + + furi_string_set(mag->file_name, mag->text_store); + + if(mag_save_key(mag)) { + scene_manager_next_scene(scene_manager, MagSceneSaveSuccess); + if(scene_manager_has_previous_scene(scene_manager, MagSceneSavedKeyMenu)) { + // Nothing, do not count editing as saving + //} else if(scene_manager_has_previous_scene(scene_manager, MagSceneSaveType)) { + //DOLPHIN_DEED(DolphinDeedRfidAdd); + // TODO: replace dolphin deed! + } else { + //DOLPHIN_DEED(DolphinDeedRfidSave); + // TODO: replace dolphin deed! + } + } else { + //scene_manager_search_and_switch_to_previous_scene( + // scene_manager, MagSceneReadKeyMenu); + // TODO: Replace with appropriate scene! No read scene prior if adding manually... + } + } + } + return consumed; } void mag_scene_save_name_on_exit(void* context) { Mag* mag = context; - UNUSED(mag); -} \ No newline at end of file + TextInput* text_input = mag->text_input; + + void* validator_context = text_input_get_validator_callback_context(text_input); + text_input_set_validator(text_input, NULL, NULL); + validator_is_file_free((ValidatorIsFile*)validator_context); + + text_input_reset(text_input); +}