mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-18 19:01:47 +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:
|
case SubGhzCustomEventViewReceiverDeleteItem:
|
||||||
subghz->txrx->idx_menu_chosen =
|
subghz->txrx->idx_menu_chosen =
|
||||||
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver);
|
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_history_delete_item(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
|
||||||
subghz_view_receiver_set_idx_menu(
|
subghz_view_receiver_delete_element_callback(subghz->subghz_receiver);
|
||||||
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_scene_receiver_update_statusbar(subghz);
|
subghz_scene_receiver_update_statusbar(subghz);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
|
@ -92,14 +92,12 @@ void subghz_history_delete_item(SubGhzHistory* instance, uint16_t item_id) {
|
|||||||
furi_assert(instance);
|
furi_assert(instance);
|
||||||
|
|
||||||
SubGhzHistoryItemArray_it_t it;
|
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);
|
SubGhzHistoryItemArray_it_last(it, instance->history->data);
|
||||||
while(!SubGhzHistoryItemArray_end_p(it)) {
|
while(!SubGhzHistoryItemArray_end_p(it)) {
|
||||||
SubGhzHistoryItem* item = SubGhzHistoryItemArray_ref(it);
|
SubGhzHistoryItem* item = SubGhzHistoryItemArray_ref(it);
|
||||||
|
|
||||||
if(strcmp(
|
if(it->index == (size_t)(item_id)) {
|
||||||
furi_string_get_cstr(item->item_str),
|
|
||||||
furi_string_get_cstr(target_item->item_str)) == 0) {
|
|
||||||
furi_string_free(item->item_str);
|
furi_string_free(item->item_str);
|
||||||
furi_string_free(item->preset->name);
|
furi_string_free(item->preset->name);
|
||||||
free(item->preset);
|
free(item->preset);
|
||||||
|
@ -434,44 +434,24 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
|
|||||||
{
|
{
|
||||||
if(model->history_item != 0) {
|
if(model->history_item != 0) {
|
||||||
SubGhzReceiverMenuItemArray_it_t it;
|
SubGhzReceiverMenuItemArray_it_t it;
|
||||||
SubGhzReceiverMenuItem* target_item =
|
// SubGhzReceiverMenuItem* target_item =
|
||||||
SubGhzReceiverMenuItemArray_get(model->history->data, model->idx);
|
// SubGhzReceiverMenuItemArray_get(model->history->data, model->idx);
|
||||||
SubGhzReceiverMenuItemArray_it_last(it, model->history->data);
|
SubGhzReceiverMenuItemArray_it_last(it, model->history->data);
|
||||||
while(!SubGhzReceiverMenuItemArray_end_p(it)) {
|
while(!SubGhzReceiverMenuItemArray_end_p(it)) {
|
||||||
SubGhzReceiverMenuItem* item = SubGhzReceiverMenuItemArray_ref(it);
|
SubGhzReceiverMenuItem* item = SubGhzReceiverMenuItemArray_ref(it);
|
||||||
|
|
||||||
if(strcmp(
|
if(it->index == (size_t)(model->idx)) {
|
||||||
furi_string_get_cstr(item->item_str),
|
|
||||||
furi_string_get_cstr(target_item->item_str)) == 0) {
|
|
||||||
furi_string_free(item->item_str);
|
furi_string_free(item->item_str);
|
||||||
item->type = 0;
|
item->type = 0;
|
||||||
SubGhzReceiverMenuItemArray_remove(model->history->data, it);
|
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);
|
SubGhzReceiverMenuItemArray_previous(it);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
true);
|
|
||||||
|
|
||||||
with_view_model(
|
// Callback
|
||||||
subghz_receiver->view,
|
|
||||||
SubGhzViewReceiverModel * model,
|
|
||||||
{
|
|
||||||
if(model->history_item != 0) {
|
|
||||||
subghz_receiver->callback(
|
subghz_receiver->callback(
|
||||||
SubGhzCustomEventViewReceiverDeleteItem, subghz_receiver->context);
|
SubGhzCustomEventViewReceiverDeleteItem, subghz_receiver->context);
|
||||||
model->history_item--;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true);
|
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) {
|
uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver) {
|
||||||
furi_assert(subghz_receiver);
|
furi_assert(subghz_receiver);
|
||||||
uint32_t idx = 0;
|
uint16_t idx = 0;
|
||||||
with_view_model(
|
with_view_model(
|
||||||
subghz_receiver->view, SubGhzViewReceiverModel * model, { idx = model->idx; }, false);
|
subghz_receiver->view, SubGhzViewReceiverModel * model, { idx = model->idx; }, false);
|
||||||
return idx;
|
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) {
|
void subghz_view_receiver_set_idx_menu(SubGhzViewReceiver* subghz_receiver, uint16_t idx) {
|
||||||
furi_assert(subghz_receiver);
|
furi_assert(subghz_receiver);
|
||||||
with_view_model(
|
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_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);
|
void subghz_view_receiver_exit(void* context);
|
||||||
|
Loading…
Reference in New Issue
Block a user