fix for save freq and category position (#1120)

* fix for save freq and category position
* applying conversation fixes, and save keep freqs when changing category
This commit is contained in:
gullradriel 2023-06-07 18:05:12 +02:00 committed by GitHub
parent 0f28fefc82
commit 1406c81e03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 29 deletions

View File

@ -40,16 +40,10 @@ FreqManBaseView::FreqManBaseView(
// initialize // initialize
refresh_list(); refresh_list();
options_category.on_change = [this](size_t category_id, int32_t) { options_category.on_change = [this](size_t category_id, int32_t) {
if (on_change_category)
on_change_category(category_id);
};
// Default function
on_change_category = [this](int32_t category_id) {
change_category(category_id); change_category(category_id);
}; };
options_category.set_selected_index(current_category_id);
button_exit.on_select = [this, &nav](Button&) { button_exit.on_select = [this, &nav](Button&) {
nav.pop(); nav.pop();
@ -83,24 +77,19 @@ void FreqManBaseView::get_freqman_files() {
}; };
void FreqManBaseView::change_category(int32_t category_id) { void FreqManBaseView::change_category(int32_t category_id) {
if (!file_list.size()) return;
current_category_id = category_id; current_category_id = category_id;
if (file_list.empty()) return;
std::vector<freqman_entry>().swap(database); std::vector<freqman_entry>().swap(database);
if (!load_freqman_file(file_list[categories[current_category_id].second], database)) { if (!load_freqman_file(file_list[categories[category_id].second], database)) {
error_ = ERROR_ACCESS; error_ = ERROR_ACCESS;
} }
menu_view.set_db(database); menu_view.set_db(database);
text_empty.hidden(!database.empty());
menu_view.set_dirty(); menu_view.set_dirty();
if (!database.size()) { set_dirty();
if (on_refresh_widgets)
on_refresh_widgets(true);
} else {
if (on_refresh_widgets)
on_refresh_widgets(false);
}
} }
void FreqManBaseView::refresh_list() { void FreqManBaseView::refresh_list() {
@ -118,10 +107,6 @@ void FreqManBaseView::refresh_list() {
options_category.set_options(categories); options_category.set_options(categories);
if ((unsigned)current_category_id >= categories.size()) if ((unsigned)current_category_id >= categories.size())
current_category_id = categories.size() - 1; current_category_id = categories.size() - 1;
if (categories.size() > 0) {
options_category.set_selected_index(current_category_id);
}
} }
void FrequencySaveView::save_current_file() { void FrequencySaveView::save_current_file() {
@ -170,6 +155,11 @@ FrequencySaveView::FrequencySaveView(
button_save_timestamp.on_select = [this, &nav](Button&) { button_save_timestamp.on_select = [this, &nav](Button&) {
on_save_timestamp(); on_save_timestamp();
}; };
options_category.on_change = [this, value](size_t category_id, int32_t) {
change_category(category_id);
big_display.set(value);
};
} }
void FrequencyLoadView::refresh_widgets(const bool v) { void FrequencyLoadView::refresh_widgets(const bool v) {
@ -215,14 +205,14 @@ FrequencyLoadView::FrequencyLoadView(
void FrequencyManagerView::on_edit_freq(rf::Frequency f) { void FrequencyManagerView::on_edit_freq(rf::Frequency f) {
database[menu_view.get_index()].frequency_a = f; database[menu_view.get_index()].frequency_a = f;
save_freqman_file(file_list[categories[current_category_id].second], database); save_freqman_file(file_list[categories[current_category_id].second], database);
refresh_list(); change_category(current_category_id);
} }
void FrequencyManagerView::on_edit_desc(NavigationView& nav) { void FrequencyManagerView::on_edit_desc(NavigationView& nav) {
text_prompt(nav, desc_buffer, 28, [this](std::string& buffer) { text_prompt(nav, desc_buffer, 28, [this](std::string& buffer) {
database[menu_view.get_index()].description = buffer; database[menu_view.get_index()].description = buffer;
save_freqman_file(file_list[categories[current_category_id].second], database); save_freqman_file(file_list[categories[current_category_id].second], database);
refresh_list(); change_category(current_category_id);
}); });
} }
@ -231,21 +221,23 @@ void FrequencyManagerView::on_new_category(NavigationView& nav) {
File freqman_file; File freqman_file;
create_freqman_file(buffer, freqman_file); create_freqman_file(buffer, freqman_file);
refresh_list(); refresh_list();
change_category(current_category_id);
}); });
} }
void FrequencyManagerView::on_delete() { void FrequencyManagerView::on_delete() {
database.erase(database.begin() + menu_view.get_index()); database.erase(database.begin() + menu_view.get_index());
save_freqman_file(file_list[categories[current_category_id].second], database); save_freqman_file(file_list[categories[current_category_id].second], database);
refresh_list(); change_category(current_category_id);
} }
void FrequencyManagerView::refresh_widgets(const bool v) { void FrequencyManagerView::refresh_widgets(const bool v) {
button_edit_freq.hidden(v); button_edit_freq.hidden(v);
button_edit_desc.hidden(v); button_edit_desc.hidden(v);
button_delete.hidden(v); button_delete.hidden(v);
menu_view.hidden(v);
text_empty.hidden(!v); text_empty.hidden(!v);
menu_view.hidden(v);
menu_view.set_dirty();
labels.hidden(v); labels.hidden(v);
// display.fill_rectangle(menu_view.screen_rect(), Color::black()); // display.fill_rectangle(menu_view.screen_rect(), Color::black());
set_dirty(); set_dirty();
@ -270,9 +262,6 @@ FrequencyManagerView::FrequencyManagerView(
&button_edit_desc, &button_edit_desc,
&button_delete}); &button_delete});
refresh_list();
change_category(current_category_id);
menu_view.on_select = [this](FreqManUIList&) { menu_view.on_select = [this](FreqManUIList&) {
button_edit_freq.focus(); button_edit_freq.focus();
}; };

View File

@ -46,7 +46,6 @@ class FreqManBaseView : public View {
NavigationView& nav_; NavigationView& nav_;
freqman_error error_{NO_ERROR}; freqman_error error_{NO_ERROR};
options_t categories{}; options_t categories{};
std::function<void(int32_t category_id)> on_change_category{nullptr};
std::function<void(void)> on_select_frequency{nullptr}; std::function<void(void)> on_select_frequency{nullptr};
std::function<void(bool)> on_refresh_widgets{nullptr}; std::function<void(bool)> on_refresh_widgets{nullptr};