nfc_scene_save_name.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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(
  6. nfc->nfc_common.view_dispatcher, SCENE_SAVE_NAME_CUSTOM_EVENT);
  7. }
  8. const void nfc_scene_save_name_on_enter(void* context) {
  9. Nfc* nfc = (Nfc*)context;
  10. // Setup view
  11. TextInput* text_input = nfc->text_input;
  12. nfc_text_store_clear(nfc);
  13. text_input_set_header_text(text_input, "Name the card");
  14. text_input_set_result_callback(
  15. text_input,
  16. nfc_scene_save_name_text_input_callback,
  17. nfc,
  18. nfc->text_store,
  19. sizeof(nfc->text_store));
  20. view_dispatcher_switch_to_view(nfc->nfc_common.view_dispatcher, NfcViewTextInput);
  21. }
  22. const bool nfc_scene_save_name_on_event(void* context, SceneManagerEvent event) {
  23. Nfc* nfc = (Nfc*)context;
  24. if(event.type == SceneManagerEventTypeCustom) {
  25. if(event.event == SCENE_SAVE_NAME_CUSTOM_EVENT) {
  26. memcpy(&nfc->device.dev_name, nfc->text_store, strlen(nfc->text_store));
  27. if(nfc_device_save(&nfc->device, nfc->text_store)) {
  28. scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess);
  29. return true;
  30. } else {
  31. return scene_manager_search_previous_scene(nfc->scene_manager, NfcSceneStart);
  32. }
  33. }
  34. }
  35. return false;
  36. }
  37. const void nfc_scene_save_name_on_exit(void* context) {
  38. Nfc* nfc = (Nfc*)context;
  39. // Clear view
  40. text_input_set_header_text(nfc->text_input, NULL);
  41. }