passy_scene_passport_number_input.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "../passy_i.h"
  2. #include <gui/modules/validators.h>
  3. #define PASSY_APP_FILE_PREFIX "Passy"
  4. void passy_scene_passport_number_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_passport_number_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, "Passport Number");
  13. if(passy->passport_number[0] != '\0') {
  14. strlcpy(passy->text_store, passy->passport_number, sizeof(passy->text_store));
  15. }
  16. text_input_set_result_callback(
  17. text_input,
  18. passy_scene_passport_number_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_passport_number_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. // Padding the passport number with '<' to make it 9 characters long
  31. size_t len = strlen(passy->text_store);
  32. while(len < 9) {
  33. passy->text_store[len++] = '<';
  34. }
  35. passy->text_store[len] = '\0';
  36. strlcpy(passy->passport_number, passy->text_store, strlen(passy->text_store) + 1);
  37. scene_manager_next_scene(passy->scene_manager, PassySceneDoBInput);
  38. consumed = true;
  39. }
  40. }
  41. return consumed;
  42. }
  43. void passy_scene_passport_number_input_on_exit(void* context) {
  44. Passy* passy = context;
  45. // Clear view
  46. memset(passy->text_store, 0, sizeof(passy->text_store));
  47. text_input_reset(passy->text_input);
  48. }