2021-10-27 17:37:11 +00: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)) {
|
2021-11-24 13:59:45 +00:00
|
|
|
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneStay);
|
2021-10-27 17:37:11 +00:00
|
|
|
} else if((result == GuiButtonTypeLeft) && (type == InputTypeShort)) {
|
2021-11-24 13:59:45 +00:00
|
|
|
view_dispatcher_send_custom_event(subghz->view_dispatcher, SubghzCustomEventSceneExit);
|
2021-10-27 17:37:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_scene_need_saving_on_enter(void* context) {
|
|
|
|
SubGhz* subghz = context;
|
|
|
|
|
2021-11-24 13:59:45 +00:00
|
|
|
widget_add_string_multiline_element(
|
2021-11-24 16:21:12 +00:00
|
|
|
subghz->widget, 64, 13, AlignCenter, AlignCenter, FontPrimary, "Exit to Sub-Ghz menu?");
|
2021-10-27 17:37:11 +00:00
|
|
|
widget_add_string_multiline_element(
|
|
|
|
subghz->widget,
|
|
|
|
64,
|
2021-11-24 13:59:45 +00:00
|
|
|
32,
|
2021-10-27 17:37:11 +00:00
|
|
|
AlignCenter,
|
|
|
|
AlignCenter,
|
|
|
|
FontSecondary,
|
2021-11-24 13:59:45 +00:00
|
|
|
"All unsaved will be\nlost.");
|
2021-10-27 17:37:11 +00:00
|
|
|
|
|
|
|
widget_add_button_element(
|
2021-11-24 13:59:45 +00:00
|
|
|
subghz->widget, GuiButtonTypeRight, "Stay", subghz_scene_need_saving_callback, subghz);
|
2021-10-27 17:37:11 +00:00
|
|
|
widget_add_button_element(
|
2021-11-24 13:59:45 +00:00
|
|
|
subghz->widget, GuiButtonTypeLeft, "Exit", subghz_scene_need_saving_callback, subghz);
|
2021-10-27 17:37:11 +00:00
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
SubGhz* subghz = context;
|
2021-11-24 13:59:45 +00:00
|
|
|
if(event.type == SceneManagerEventTypeBack) {
|
|
|
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
|
|
|
|
scene_manager_previous_scene(subghz->scene_manager);
|
|
|
|
return true;
|
|
|
|
} else if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == SubghzCustomEventSceneStay) {
|
|
|
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
|
2021-10-27 17:37:11 +00:00
|
|
|
scene_manager_previous_scene(subghz->scene_manager);
|
|
|
|
return true;
|
2021-11-24 13:59:45 +00:00
|
|
|
} else if(event.event == SubghzCustomEventSceneExit) {
|
2021-10-27 17:37:11 +00:00
|
|
|
if(subghz->txrx->rx_key_state == SubGhzRxKeyStateExit) {
|
|
|
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
|
|
|
scene_manager_search_and_switch_to_previous_scene(
|
|
|
|
subghz->scene_manager, SubGhzSceneStart);
|
|
|
|
} else {
|
|
|
|
subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE;
|
|
|
|
scene_manager_previous_scene(subghz->scene_manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void subghz_scene_need_saving_on_exit(void* context) {
|
|
|
|
SubGhz* subghz = context;
|
|
|
|
widget_clear(subghz->widget);
|
|
|
|
}
|