infrared_scene_ask_retry.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "../infrared_i.h"
  2. static void infrared_scene_dialog_result_callback(DialogExResult result, void* context) {
  3. Infrared* infrared = context;
  4. view_dispatcher_send_custom_event(infrared->view_dispatcher, result);
  5. }
  6. void infrared_scene_ask_retry_on_enter(void* context) {
  7. Infrared* infrared = context;
  8. DialogEx* dialog_ex = infrared->dialog_ex;
  9. dialog_ex_set_header(dialog_ex, "Return to Reading?", 64, 0, AlignCenter, AlignTop);
  10. dialog_ex_set_text(
  11. dialog_ex, "All unsaved data\nwill be lost!", 64, 31, AlignCenter, AlignCenter);
  12. dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
  13. dialog_ex_set_left_button_text(dialog_ex, "Exit");
  14. dialog_ex_set_center_button_text(dialog_ex, NULL);
  15. dialog_ex_set_right_button_text(dialog_ex, "Stay");
  16. dialog_ex_set_result_callback(dialog_ex, infrared_scene_dialog_result_callback);
  17. dialog_ex_set_context(dialog_ex, context);
  18. view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewDialogEx);
  19. }
  20. bool infrared_scene_ask_retry_on_event(void* context, SceneManagerEvent event) {
  21. Infrared* infrared = context;
  22. SceneManager* scene_manager = infrared->scene_manager;
  23. bool consumed = false;
  24. if(event.type == SceneManagerEventTypeBack) {
  25. consumed = true;
  26. } else if(event.type == SceneManagerEventTypeCustom) {
  27. if(event.event == DialogExResultLeft) {
  28. scene_manager_search_and_switch_to_previous_scene(scene_manager, InfraredSceneLearn);
  29. consumed = true;
  30. } else if(event.event == DialogExResultRight) {
  31. scene_manager_previous_scene(scene_manager);
  32. consumed = true;
  33. }
  34. }
  35. return consumed;
  36. }
  37. void infrared_scene_ask_retry_on_exit(void* context) {
  38. Infrared* infrared = context;
  39. dialog_ex_reset(infrared->dialog_ex);
  40. }