nfc_maker_scene_save_name.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "../nfc_maker.h"
  2. enum TextInputResult {
  3. TextInputResultOk,
  4. };
  5. static void nfc_maker_scene_save_name_text_input_callback(void* context) {
  6. NfcMaker* app = context;
  7. view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
  8. }
  9. void nfc_maker_scene_save_name_on_enter(void* context) {
  10. NfcMaker* app = context;
  11. TextInput* text_input = app->text_input;
  12. text_input_set_header_text(text_input, "Save the NFC tag:");
  13. FuriString* prefix = furi_string_alloc();
  14. nfc_device_get_abbreviated_name(app->nfc_device, prefix);
  15. furi_string_replace_all(prefix, " ", "_");
  16. name_generator_make_auto(app->save_buf, BIG_INPUT_LEN, furi_string_get_cstr(prefix));
  17. furi_string_free(prefix);
  18. text_input_set_result_callback(
  19. text_input,
  20. nfc_maker_scene_save_name_text_input_callback,
  21. app,
  22. app->save_buf,
  23. BIG_INPUT_LEN,
  24. true);
  25. ValidatorIsFile* validator_is_file =
  26. validator_is_file_alloc_init(NFC_APP_FOLDER, NFC_APP_EXTENSION, NULL);
  27. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  28. view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
  29. }
  30. bool nfc_maker_scene_save_name_on_event(void* context, SceneManagerEvent event) {
  31. NfcMaker* app = context;
  32. bool consumed = false;
  33. if(event.type == SceneManagerEventTypeCustom) {
  34. consumed = true;
  35. switch(event.event) {
  36. case TextInputResultOk:
  37. scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveResult);
  38. break;
  39. default:
  40. break;
  41. }
  42. }
  43. return consumed;
  44. }
  45. void nfc_maker_scene_save_name_on_exit(void* context) {
  46. NfcMaker* app = context;
  47. text_input_reset(app->text_input);
  48. }