passy_scene_passport_number_input.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "../passy_i.h"
  2. #include <gui/modules/validators.h>
  3. #define PASSY_APP_FILE_PREFIX "Passy"
  4. void passy_scene_passport_number_input_text_input_callback(void* context) {
  5. Passy* passy = context;
  6. view_dispatcher_send_custom_event(passy->view_dispatcher, PassyCustomEventTextInputDone);
  7. }
  8. void passy_scene_passport_number_input_on_enter(void* context) {
  9. Passy* passy = context;
  10. // Setup view
  11. TextInput* text_input = passy->text_input;
  12. // TODO: reload from saved data
  13. text_input_set_header_text(text_input, "Passport Number");
  14. text_input_set_result_callback(
  15. text_input,
  16. passy_scene_passport_number_input_text_input_callback,
  17. passy,
  18. passy->text_store,
  19. sizeof(passy->text_store),
  20. false);
  21. view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewTextInput);
  22. }
  23. bool passy_scene_passport_number_input_on_event(void* context, SceneManagerEvent event) {
  24. Passy* passy = context;
  25. bool consumed = false;
  26. if(event.type == SceneManagerEventTypeCustom) {
  27. if(event.event == PassyCustomEventTextInputDone) {
  28. strlcpy(passy->passport_number, passy->text_store, strlen(passy->text_store) + 1);
  29. scene_manager_next_scene(passy->scene_manager, PassySceneDoBInput);
  30. consumed = true;
  31. }
  32. }
  33. return consumed;
  34. }
  35. void passy_scene_passport_number_input_on_exit(void* context) {
  36. Passy* passy = context;
  37. // Clear view
  38. memset(passy->text_store, 0, sizeof(passy->text_store));
  39. text_input_reset(passy->text_input);
  40. }