2021-08-11 17:51:06 +00:00
|
|
|
#include "../irda-app.h"
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
void IrdaAppSceneEditRename::on_enter(IrdaApp* app) {
|
|
|
|
IrdaAppViewManager* view_manager = app->get_view_manager();
|
|
|
|
TextInput* text_input = view_manager->get_text_input();
|
2021-08-19 00:18:42 +00:00
|
|
|
size_t enter_name_length = 0;
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
auto remote_manager = app->get_remote_manager();
|
|
|
|
if(app->get_edit_element() == IrdaApp::EditElement::Button) {
|
2021-06-09 13:04:49 +00:00
|
|
|
furi_assert(app->get_current_button() != IrdaApp::ButtonNA);
|
|
|
|
auto button_name = remote_manager->get_button_name(app->get_current_button());
|
2021-08-19 00:18:42 +00:00
|
|
|
char* buffer_str = app->get_text_store(0);
|
|
|
|
size_t max_len = IrdaAppRemoteManager::max_button_name_length;
|
|
|
|
strncpy(buffer_str, button_name.c_str(), max_len);
|
|
|
|
buffer_str[max_len + 1] = 0;
|
|
|
|
enter_name_length = max_len;
|
|
|
|
text_input_set_header_text(text_input, "Name the key");
|
2021-06-02 15:16:05 +00:00
|
|
|
} else {
|
2021-06-09 13:04:49 +00:00
|
|
|
auto remote_name = remote_manager->get_remote_name();
|
2021-06-02 15:16:05 +00:00
|
|
|
strncpy(app->get_text_store(0), remote_name.c_str(), app->get_text_store_size());
|
2021-08-19 00:18:42 +00:00
|
|
|
enter_name_length = IrdaAppRemoteManager::max_remote_name_length;
|
|
|
|
text_input_set_header_text(text_input, "Name the remote");
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
text_input_set_result_callback(
|
|
|
|
text_input,
|
|
|
|
IrdaApp::text_input_callback,
|
|
|
|
app,
|
|
|
|
app->get_text_store(0),
|
2021-08-19 00:18:42 +00:00
|
|
|
enter_name_length,
|
2021-12-21 12:53:57 +00:00
|
|
|
true);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppSceneEditRename::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event->type == IrdaAppEvent::Type::TextEditDone) {
|
|
|
|
auto remote_manager = app->get_remote_manager();
|
2021-06-09 13:04:49 +00:00
|
|
|
bool result = false;
|
2021-06-02 15:16:05 +00:00
|
|
|
if(app->get_edit_element() == IrdaApp::EditElement::Button) {
|
2021-06-09 13:04:49 +00:00
|
|
|
result =
|
|
|
|
remote_manager->rename_button(app->get_current_button(), app->get_text_store(0));
|
|
|
|
app->set_current_button(IrdaApp::ButtonNA);
|
2021-06-02 15:16:05 +00:00
|
|
|
} else {
|
2021-06-09 13:04:49 +00:00
|
|
|
result = remote_manager->rename_remote(app->get_text_store(0));
|
|
|
|
}
|
|
|
|
if(!result) {
|
|
|
|
app->search_and_switch_to_previous_scene(
|
|
|
|
{IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList});
|
|
|
|
} else {
|
|
|
|
app->switch_to_next_scene_without_saving(IrdaApp::Scene::EditRenameDone);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneEditRename::on_exit(IrdaApp* app) {
|
|
|
|
}
|