nfc_maker_scene_save.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. NFCMaker_TextInput* text_input = app->text_input;
  12. nfc_maker_text_input_set_header_text(text_input, "Save the NFC tag:");
  13. name_generator_make_auto(app->save_buf, BIG_INPUT_LEN, "NFC");
  14. nfc_maker_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. NFCMakerValidatorIsFile* validator_is_file =
  22. nfc_maker_validator_is_file_alloc_init(NFC_MK_APP_FOLDER, NFC_MK_APP_EXTENSION, NULL);
  23. nfc_maker_text_input_set_validator(
  24. text_input, nfc_maker_validator_is_file_callback, validator_is_file);
  25. view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
  26. }
  27. bool nfc_maker_scene_save_on_event(void* context, SceneManagerEvent event) {
  28. NfcMaker* app = context;
  29. bool consumed = false;
  30. if(event.type == SceneManagerEventTypeCustom) {
  31. consumed = true;
  32. switch(event.event) {
  33. case TextInputResultOk:
  34. scene_manager_next_scene(app->scene_manager, NfcMakerSceneResult);
  35. break;
  36. default:
  37. break;
  38. }
  39. }
  40. return consumed;
  41. }
  42. void nfc_maker_scene_save_on_exit(void* context) {
  43. NfcMaker* app = context;
  44. nfc_maker_text_input_reset(app->text_input);
  45. }