Skip to content

Commit

Permalink
better subghz history element removal
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Dec 21, 2023
1 parent 49b2a4d commit 8fa21c4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 44 deletions.
4 changes: 3 additions & 1 deletion applications/main/subghz/scenes/subghz_scene_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) {
subghz_view_receiver_disable_draw_callback(subghz->subghz_receiver);

subghz_history_delete_item(subghz->history, subghz->idx_menu_chosen);
subghz_view_receiver_delete_element_callback(subghz->subghz_receiver);
subghz_view_receiver_delete_item(
subghz->subghz_receiver,
subghz_view_receiver_get_idx_menu(subghz->subghz_receiver));
subghz_view_receiver_enable_draw_callback(subghz->subghz_receiver);

subghz_scene_receiver_update_statusbar(subghz);
Expand Down
27 changes: 10 additions & 17 deletions applications/main/subghz/subghz_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,19 @@ void subghz_history_reset(SubGhzHistory* instance) {
instance->code_last_hash_data = 0;
}

void subghz_history_delete_item(SubGhzHistory* instance, uint16_t item_id) {
void subghz_history_delete_item(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);

SubGhzHistoryItemArray_it_t it;
//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(it->index == (size_t)(item_id)) {
furi_string_free(item->item_str);
furi_string_free(item->preset->name);
free(item->preset);
flipper_format_free(item->flipper_string);
item->type = 0;
SubGhzHistoryItemArray_remove(instance->history->data, it);
}
SubGhzHistoryItemArray_previous(it);
if(idx < SubGhzHistoryItemArray_size(instance->history->data)) {
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
furi_string_free(item->item_str);
furi_string_free(item->preset->name);
free(item->preset);
flipper_format_free(item->flipper_string);
item->type = 0;
SubGhzHistoryItemArray_remove_v(instance->history->data, idx, idx + 1);
instance->last_index_write--;
}
instance->last_index_write--;
}

uint16_t subghz_history_get_item(SubGhzHistory* instance) {
Expand Down
2 changes: 1 addition & 1 deletion applications/main/subghz/subghz_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void subghz_history_free(SubGhzHistory* instance);
*/
void subghz_history_reset(SubGhzHistory* instance);

void subghz_history_delete_item(SubGhzHistory* instance, uint16_t item_id);
void subghz_history_delete_item(SubGhzHistory* instance, uint16_t idx);

/** Get frequency to history[idx]
*
Expand Down
40 changes: 16 additions & 24 deletions applications/main/subghz/views/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,40 +655,32 @@ uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver)
return idx;
}

void subghz_view_receiver_delete_element_callback(SubGhzViewReceiver* subghz_receiver) {
void subghz_view_receiver_delete_item(SubGhzViewReceiver* subghz_receiver, uint16_t idx) {
furi_assert(subghz_receiver);

with_view_model(
subghz_receiver->view,
SubGhzViewReceiverModel * model,
{
SubGhzReceiverMenuItemArray_it_t it;
// 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(it->index == (size_t)(model->idx)) {
furi_string_free(item->item_str);
furi_string_free(item->time);
item->type = 0;
SubGhzReceiverMenuItemArray_remove(model->history->data, it);
if(idx < SubGhzReceiverMenuItemArray_size(model->history->data)) {
SubGhzReceiverMenuItem* item =
SubGhzReceiverMenuItemArray_get(model->history->data, idx);
furi_string_free(item->item_str);
furi_string_free(item->time);
item->type = 0;
SubGhzReceiverMenuItemArray_remove_v(model->history->data, idx, idx + 1);

if(model->history_item == 5) {
if(model->idx >= 2) {
model->idx = model->history_item - 1;
}
}
model->history_item--;

SubGhzReceiverMenuItemArray_previous(it);
}

if(model->history_item == 5) {
if(model->idx >= 2) {
model->idx = model->history_item - 1;
if(model->idx && (model->idx > idx || model->idx == model->history_item)) {
model->idx--;
}
}
model->history_item--;

if(model->idx != 0) {
model->idx--;
}
},
true);
}
Expand Down
2 changes: 1 addition & 1 deletion applications/main/subghz/views/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ 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_delete_item(SubGhzViewReceiver* subghz_receiver, uint16_t idx);

void subghz_view_receiver_enable_draw_callback(SubGhzViewReceiver* subghz_receiver);

Expand Down

0 comments on commit 8fa21c4

Please sign in to comment.