nfc_scene_save_name.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "../nfc_i.h"
  2. #define SCENE_SAVE_NAME_CUSTOM_EVENT (0UL)
  3. void nfc_scene_save_name_text_input_callback(void* context) {
  4. Nfc* nfc = (Nfc*)context;
  5. view_dispatcher_send_custom_event(nfc->view_dispatcher, SCENE_SAVE_NAME_CUSTOM_EVENT);
  6. }
  7. const void nfc_scene_save_name_on_enter(void* context) {
  8. Nfc* nfc = (Nfc*)context;
  9. // Setup view
  10. TextInput* text_input = nfc->text_input;
  11. if(nfc->dev.dev_name) {
  12. nfc_device_delete(&nfc->dev);
  13. }
  14. nfc_text_store_set(nfc, nfc->dev.dev_name);
  15. text_input_set_header_text(text_input, "Name the card");
  16. text_input_set_result_callback(
  17. text_input,
  18. nfc_scene_save_name_text_input_callback,
  19. nfc,
  20. nfc->text_store,
  21. sizeof(nfc->text_store));
  22. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextInput);
  23. }
  24. const bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) {
  25. Nfc* nfc = (Nfc*)context;
  26. if(event.type == SceneManagerEventTypeCustom) {
  27. if(event.event == SCENE_SAVE_NAME_CUSTOM_EVENT) {
  28. memcpy(&nfc->dev.dev_name, nfc->text_store, strlen(nfc->text_store));
  29. if(nfc_device_save(&nfc->dev, nfc->text_store)) {
  30. scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess);
  31. return true;
  32. } else {
  33. return scene_manager_search_previous_scene(nfc->scene_manager, NfcSceneStart);
  34. }
  35. }
  36. }
  37. return false;
  38. }
  39. const void nfc_scene_save_name_on_exit(void* context) {
  40. Nfc* nfc = (Nfc*)context;
  41. // Clear view
  42. text_input_set_header_text(nfc->text_input, NULL);
  43. }