passy_scene_dob_input.c 1.6 KB

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