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