2022-02-25 15:22:58 +00:00
|
|
|
#include "../infrared_app.h"
|
2021-06-09 13:04:49 +00:00
|
|
|
#include "gui/modules/submenu.h"
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
SubmenuIndexAddKey,
|
|
|
|
SubmenuIndexRenameKey,
|
|
|
|
SubmenuIndexDeleteKey,
|
|
|
|
SubmenuIndexRenameRemote,
|
|
|
|
SubmenuIndexDeleteRemote,
|
|
|
|
} SubmenuIndex;
|
|
|
|
|
|
|
|
static void submenu_callback(void* context, uint32_t index) {
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredApp* app = static_cast<InfraredApp*>(context);
|
|
|
|
InfraredAppEvent event;
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
event.type = InfraredAppEvent::Type::MenuSelected;
|
2021-06-02 15:16:05 +00:00
|
|
|
event.payload.menu_index = index;
|
|
|
|
|
|
|
|
app->get_view_manager()->send_event(&event);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppSceneEdit::on_enter(InfraredApp* app) {
|
|
|
|
InfraredAppViewManager* view_manager = app->get_view_manager();
|
2021-06-02 15:16:05 +00:00
|
|
|
Submenu* submenu = view_manager->get_submenu();
|
|
|
|
|
|
|
|
submenu_add_item(submenu, "Add key", SubmenuIndexAddKey, submenu_callback, app);
|
|
|
|
submenu_add_item(submenu, "Rename key", SubmenuIndexRenameKey, submenu_callback, app);
|
|
|
|
submenu_add_item(submenu, "Delete key", SubmenuIndexDeleteKey, submenu_callback, app);
|
|
|
|
submenu_add_item(submenu, "Rename remote", SubmenuIndexRenameRemote, submenu_callback, app);
|
|
|
|
submenu_add_item(submenu, "Delete remote", SubmenuIndexDeleteRemote, submenu_callback, app);
|
2021-06-09 13:04:49 +00:00
|
|
|
submenu_set_selected_item(submenu, submenu_item_selected);
|
|
|
|
submenu_item_selected = 0;
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
view_manager->switch_to(InfraredAppViewManager::ViewId::Submenu);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool InfraredAppSceneEdit::on_event(InfraredApp* app, InfraredAppEvent* event) {
|
2021-06-02 15:16:05 +00:00
|
|
|
bool consumed = false;
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
if(event->type == InfraredAppEvent::Type::MenuSelected) {
|
2021-06-09 13:04:49 +00:00
|
|
|
submenu_item_selected = event->payload.menu_index;
|
2021-06-02 15:16:05 +00:00
|
|
|
switch(event->payload.menu_index) {
|
|
|
|
case SubmenuIndexAddKey:
|
2021-06-09 13:04:49 +00:00
|
|
|
app->set_learn_new_remote(false);
|
2022-02-25 15:22:58 +00:00
|
|
|
app->switch_to_next_scene(InfraredApp::Scene::Learn);
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
|
|
|
case SubmenuIndexRenameKey:
|
2022-02-25 15:22:58 +00:00
|
|
|
app->set_edit_action(InfraredApp::EditAction::Rename);
|
|
|
|
app->set_edit_element(InfraredApp::EditElement::Button);
|
|
|
|
app->switch_to_next_scene(InfraredApp::Scene::EditKeySelect);
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
|
|
|
case SubmenuIndexDeleteKey:
|
2022-02-25 15:22:58 +00:00
|
|
|
app->set_edit_action(InfraredApp::EditAction::Delete);
|
|
|
|
app->set_edit_element(InfraredApp::EditElement::Button);
|
|
|
|
app->switch_to_next_scene(InfraredApp::Scene::EditKeySelect);
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
|
|
|
case SubmenuIndexRenameRemote:
|
2022-02-25 15:22:58 +00:00
|
|
|
app->set_edit_action(InfraredApp::EditAction::Rename);
|
|
|
|
app->set_edit_element(InfraredApp::EditElement::Remote);
|
|
|
|
app->switch_to_next_scene(InfraredApp::Scene::EditRename);
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
|
|
|
case SubmenuIndexDeleteRemote:
|
2022-02-25 15:22:58 +00:00
|
|
|
app->set_edit_action(InfraredApp::EditAction::Delete);
|
|
|
|
app->set_edit_element(InfraredApp::EditElement::Remote);
|
|
|
|
app->switch_to_next_scene(InfraredApp::Scene::EditDelete);
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppSceneEdit::on_exit(InfraredApp* app) {
|
|
|
|
InfraredAppViewManager* view_manager = app->get_view_manager();
|
2021-06-02 15:16:05 +00:00
|
|
|
Submenu* submenu = view_manager->get_submenu();
|
|
|
|
|
2022-01-21 17:32:03 +00:00
|
|
|
submenu_reset(submenu);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|