passy_scene_doe_input.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "../passy_i.h"
  2. #include <gui/modules/validators.h>
  3. #define PASSY_APP_FILE_PREFIX "Passy"
  4. void passy_scene_doe_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_doe_input_on_enter(void* context) {
  9. Passy* passy = context;
  10. // Setup view
  11. TextInput* text_input = passy->text_input;
  12. text_input_set_header_text(text_input, "DoE: YYMMDD");
  13. text_input_set_minimum_length(text_input, 6);
  14. if(passy->date_of_expiry[0] != '\0') {
  15. strlcpy(passy->text_store, passy->date_of_expiry, sizeof(passy->text_store));
  16. }
  17. text_input_set_result_callback(
  18. text_input,
  19. passy_scene_doe_input_text_input_callback,
  20. passy,
  21. passy->text_store,
  22. sizeof(passy->text_store),
  23. false);
  24. view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewTextInput);
  25. }
  26. bool passy_scene_doe_input_on_event(void* context, SceneManagerEvent event) {
  27. Passy* passy = context;
  28. bool consumed = false;
  29. if(event.type == SceneManagerEventTypeCustom) {
  30. if(event.event == PassyCustomEventTextInputDone) {
  31. strlcpy(passy->date_of_expiry, passy->text_store, strlen(passy->text_store) + 1);
  32. passy_save_mrz_info(passy);
  33. scene_manager_next_scene(passy->scene_manager, PassySceneMainMenu);
  34. consumed = true;
  35. }
  36. }
  37. return consumed;
  38. }
  39. void passy_scene_doe_input_on_exit(void* context) {
  40. Passy* passy = context;
  41. // Clear view
  42. memset(passy->text_store, 0, sizeof(passy->text_store));
  43. text_input_reset(passy->text_input);
  44. }