2023-10-30 16:20:35 +00:00
|
|
|
#include "../infrared_app_i.h"
|
2023-08-02 03:43:36 +00:00
|
|
|
|
2023-10-30 16:20:35 +00:00
|
|
|
static void infrared_scene_edit_move_button_callback(
|
|
|
|
uint32_t index_old,
|
|
|
|
uint32_t index_new,
|
|
|
|
void* context) {
|
|
|
|
InfraredApp* infrared = context;
|
|
|
|
furi_assert(infrared);
|
|
|
|
|
|
|
|
infrared->app_state.prev_button_index = index_old;
|
|
|
|
infrared->app_state.current_button_index = index_new;
|
2023-08-07 09:18:46 +00:00
|
|
|
|
2023-10-30 16:20:35 +00:00
|
|
|
view_dispatcher_send_custom_event(
|
|
|
|
infrared->view_dispatcher, InfraredCustomEventTypeButtonSelected);
|
2023-08-02 03:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void infrared_scene_edit_move_on_enter(void* context) {
|
2023-10-30 16:20:35 +00:00
|
|
|
InfraredApp* infrared = context;
|
2023-08-02 03:43:36 +00:00
|
|
|
InfraredRemote* remote = infrared->remote;
|
|
|
|
|
2023-10-30 16:20:35 +00:00
|
|
|
for(size_t i = 0; i < infrared_remote_get_signal_count(remote); ++i) {
|
|
|
|
infrared_move_view_add_item(
|
|
|
|
infrared->move_view, infrared_remote_get_signal_name(remote, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
infrared_move_view_set_callback(
|
|
|
|
infrared->move_view, infrared_scene_edit_move_button_callback, infrared);
|
2023-08-02 03:43:36 +00:00
|
|
|
|
2023-10-30 16:20:35 +00:00
|
|
|
view_set_orientation(view_stack_get_view(infrared->view_stack), ViewOrientationHorizontal);
|
|
|
|
view_stack_add_view(infrared->view_stack, infrared_move_view_get_view(infrared->move_view));
|
2023-08-02 03:43:36 +00:00
|
|
|
|
2023-10-30 16:20:35 +00:00
|
|
|
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewStack);
|
2023-08-02 03:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool infrared_scene_edit_move_on_event(void* context, SceneManagerEvent event) {
|
2023-10-30 16:20:35 +00:00
|
|
|
InfraredApp* infrared = context;
|
2023-08-02 03:43:36 +00:00
|
|
|
bool consumed = false;
|
|
|
|
|
2023-10-30 16:20:35 +00:00
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == InfraredCustomEventTypeButtonSelected) {
|
|
|
|
infrared_show_loading_popup(infrared, true);
|
|
|
|
const bool button_moved = infrared_remote_move_signal(
|
|
|
|
infrared->remote,
|
|
|
|
infrared->app_state.prev_button_index,
|
|
|
|
infrared->app_state.current_button_index);
|
|
|
|
infrared_show_loading_popup(infrared, false);
|
|
|
|
|
|
|
|
if(!button_moved) {
|
|
|
|
infrared_show_error_message(
|
|
|
|
infrared,
|
|
|
|
"Failed to move\n\"%s\"",
|
|
|
|
infrared_remote_get_signal_name(
|
|
|
|
infrared->remote, infrared->app_state.current_button_index));
|
|
|
|
scene_manager_search_and_switch_to_previous_scene(
|
|
|
|
infrared->scene_manager, InfraredSceneRemoteList);
|
|
|
|
}
|
|
|
|
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
}
|
2023-08-02 03:43:36 +00:00
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void infrared_scene_edit_move_on_exit(void* context) {
|
2023-10-30 16:20:35 +00:00
|
|
|
InfraredApp* infrared = context;
|
|
|
|
view_stack_remove_view(infrared->view_stack, infrared_move_view_get_view(infrared->move_view));
|
|
|
|
infrared_move_view_reset(infrared->move_view);
|
2023-08-02 03:43:36 +00:00
|
|
|
}
|