mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-18 10:51:54 +03:00
Fix Subghz item removal bug
This commit is contained in:
parent
f676072e15
commit
d33b092a9d
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user