subrem_scene_edit_preview.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "../subghz_remote_app_i.h"
  2. #include "../views/remote.h"
  3. #define TAG "SubRemScenRemote"
  4. void subghz_scene_edit_preview_save_popup_callback(void* context) {
  5. SubGhzRemoteApp* app = context;
  6. view_dispatcher_send_custom_event(
  7. app->view_dispatcher, SubRemCustomEventSceneEditPreviewSaved);
  8. }
  9. void subrem_scene_edit_preview_callback(SubRemCustomEvent event, void* context) {
  10. furi_assert(context);
  11. SubGhzRemoteApp* app = context;
  12. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  13. }
  14. void subrem_scene_edit_preview_on_enter(void* context) {
  15. SubGhzRemoteApp* app = context;
  16. // Setup view
  17. Popup* popup = app->popup;
  18. popup_set_icon(popup, 36, 5, &I_DolphinDone_80x58);
  19. popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom);
  20. popup_set_timeout(popup, 1500);
  21. popup_set_context(popup, app);
  22. popup_set_callback(popup, subghz_scene_edit_preview_save_popup_callback);
  23. popup_enable_timeout(popup);
  24. subrem_view_remote_update_data_labels(app->subrem_remote_view, app->map_preset->subs_preset);
  25. subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateOFF, 0);
  26. subrem_view_remote_set_callback(
  27. app->subrem_remote_view, subrem_scene_edit_preview_callback, app);
  28. view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewIDRemote);
  29. }
  30. bool subrem_scene_edit_preview_on_event(void* context, SceneManagerEvent event) {
  31. SubGhzRemoteApp* app = context;
  32. if(event.type == SceneManagerEventTypeBack ||
  33. (event.type == SceneManagerEventTypeCustom &&
  34. (event.event == SubRemCustomEventViewRemoteStartLEFT ||
  35. event.event == SubRemCustomEventViewRemoteForcedStop))) {
  36. scene_manager_previous_scene(app->scene_manager);
  37. return true;
  38. } else if(
  39. event.type == SceneManagerEventTypeCustom &&
  40. (event.event == SubRemCustomEventViewRemoteStartRIGHT ||
  41. event.event == SubRemCustomEventViewRemoteStartOK)) {
  42. if(subrem_save_map_to_file(app)) {
  43. view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewIDPopup);
  44. app->map_not_saved = false;
  45. return true;
  46. }
  47. // TODO error screen
  48. return true;
  49. } else if(
  50. event.type == SceneManagerEventTypeCustom &&
  51. event.event == SubRemCustomEventSceneEditPreviewSaved) {
  52. scene_manager_search_and_switch_to_previous_scene(app->scene_manager, SubRemSceneEditMenu);
  53. }
  54. // } else if(event.type == SceneManagerEventTypeTick) {
  55. // }
  56. return false;
  57. }
  58. void subrem_scene_edit_preview_on_exit(void* context) {
  59. SubGhzRemoteApp* app = context;
  60. subrem_view_remote_set_state(app->subrem_remote_view, SubRemViewRemoteStateIdle, 0);
  61. popup_reset(app->popup);
  62. }