[FL-2222] IR fixes (#994)

* Fix elements_multiline_text_aligned
* IR: fix delete menu
* IR: bold text on delete/saved
* IR: add safe back screen
* IR: don't clear text on rename
* Nfc,Infrared: update DialogEx usage

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Albert Kharisov
2022-02-16 15:09:47 +04:00
committed by GitHub
parent be500993a3
commit 07036cc0f5
12 changed files with 173 additions and 74 deletions

View File

@@ -33,6 +33,7 @@ public:
LearnSuccess,
LearnEnterName,
LearnDone,
AskBack,
Remote,
RemoteList,
Edit,
@@ -123,6 +124,7 @@ private:
{Scene::LearnSuccess, new IrdaAppSceneLearnSuccess()},
{Scene::LearnEnterName, new IrdaAppSceneLearnEnterName()},
{Scene::LearnDone, new IrdaAppSceneLearnDone()},
{Scene::AskBack, new IrdaAppSceneAskBack()},
{Scene::Remote, new IrdaAppSceneRemote()},
{Scene::RemoteList, new IrdaAppSceneRemoteList()},
{Scene::Edit, new IrdaAppSceneEdit()},

View File

@@ -89,6 +89,13 @@ private:
std::vector<std::string> remote_names;
};
class IrdaAppSceneAskBack : public IrdaAppScene {
public:
void on_enter(IrdaApp* app) final;
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
void on_exit(IrdaApp* app) final;
};
class IrdaAppSceneEdit : public IrdaAppScene {
public:
void on_enter(IrdaApp* app) final;

View File

@@ -0,0 +1,71 @@
#include "../irda_app.h"
#include "gui/modules/dialog_ex.h"
#include "irda.h"
#include "irda/scene/irda_app_scene.h"
#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 IrdaAppSceneAskBack::on_enter(IrdaApp* app) {
IrdaAppViewManager* view_manager = app->get_view_manager();
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);
view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx);
}
bool IrdaAppSceneAskBack::on_event(IrdaApp* app, IrdaAppEvent* event) {
bool consumed = false;
if(event->type == IrdaAppEvent::Type::DialogExSelected) {
switch(event->payload.dialog_ex_result) {
case DialogExResultLeft:
consumed = true;
if(app->get_learn_new_remote()) {
app->search_and_switch_to_previous_scene({IrdaApp::Scene::Start});
} else {
app->search_and_switch_to_previous_scene(
{IrdaApp::Scene::Edit, IrdaApp::Scene::Remote});
}
break;
case DialogExResultCenter:
furi_assert(0);
break;
case DialogExResultRight:
app->switch_to_previous_scene();
consumed = true;
break;
}
}
if(event->type == IrdaAppEvent::Type::Back) {
consumed = true;
}
return consumed;
}
void IrdaAppSceneAskBack::on_exit(IrdaApp* app) {
}

View File

@@ -21,7 +21,7 @@ void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) {
if(app->get_edit_element() == IrdaApp::EditElement::Button) {
auto signal = remote_manager->get_button_data(app->get_current_button());
dialog_ex_set_header(dialog_ex, "Delete button?", 64, 6, AlignCenter, AlignCenter);
dialog_ex_set_header(dialog_ex, "Delete button?", 64, 0, AlignCenter, AlignTop);
if(!signal.is_raw()) {
auto message = &signal.get_message();
app->set_text_store(
@@ -41,7 +41,7 @@ void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) {
signal.get_raw_signal().timings_cnt);
}
} else {
dialog_ex_set_header(dialog_ex, "Delete remote?", 64, 6, AlignCenter, AlignCenter);
dialog_ex_set_header(dialog_ex, "Delete remote?", 64, 0, AlignCenter, AlignTop);
app->set_text_store(
0,
"%s\n with %lu buttons",
@@ -49,7 +49,7 @@ void IrdaAppSceneEditDelete::on_enter(IrdaApp* app) {
remote_manager->get_number_of_buttons());
}
dialog_ex_set_text(dialog_ex, app->get_text_store(0), 64, 32, AlignCenter, AlignCenter);
dialog_ex_set_text(dialog_ex, app->get_text_store(0), 64, 31, AlignCenter, AlignCenter);
dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
dialog_ex_set_left_button_text(dialog_ex, "Back");
dialog_ex_set_right_button_text(dialog_ex, "Delete");

View File

@@ -5,7 +5,7 @@ void IrdaAppSceneEditDeleteDone::on_enter(IrdaApp* app) {
Popup* popup = view_manager->get_popup();
popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62);
popup_set_text(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
popup_set_header(popup, "Deleted", 83, 19, AlignLeft, AlignBottom);
popup_set_callback(popup, IrdaApp::popup_callback);
popup_set_context(popup, app);
@@ -32,4 +32,7 @@ bool IrdaAppSceneEditDeleteDone::on_event(IrdaApp* app, IrdaAppEvent* event) {
}
void IrdaAppSceneEditDeleteDone::on_exit(IrdaApp* app) {
IrdaAppViewManager* view_manager = app->get_view_manager();
Popup* popup = view_manager->get_popup();
popup_set_header(popup, nullptr, 0, 0, AlignLeft, AlignTop);
}

View File

@@ -32,7 +32,7 @@ void IrdaAppSceneEditRename::on_enter(IrdaApp* app) {
app,
app->get_text_store(0),
enter_name_length,
true);
false);
view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput);
}

View File

@@ -69,4 +69,7 @@ bool IrdaAppSceneLearn::on_event(IrdaApp* app, IrdaAppEvent* event) {
void IrdaAppSceneLearn::on_exit(IrdaApp* app) {
irda_worker_rx_stop(app->get_irda_worker());
auto view_manager = app->get_view_manager();
auto popup = view_manager->get_popup();
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignCenter);
}

View File

@@ -9,9 +9,9 @@ void IrdaAppSceneLearnDone::on_enter(IrdaApp* app) {
DOLPHIN_DEED(DolphinDeedIrSave);
if(app->get_learn_new_remote()) {
popup_set_text(popup, "New remote\ncreated!", 5, 7, AlignLeft, AlignTop);
popup_set_header(popup, "New remote\ncreated!", 0, 0, AlignLeft, AlignTop);
} else {
popup_set_text(popup, "Saved!", 5, 7, AlignLeft, AlignTop);
popup_set_header(popup, "Saved!", 5, 7, AlignLeft, AlignTop);
}
popup_set_callback(popup, IrdaApp::popup_callback);
@@ -35,4 +35,7 @@ bool IrdaAppSceneLearnDone::on_event(IrdaApp* app, IrdaAppEvent* event) {
void IrdaAppSceneLearnDone::on_exit(IrdaApp* app) {
app->set_learn_new_remote(false);
IrdaAppViewManager* view_manager = app->get_view_manager();
Popup* popup = view_manager->get_popup();
popup_set_header(popup, nullptr, 0, 0, AlignLeft, AlignTop);
}

View File

@@ -91,12 +91,17 @@ bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) {
}
}
if(event->type == IrdaAppEvent::Type::Back) {
app->switch_to_next_scene(IrdaApp::Scene::AskBack);
consumed = true;
}
return consumed;
}
void IrdaAppSceneLearnSuccess::on_exit(IrdaApp* app) {
IrdaAppViewManager* view_manager = app->get_view_manager();
DialogEx* dialog_ex = view_manager->get_dialog_ex();
dialog_ex_set_center_button_text(dialog_ex, nullptr);
dialog_ex_reset(dialog_ex);
app->notify_green_off();
}