subrem_scene_fw_warning.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "../subghz_remote_app_i.h"
  2. #include "../helpers/subrem_custom_event.h"
  3. #ifdef FW_ORIGIN_Official
  4. typedef enum {
  5. SceneFwWarningStateAttention,
  6. SceneFwWarningStateAccept,
  7. } SceneFwWarningState;
  8. static void subrem_scene_fw_warning_widget_render(SubGhzRemoteApp* app, SceneFwWarningState state);
  9. static void
  10. subrem_scene_fw_warning_widget_callback(GuiButtonType result, InputType type, void* context) {
  11. furi_assert(context);
  12. SubGhzRemoteApp* app = context;
  13. if(type == InputTypeShort) {
  14. SubRemCustomEvent event = SubRemCustomEventSceneFwWarningExit;
  15. switch(scene_manager_get_scene_state(app->scene_manager, SubRemSceneFwWarning)) {
  16. case SceneFwWarningStateAttention:
  17. if(result == GuiButtonTypeRight) {
  18. event = SubRemCustomEventSceneFwWarningNext;
  19. }
  20. break;
  21. case SceneFwWarningStateAccept:
  22. if(result == GuiButtonTypeRight) {
  23. event = SubRemCustomEventSceneFwWarningContinue;
  24. }
  25. break;
  26. }
  27. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  28. }
  29. }
  30. static void
  31. subrem_scene_fw_warning_widget_render(SubGhzRemoteApp* app, SceneFwWarningState state) {
  32. furi_assert(app);
  33. Widget* widget = app->widget;
  34. widget_reset(widget);
  35. switch(state) {
  36. case SceneFwWarningStateAttention:
  37. widget_add_button_element(
  38. widget, GuiButtonTypeLeft, "Exit", subrem_scene_fw_warning_widget_callback, app);
  39. widget_add_button_element(
  40. widget, GuiButtonTypeRight, "Continue", subrem_scene_fw_warning_widget_callback, app);
  41. widget_add_string_element(
  42. widget, 64, 12, AlignCenter, AlignBottom, FontPrimary, "Not official FW");
  43. widget_add_string_multiline_element(
  44. widget,
  45. 64,
  46. 32,
  47. AlignCenter,
  48. AlignCenter,
  49. FontSecondary,
  50. "You are using custom firmware\nPlease download a compatible\nversion of the application");
  51. break;
  52. case SceneFwWarningStateAccept:
  53. widget_add_button_element(
  54. widget, GuiButtonTypeLeft, "Exit", subrem_scene_fw_warning_widget_callback, app);
  55. widget_add_button_element(
  56. widget, GuiButtonTypeRight, "Accept", subrem_scene_fw_warning_widget_callback, app);
  57. widget_add_string_element(
  58. widget, 64, 12, AlignCenter, AlignBottom, FontPrimary, "Not official FW");
  59. widget_add_string_multiline_element(
  60. widget,
  61. 64,
  62. 32,
  63. AlignCenter,
  64. AlignCenter,
  65. FontSecondary,
  66. "Yes, I understand that\nthe application can\nbreak my subghz key file");
  67. break;
  68. }
  69. }
  70. void subrem_scene_fw_warning_on_enter(void* context) {
  71. furi_assert(context);
  72. SubGhzRemoteApp* app = context;
  73. scene_manager_set_scene_state(
  74. app->scene_manager, SubRemSceneFwWarning, SceneFwWarningStateAttention);
  75. subrem_scene_fw_warning_widget_render(app, SceneFwWarningStateAttention);
  76. view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewIDWidget);
  77. }
  78. bool subrem_scene_fw_warning_on_event(void* context, SceneManagerEvent event) {
  79. furi_assert(context);
  80. SubGhzRemoteApp* app = context;
  81. bool consumed = false;
  82. if(event.type == SceneManagerEventTypeBack) {
  83. consumed = true;
  84. } else if(event.type == SceneManagerEventTypeCustom) {
  85. if(event.event == SubRemCustomEventSceneFwWarningExit) {
  86. scene_manager_stop(app->scene_manager);
  87. view_dispatcher_stop(app->view_dispatcher);
  88. consumed = true;
  89. } else if(event.event == SubRemCustomEventSceneFwWarningNext) {
  90. scene_manager_set_scene_state(
  91. app->scene_manager, SubRemSceneFwWarning, SceneFwWarningStateAccept);
  92. subrem_scene_fw_warning_widget_render(app, SceneFwWarningStateAccept);
  93. view_dispatcher_switch_to_view(app->view_dispatcher, SubRemViewIDWidget);
  94. consumed = true;
  95. } else if(event.event == SubRemCustomEventSceneFwWarningContinue) {
  96. scene_manager_previous_scene(app->scene_manager);
  97. consumed = true;
  98. }
  99. }
  100. return consumed;
  101. }
  102. void subrem_scene_fw_warning_on_exit(void* context) {
  103. furi_assert(context);
  104. SubGhzRemoteApp* app = context;
  105. widget_reset(app->widget);
  106. }
  107. #endif