diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index ba1e2faed..c0112199c 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -207,16 +207,9 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReceiverDeleteItem: subghz->txrx->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); - if(subghz->txrx->idx_menu_chosen == 0) { - subghz_history_delete_item(subghz->txrx->history, subghz->txrx->idx_menu_chosen); - subghz_view_receiver_set_idx_menu( - subghz->subghz_receiver, subghz->txrx->idx_menu_chosen); - } else { - subghz_history_delete_item( - subghz->txrx->history, subghz->txrx->idx_menu_chosen + 1); - subghz_view_receiver_set_idx_menu( - subghz->subghz_receiver, subghz->txrx->idx_menu_chosen); - } + + subghz_history_delete_item(subghz->txrx->history, subghz->txrx->idx_menu_chosen); + subghz_view_receiver_delete_element_callback(subghz->subghz_receiver); subghz_scene_receiver_update_statusbar(subghz); consumed = true; diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 1df7d0238..f6530238e 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -92,14 +92,12 @@ void subghz_history_delete_item(SubGhzHistory* instance, uint16_t item_id) { furi_assert(instance); SubGhzHistoryItemArray_it_t it; - SubGhzHistoryItem* target_item = SubGhzHistoryItemArray_get(instance->history->data, item_id); + //SubGhzHistoryItem* target_item = SubGhzHistoryItemArray_get(instance->history->data, item_id); SubGhzHistoryItemArray_it_last(it, instance->history->data); while(!SubGhzHistoryItemArray_end_p(it)) { SubGhzHistoryItem* item = SubGhzHistoryItemArray_ref(it); - if(strcmp( - furi_string_get_cstr(item->item_str), - furi_string_get_cstr(target_item->item_str)) == 0) { + if(it->index == (size_t)(item_id)) { furi_string_free(item->item_str); furi_string_free(item->preset->name); free(item->preset); diff --git a/applications/main/subghz/views/receiver.c b/applications/main/subghz/views/receiver.c index 74c7d749b..71ff85448 100644 --- a/applications/main/subghz/views/receiver.c +++ b/applications/main/subghz/views/receiver.c @@ -434,44 +434,24 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) { { if(model->history_item != 0) { SubGhzReceiverMenuItemArray_it_t it; - SubGhzReceiverMenuItem* target_item = - SubGhzReceiverMenuItemArray_get(model->history->data, model->idx); + // SubGhzReceiverMenuItem* target_item = + // SubGhzReceiverMenuItemArray_get(model->history->data, model->idx); SubGhzReceiverMenuItemArray_it_last(it, model->history->data); while(!SubGhzReceiverMenuItemArray_end_p(it)) { SubGhzReceiverMenuItem* item = SubGhzReceiverMenuItemArray_ref(it); - if(strcmp( - furi_string_get_cstr(item->item_str), - furi_string_get_cstr(target_item->item_str)) == 0) { + if(it->index == (size_t)(model->idx)) { furi_string_free(item->item_str); item->type = 0; SubGhzReceiverMenuItemArray_remove(model->history->data, it); - if(model->history_item == 5) { - if(model->idx >= 2) { - model->idx = model->history_item - 1; - } - } - if(model->idx == model->history_item - 1) { - if(model->idx != 0) { - model->idx--; - } - } } SubGhzReceiverMenuItemArray_previous(it); } - } - }, - true); - with_view_model( - subghz_receiver->view, - SubGhzViewReceiverModel * model, - { - if(model->history_item != 0) { + // Callback subghz_receiver->callback( SubGhzCustomEventViewReceiverDeleteItem, subghz_receiver->context); - model->history_item--; } }, true); @@ -588,12 +568,33 @@ View* subghz_view_receiver_get_view(SubGhzViewReceiver* subghz_receiver) { uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver) { furi_assert(subghz_receiver); - uint32_t idx = 0; + uint16_t idx = 0; with_view_model( subghz_receiver->view, SubGhzViewReceiverModel * model, { idx = model->idx; }, false); return idx; } +void subghz_view_receiver_delete_element_callback(SubGhzViewReceiver* subghz_receiver) { + furi_assert(subghz_receiver); + + with_view_model( + subghz_receiver->view, + SubGhzViewReceiverModel * model, + { + if(model->history_item == 5) { + if(model->idx >= 2) { + model->idx = model->history_item - 1; + } + } + model->history_item--; + + if(model->idx != 0) { + model->idx--; + } + }, + true); +} + void subghz_view_receiver_set_idx_menu(SubGhzViewReceiver* subghz_receiver, uint16_t idx) { furi_assert(subghz_receiver); with_view_model( diff --git a/applications/main/subghz/views/receiver.h b/applications/main/subghz/views/receiver.h index 37eb473de..ad8c31eda 100644 --- a/applications/main/subghz/views/receiver.h +++ b/applications/main/subghz/views/receiver.h @@ -46,4 +46,6 @@ uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver); void subghz_view_receiver_set_idx_menu(SubGhzViewReceiver* subghz_receiver, uint16_t idx); +void subghz_view_receiver_delete_element_callback(SubGhzViewReceiver* subghz_receiver); + void subghz_view_receiver_exit(void* context);