passy_scene_dob_input.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. text_input_set_header_text(text_input, "DoB: YYMMDD");
  14. text_input_set_minimum_length(text_input, 6);
  15. if(passy->date_of_birth[0] != '\0') {
  16. strlcpy(passy->text_store, passy->date_of_birth, sizeof(passy->text_store));
  17. }
  18. text_input_set_result_callback(
  19. text_input,
  20. passy_scene_dob_input_text_input_callback,
  21. passy,
  22. passy->text_store,
  23. sizeof(passy->text_store),
  24. false);
  25. view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewTextInput);
  26. }
  27. bool passy_scene_dob_input_on_event(void* context, SceneManagerEvent event) {
  28. Passy* passy = context;
  29. bool consumed = false;
  30. if(event.type == SceneManagerEventTypeCustom) {
  31. if(event.event == PassyCustomEventTextInputDone) {
  32. strlcpy(passy->date_of_birth, passy->text_store, strlen(passy->text_store) + 1);
  33. scene_manager_next_scene(passy->scene_manager, PassySceneDoEInput);
  34. consumed = true;
  35. }
  36. }
  37. return consumed;
  38. }
  39. void passy_scene_dob_input_on_exit(void* context) {
  40. Passy* passy = context;
  41. memset(passy->text_store, 0, sizeof(passy->text_store));
  42. text_input_reset(passy->text_input);
  43. }