passy_scene_doe_input.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. scene_manager_next_scene(passy->scene_manager, PassySceneRead);
  31. consumed = true;
  32. }
  33. }
  34. return consumed;
  35. }
  36. void passy_scene_doe_input_on_exit(void* context) {
  37. Passy* passy = context;
  38. // Clear view
  39. memset(passy->text_store, 0, sizeof(passy->text_store));
  40. text_input_reset(passy->text_input);
  41. }