2022-02-25 15:22:58 +00:00
|
|
|
#include "../infrared_app.h"
|
2022-02-16 11:09:47 +00:00
|
|
|
#include "gui/modules/dialog_ex.h"
|
2022-02-25 15:22:58 +00:00
|
|
|
#include "infrared.h"
|
|
|
|
#include "infrared/scene/infrared_app_scene.h"
|
2022-02-16 11:09:47 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
static void dialog_result_callback(DialogExResult result, void* context) {
|
2022-02-25 15:22:58 +00:00
|
|
|
auto app = static_cast<InfraredApp*>(context);
|
|
|
|
InfraredAppEvent event;
|
2022-02-16 11:09:47 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
event.type = InfraredAppEvent::Type::DialogExSelected;
|
2022-02-16 11:09:47 +00:00
|
|
|
event.payload.dialog_ex_result = result;
|
|
|
|
|
|
|
|
app->get_view_manager()->send_event(&event);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppSceneAskBack::on_enter(InfraredApp* app) {
|
|
|
|
InfraredAppViewManager* view_manager = app->get_view_manager();
|
2022-02-16 11:09:47 +00:00
|
|
|
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
|
|
|
|
|
|
|
if(app->get_learn_new_remote()) {
|
|
|
|
dialog_ex_set_header(dialog_ex, "Exit to Infrared menu?", 64, 0, AlignCenter, AlignTop);
|
|
|
|
} else {
|
|
|
|
dialog_ex_set_header(dialog_ex, "Exit to remote menu?", 64, 0, AlignCenter, AlignTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog_ex_set_text(
|
|
|
|
dialog_ex, "All unsaved data\nwill be lost", 64, 31, AlignCenter, AlignCenter);
|
|
|
|
dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
|
|
|
|
dialog_ex_set_left_button_text(dialog_ex, "Exit");
|
|
|
|
dialog_ex_set_center_button_text(dialog_ex, nullptr);
|
|
|
|
dialog_ex_set_right_button_text(dialog_ex, "Stay");
|
|
|
|
dialog_ex_set_result_callback(dialog_ex, dialog_result_callback);
|
|
|
|
dialog_ex_set_context(dialog_ex, app);
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
view_manager->switch_to(InfraredAppViewManager::ViewId::DialogEx);
|
2022-02-16 11:09:47 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool InfraredAppSceneAskBack::on_event(InfraredApp* app, InfraredAppEvent* event) {
|
2022-02-16 11:09:47 +00:00
|
|
|
bool consumed = false;
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
if(event->type == InfraredAppEvent::Type::DialogExSelected) {
|
2022-02-16 11:09:47 +00:00
|
|
|
switch(event->payload.dialog_ex_result) {
|
|
|
|
case DialogExResultLeft:
|
|
|
|
consumed = true;
|
|
|
|
if(app->get_learn_new_remote()) {
|
2022-02-25 15:22:58 +00:00
|
|
|
app->search_and_switch_to_previous_scene({InfraredApp::Scene::Start});
|
2022-02-16 11:09:47 +00:00
|
|
|
} else {
|
|
|
|
app->search_and_switch_to_previous_scene(
|
2022-02-25 15:22:58 +00:00
|
|
|
{InfraredApp::Scene::Edit, InfraredApp::Scene::Remote});
|
2022-02-16 11:09:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DialogExResultCenter:
|
|
|
|
furi_assert(0);
|
|
|
|
break;
|
|
|
|
case DialogExResultRight:
|
|
|
|
app->switch_to_previous_scene();
|
|
|
|
consumed = true;
|
|
|
|
break;
|
2022-02-18 20:16:22 +00:00
|
|
|
default:
|
|
|
|
break;
|
2022-02-16 11:09:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
if(event->type == InfraredAppEvent::Type::Back) {
|
2022-02-16 11:09:47 +00:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2022-05-06 13:37:10 +00:00
|
|
|
void InfraredAppSceneAskBack::on_exit(InfraredApp*) {
|
2022-02-16 11:09:47 +00:00
|
|
|
}
|