2021-06-02 18:16:05 +03:00
|
|
|
#include "../irda-app.hpp"
|
|
|
|
#include "irda.h"
|
2021-06-09 16:04:49 +03:00
|
|
|
#include "irda/scene/irda-app-scene.hpp"
|
2021-06-02 18:16:05 +03:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
static void dialog_result_callback(DialogExResult result, void* context) {
|
|
|
|
auto app = static_cast<IrdaApp*>(context);
|
|
|
|
IrdaAppEvent event;
|
|
|
|
|
|
|
|
event.type = IrdaAppEvent::Type::DialogExSelected;
|
|
|
|
event.payload.dialog_ex_result = result;
|
|
|
|
|
|
|
|
app->get_view_manager()->send_event(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) {
|
|
|
|
IrdaAppViewManager* view_manager = app->get_view_manager();
|
|
|
|
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
|
|
|
|
|
|
|
auto remote_manager = app->get_remote_manager();
|
|
|
|
|
|
|
|
if(app->get_edit_element() == IrdaApp::EditElement::Button) {
|
2021-06-09 16:04:49 +03:00
|
|
|
auto message = remote_manager->get_button_data(app->get_current_button());
|
2021-06-02 18:16:05 +03:00
|
|
|
dialog_ex_set_header(dialog_ex, "Delete button?", 64, 6, AlignCenter, AlignCenter);
|
|
|
|
app->set_text_store(
|
|
|
|
0,
|
|
|
|
"%s\n%s\nA=0x%0*lX C=0x%0*lX",
|
2021-06-09 16:04:49 +03:00
|
|
|
remote_manager->get_button_name(app->get_current_button()).c_str(),
|
2021-06-02 18:16:05 +03:00
|
|
|
irda_get_protocol_name(message->protocol),
|
|
|
|
irda_get_protocol_address_length(message->protocol),
|
|
|
|
message->address,
|
|
|
|
irda_get_protocol_command_length(message->protocol),
|
|
|
|
message->command);
|
|
|
|
} else {
|
|
|
|
dialog_ex_set_header(dialog_ex, "Delete remote?", 64, 6, AlignCenter, AlignCenter);
|
|
|
|
app->set_text_store(
|
|
|
|
0,
|
|
|
|
"%s\n with %lu buttons",
|
2021-06-09 16:04:49 +03:00
|
|
|
remote_manager->get_remote_name().c_str(),
|
|
|
|
remote_manager->get_number_of_buttons());
|
2021-06-02 18:16:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dialog_ex_set_text(dialog_ex, app->get_text_store(0), 64, 32, AlignCenter, AlignCenter);
|
2021-07-07 11:57:49 +03:00
|
|
|
dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
|
2021-06-02 18:16:05 +03:00
|
|
|
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
|
|
|
dialog_ex_set_right_button_text(dialog_ex, "Delete");
|
|
|
|
dialog_ex_set_result_callback(dialog_ex, dialog_result_callback);
|
|
|
|
dialog_ex_set_context(dialog_ex, app);
|
|
|
|
|
|
|
|
view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppSceneEditDelete::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event->type == IrdaAppEvent::Type::DialogExSelected) {
|
|
|
|
switch(event->payload.dialog_ex_result) {
|
|
|
|
case DialogExResultLeft:
|
|
|
|
app->switch_to_previous_scene();
|
|
|
|
break;
|
|
|
|
case DialogExResultCenter:
|
|
|
|
furi_assert(0);
|
|
|
|
break;
|
|
|
|
case DialogExResultRight:
|
|
|
|
auto remote_manager = app->get_remote_manager();
|
2021-06-09 16:04:49 +03:00
|
|
|
bool result = false;
|
2021-06-02 18:16:05 +03:00
|
|
|
if(app->get_edit_element() == IrdaApp::EditElement::Remote) {
|
2021-06-09 16:04:49 +03:00
|
|
|
result = remote_manager->delete_remote();
|
2021-06-02 18:16:05 +03:00
|
|
|
} else {
|
2021-06-09 16:04:49 +03:00
|
|
|
result = remote_manager->delete_button(app->get_current_button());
|
|
|
|
app->set_current_button(IrdaApp::ButtonNA);
|
2021-06-02 18:16:05 +03:00
|
|
|
}
|
|
|
|
|
2021-06-09 16:04:49 +03:00
|
|
|
if(!result) {
|
|
|
|
app->search_and_switch_to_previous_scene(
|
|
|
|
{IrdaApp::Scene::RemoteList, IrdaApp::Scene::Start});
|
|
|
|
} else {
|
|
|
|
app->switch_to_next_scene(IrdaApp::Scene::EditDeleteDone);
|
|
|
|
}
|
2021-06-02 18:16:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneEditDelete::on_exit(IrdaApp* app) {
|
|
|
|
}
|