nfc_magic_scene_gen1_save_name.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "../nfc_magic_app_i.h"
  2. #include "furi.h"
  3. #include <toolbox/name_generator.h>
  4. void nfc_magic_scene_gen1_save_name_text_input_done_callback(void* context) {
  5. NfcMagicApp* instance = context;
  6. view_dispatcher_send_custom_event(instance->view_dispatcher, NfcMagicCustomEventTextInputDone);
  7. }
  8. void nfc_magic_scene_gen1_save_name_on_enter(void* context) {
  9. NfcMagicApp* instance = context;
  10. FuriString* folder_path = furi_string_alloc();
  11. TextInput* text_input = instance->text_input;
  12. furi_string_set(instance->file_path, NFC_APP_FOLDER);
  13. name_generator_make_auto(
  14. instance->text_store, NFC_MAGIC_APP_TEXT_STORE_SIZE, NFC_MAGIC_APP_FILENAME_PREFIX);
  15. furi_string_set(folder_path, NFC_APP_FOLDER);
  16. text_input_set_header_text(text_input, "Name the card");
  17. text_input_set_result_callback(
  18. text_input,
  19. nfc_magic_scene_gen1_save_name_text_input_done_callback,
  20. instance,
  21. instance->text_store,
  22. NFC_MAGIC_APP_NAME_SIZE,
  23. false);
  24. ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
  25. furi_string_get_cstr(folder_path),
  26. NFC_APP_EXTENSION,
  27. furi_string_get_cstr(instance->file_name));
  28. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  29. furi_string_free(folder_path);
  30. view_dispatcher_switch_to_view(instance->view_dispatcher, NfcMagicAppViewTextInput);
  31. }
  32. bool nfc_magic_scene_gen1_save_name_on_event(void* context, SceneManagerEvent event) {
  33. NfcMagicApp* instance = context;
  34. bool consumed = false;
  35. if(event.type == SceneManagerEventTypeCustom) {
  36. if(event.event == NfcMagicCustomEventTextInputDone) {
  37. furi_string_set(instance->file_name, instance->text_store);
  38. furi_string_cat_printf(
  39. instance->file_path,
  40. "/%s%s",
  41. furi_string_get_cstr(instance->file_name),
  42. NFC_APP_EXTENSION);
  43. if(nfc_device_save(instance->source_dev, furi_string_get_cstr(instance->file_path))) {
  44. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneSuccess);
  45. dolphin_deed(DolphinDeedNfcSave);
  46. } else {
  47. consumed = scene_manager_search_and_switch_to_previous_scene(
  48. instance->scene_manager, NfcMagicSceneStart);
  49. }
  50. }
  51. }
  52. return consumed;
  53. }
  54. void nfc_magic_scene_gen1_save_name_on_exit(void* context) {
  55. NfcMagicApp* instance = context;
  56. void* validator_context = text_input_get_validator_callback_context(instance->text_input);
  57. text_input_set_validator(instance->text_input, NULL, NULL);
  58. validator_is_file_free(validator_context);
  59. text_input_reset(instance->text_input);
  60. }