2021-10-27 20:37:11 +03:00
|
|
|
#include "../subghz_i.h"
|
|
|
|
#include "../helpers/subghz_custom_event.h"
|
|
|
|
|
|
|
|
void subghz_scene_need_saving_callback(GuiButtonType result, InputType type, void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
SubGhz* subghz = context;
|
|
|
|
|
|
|
|
if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
|
2022-03-03 12:48:56 +03:00
|
|
|
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneStay);
|
2021-10-27 20:37:11 +03:00
|
|
|
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
|
2022-03-03 12:48:56 +03:00
|
|
|
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneExit);
|
2021-10-27 20:37:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_scene_need_saving_on_enter(void* context) {
|
|
|
|
SubGhz* subghz = context;
|
|
|
|
|
2021-11-24 16:59:45 +03:00
|
|
|
widget_add_string_multiline_element(
|
2023-03-08 14:27:21 +03:00
|
|
|
subghz->widget, 64, 13, AlignCenter, AlignCenter, FontPrimary, "Exit to Sub-GHz Menu?");
|
2021-10-27 20:37:11 +03:00
|
|
|
widget_add_string_multiline_element(
|
|
|
|
subghz->widget,
|
|
|
|
64,
|
2021-11-24 16:59:45 +03:00
|
|
|
32,
|
2021-10-27 20:37:11 +03:00
|
|
|
AlignCenter,
|
|
|
|
AlignCenter,
|
|
|
|
FontSecondary,
|
2023-03-08 14:27:21 +03:00
|
|
|
"All unsaved data\nwill be lost!");
|
2021-10-27 20:37:11 +03:00
|
|
|
|
|
|
|
widget_add_button_element(
|
2021-11-24 16:59:45 +03:00
|
|
|
subghz->widget, GuiButtonTypeRight, "Stay", subghz_scene_need_saving_callback, subghz);
|
2021-10-27 20:37:11 +03:00
|
|
|
widget_add_button_element(
|
2021-11-24 16:59:45 +03:00
|
|
|
subghz->widget, GuiButtonTypeLeft, "Exit", subghz_scene_need_saving_callback, subghz);
|
2021-10-27 20:37:11 +03:00
|
|
|
|
2022-03-03 12:48:56 +03:00
|
|
|
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
|
2021-10-27 20:37:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
SubGhz* subghz = context;
|
2021-11-24 16:59:45 +03:00
|
|
|
if(event.type == SceneManagerEventTypeBack) {
|
2023-05-06 17:47:49 +03:00
|
|
|
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack);
|
2021-11-24 16:59:45 +03:00
|
|
|
scene_manager_previous_scene(subghz->scene_manager);
|
|
|
|
return true;
|
|
|
|
} else if(event.type == SceneManagerEventTypeCustom) {
|
2022-03-03 12:48:56 +03:00
|
|
|
if(event.event == SubGhzCustomEventSceneStay) {
|
2023-05-06 17:47:49 +03:00
|
|
|
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateBack);
|
2021-10-27 20:37:11 +03:00
|
|
|
scene_manager_previous_scene(subghz->scene_manager);
|
|
|
|
return true;
|
2022-03-03 12:48:56 +03:00
|
|
|
} else if(event.event == SubGhzCustomEventSceneExit) {
|
2023-05-09 21:20:35 +03:00
|
|
|
SubGhzRxKeyState state = subghz_rx_key_state_get(subghz);
|
|
|
|
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
|
|
|
|
|
2023-05-10 13:21:42 +03:00
|
|
|
if(state == SubGhzRxKeyStateExit) {
|
2024-01-30 23:32:41 +03:00
|
|
|
if(scene_manager_has_previous_scene(subghz->scene_manager, SubGhzSceneReadRAW)) {
|
|
|
|
if(!furi_string_empty(subghz->file_path_tmp)) {
|
|
|
|
subghz_delete_file(subghz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-09 19:10:56 +03:00
|
|
|
subghz_txrx_set_preset(
|
2023-05-09 12:07:36 +03:00
|
|
|
subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0);
|
2021-10-27 20:37:11 +03:00
|
|
|
scene_manager_search_and_switch_to_previous_scene(
|
|
|
|
subghz->scene_manager, SubGhzSceneStart);
|
|
|
|
} else {
|
|
|
|
scene_manager_previous_scene(subghz->scene_manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_scene_need_saving_on_exit(void* context) {
|
|
|
|
SubGhz* subghz = context;
|
2022-02-02 22:59:28 +03:00
|
|
|
widget_reset(subghz->widget);
|
2021-10-27 20:37:11 +03:00
|
|
|
}
|