nfc_scene_exit_confirm.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "../nfc_i.h"
  2. void nfc_scene_exit_confirm_dialog_callback(DialogExResult result, void* context) {
  3. Nfc* nfc = context;
  4. view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
  5. }
  6. void nfc_scene_exit_confirm_on_enter(void* context) {
  7. Nfc* nfc = context;
  8. DialogEx* dialog_ex = nfc->dialog_ex;
  9. dialog_ex_set_left_button_text(dialog_ex, "Exit");
  10. dialog_ex_set_right_button_text(dialog_ex, "Stay");
  11. dialog_ex_set_header(dialog_ex, "Exit to NFC Menu?", 64, 11, AlignCenter, AlignTop);
  12. dialog_ex_set_text(
  13. dialog_ex, "All unsaved data\nwill be lost!", 64, 25, AlignCenter, AlignTop);
  14. dialog_ex_set_context(dialog_ex, nfc);
  15. dialog_ex_set_result_callback(dialog_ex, nfc_scene_exit_confirm_dialog_callback);
  16. view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
  17. }
  18. bool nfc_scene_exit_confirm_on_event(void* context, SceneManagerEvent event) {
  19. Nfc* nfc = context;
  20. bool consumed = false;
  21. if(event.type == SceneManagerEventTypeCustom) {
  22. if(event.event == DialogExResultRight) {
  23. consumed = scene_manager_previous_scene(nfc->scene_manager);
  24. } else if(event.event == DialogExResultLeft) {
  25. if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneReadCardType)) {
  26. consumed = scene_manager_search_and_switch_to_previous_scene(
  27. nfc->scene_manager, NfcSceneReadCardType);
  28. } else {
  29. consumed = scene_manager_search_and_switch_to_previous_scene(
  30. nfc->scene_manager, NfcSceneStart);
  31. }
  32. }
  33. } else if(event.type == SceneManagerEventTypeBack) {
  34. consumed = true;
  35. }
  36. return consumed;
  37. }
  38. void nfc_scene_exit_confirm_on_exit(void* context) {
  39. Nfc* nfc = context;
  40. // Clean view
  41. dialog_ex_reset(nfc->dialog_ex);
  42. }