nfc_maker_scene_save_name.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. furi_string_set(prefix, nfc_device_get_name(app->nfc_device, NfcDeviceNameTypeFull));
  15. furi_string_replace(prefix, "Mifare", "MF");
  16. furi_string_replace(prefix, " Classic", "C"); // MFC
  17. furi_string_replace(prefix, "Desfire", "Des"); // MF Des
  18. furi_string_replace(prefix, "Ultralight", "UL"); // MF UL
  19. furi_string_replace(prefix, " Plus", "+"); // NTAG I2C+
  20. furi_string_replace(prefix, " (Unknown)", "");
  21. furi_string_replace_all(prefix, " ", "_");
  22. name_generator_make_auto(app->save_buf, sizeof(app->save_buf), furi_string_get_cstr(prefix));
  23. furi_string_free(prefix);
  24. text_input_set_result_callback(
  25. text_input,
  26. nfc_maker_scene_save_name_text_input_callback,
  27. app,
  28. app->save_buf,
  29. sizeof(app->save_buf),
  30. true);
  31. ValidatorIsFile* validator_is_file =
  32. validator_is_file_alloc_init(NFC_APP_FOLDER, NFC_APP_EXTENSION, NULL);
  33. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  34. view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
  35. }
  36. bool nfc_maker_scene_save_name_on_event(void* context, SceneManagerEvent event) {
  37. NfcMaker* app = context;
  38. bool consumed = false;
  39. if(event.type == SceneManagerEventTypeCustom) {
  40. consumed = true;
  41. switch(event.event) {
  42. case TextInputResultOk:
  43. scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveResult);
  44. break;
  45. default:
  46. break;
  47. }
  48. }
  49. return consumed;
  50. }
  51. void nfc_maker_scene_save_name_on_exit(void* context) {
  52. NfcMaker* app = context;
  53. text_input_reset(app->text_input);
  54. }