passy_scene_doe_input.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // TODO: reload from saved data
  13. text_input_set_header_text(text_input, "DoE: YYMMDD");
  14. text_input_set_minimum_length(text_input, 6);
  15. text_input_set_result_callback(
  16. text_input,
  17. passy_scene_doe_input_text_input_callback,
  18. passy,
  19. passy->text_store,
  20. sizeof(passy->text_store),
  21. false);
  22. view_dispatcher_switch_to_view(passy->view_dispatcher, PassyViewTextInput);
  23. }
  24. bool passy_scene_doe_input_on_event(void* context, SceneManagerEvent event) {
  25. Passy* passy = context;
  26. bool consumed = false;
  27. if(event.type == SceneManagerEventTypeCustom) {
  28. if(event.event == PassyCustomEventTextInputDone) {
  29. strlcpy(passy->date_of_expiry, passy->text_store, strlen(passy->text_store) + 1);
  30. passy_save_mrz_info(passy);
  31. scene_manager_next_scene(passy->scene_manager, PassySceneMainMenu);
  32. consumed = true;
  33. }
  34. }
  35. return consumed;
  36. }
  37. void passy_scene_doe_input_on_exit(void* context) {
  38. Passy* passy = context;
  39. // Clear view
  40. memset(passy->text_store, 0, sizeof(passy->text_store));
  41. text_input_reset(passy->text_input);
  42. }