nfc_maker_scene_save.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "../nfc_maker.h"
  2. enum TextInputResult {
  3. TextInputResultOk,
  4. };
  5. static void nfc_maker_scene_save_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_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. name_generator_make_auto(app->save_buf, BIG_INPUT_LEN, "NFC");
  14. text_input_set_result_callback(
  15. text_input,
  16. nfc_maker_scene_save_text_input_callback,
  17. app,
  18. app->save_buf,
  19. BIG_INPUT_LEN,
  20. true);
  21. ValidatorIsFile* validator_is_file =
  22. validator_is_file_alloc_init(NFC_APP_FOLDER, NFC_APP_EXTENSION, NULL);
  23. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  24. view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
  25. }
  26. bool nfc_maker_scene_save_on_event(void* context, SceneManagerEvent event) {
  27. NfcMaker* app = context;
  28. bool consumed = false;
  29. if(event.type == SceneManagerEventTypeCustom) {
  30. consumed = true;
  31. switch(event.event) {
  32. case TextInputResultOk:
  33. scene_manager_next_scene(app->scene_manager, NfcMakerSceneResult);
  34. break;
  35. default:
  36. break;
  37. }
  38. }
  39. return consumed;
  40. }
  41. void nfc_maker_scene_save_on_exit(void* context) {
  42. NfcMaker* app = context;
  43. text_input_reset(app->text_input);
  44. }