irda_app_scene_ask_back.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "../irda_app.h"
  2. #include "gui/modules/dialog_ex.h"
  3. #include "irda.h"
  4. #include "irda/scene/irda_app_scene.h"
  5. #include <string>
  6. static void dialog_result_callback(DialogExResult result, void* context) {
  7. auto app = static_cast<IrdaApp*>(context);
  8. IrdaAppEvent event;
  9. event.type = IrdaAppEvent::Type::DialogExSelected;
  10. event.payload.dialog_ex_result = result;
  11. app->get_view_manager()->send_event(&event);
  12. }
  13. void IrdaAppSceneAskBack::on_enter(IrdaApp* app) {
  14. IrdaAppViewManager* view_manager = app->get_view_manager();
  15. DialogEx* dialog_ex = view_manager->get_dialog_ex();
  16. if(app->get_learn_new_remote()) {
  17. dialog_ex_set_header(dialog_ex, "Exit to Infrared menu?", 64, 0, AlignCenter, AlignTop);
  18. } else {
  19. dialog_ex_set_header(dialog_ex, "Exit to remote menu?", 64, 0, AlignCenter, AlignTop);
  20. }
  21. dialog_ex_set_text(
  22. dialog_ex, "All unsaved data\nwill be lost", 64, 31, AlignCenter, AlignCenter);
  23. dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
  24. dialog_ex_set_left_button_text(dialog_ex, "Exit");
  25. dialog_ex_set_center_button_text(dialog_ex, nullptr);
  26. dialog_ex_set_right_button_text(dialog_ex, "Stay");
  27. dialog_ex_set_result_callback(dialog_ex, dialog_result_callback);
  28. dialog_ex_set_context(dialog_ex, app);
  29. view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx);
  30. }
  31. bool IrdaAppSceneAskBack::on_event(IrdaApp* app, IrdaAppEvent* event) {
  32. bool consumed = false;
  33. if(event->type == IrdaAppEvent::Type::DialogExSelected) {
  34. switch(event->payload.dialog_ex_result) {
  35. case DialogExResultLeft:
  36. consumed = true;
  37. if(app->get_learn_new_remote()) {
  38. app->search_and_switch_to_previous_scene({IrdaApp::Scene::Start});
  39. } else {
  40. app->search_and_switch_to_previous_scene(
  41. {IrdaApp::Scene::Edit, IrdaApp::Scene::Remote});
  42. }
  43. break;
  44. case DialogExResultCenter:
  45. furi_assert(0);
  46. break;
  47. case DialogExResultRight:
  48. app->switch_to_previous_scene();
  49. consumed = true;
  50. break;
  51. }
  52. }
  53. if(event->type == IrdaAppEvent::Type::Back) {
  54. consumed = true;
  55. }
  56. return consumed;
  57. }
  58. void IrdaAppSceneAskBack::on_exit(IrdaApp* app) {
  59. }