Simplify SettingChimes code
This commit is contained in:
parent
a1385cb481
commit
d55ec42b17
|
@ -14,6 +14,8 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr std::array<SettingChimes::Option, 3> SettingChimes::options;
|
||||||
|
|
||||||
SettingChimes::SettingChimes(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
|
SettingChimes::SettingChimes(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
|
||||||
: Screen(app), settingsController {settingsController} {
|
: Screen(app), settingsController {settingsController} {
|
||||||
|
|
||||||
|
@ -40,37 +42,16 @@ SettingChimes::SettingChimes(Pinetime::Applications::DisplayApp* app, Pinetime::
|
||||||
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
||||||
|
|
||||||
optionsTotal = 0;
|
for (unsigned int i = 0; i < options.size(); i++) {
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
cbOption[i] = lv_checkbox_create(container1, nullptr);
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Off");
|
lv_checkbox_set_text(cbOption[i], options[i].name);
|
||||||
cbOption[optionsTotal]->user_data = this;
|
if (settingsController.GetChimeOption() == options[i].chimesOption) {
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
lv_checkbox_set_checked(cbOption[i], true);
|
||||||
SetRadioButtonStyle(cbOption[optionsTotal]);
|
|
||||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::None) {
|
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
|
||||||
}
|
}
|
||||||
|
cbOption[i]->user_data = this;
|
||||||
optionsTotal++;
|
lv_obj_set_event_cb(cbOption[i], event_handler);
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
SetRadioButtonStyle(cbOption[i]);
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Every hour");
|
|
||||||
cbOption[optionsTotal]->user_data = this;
|
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
|
||||||
SetRadioButtonStyle(cbOption[optionsTotal]);
|
|
||||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours) {
|
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
optionsTotal++;
|
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Every 30 mins");
|
|
||||||
cbOption[optionsTotal]->user_data = this;
|
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
|
||||||
SetRadioButtonStyle(cbOption[optionsTotal]);
|
|
||||||
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours) {
|
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
|
||||||
}
|
|
||||||
|
|
||||||
optionsTotal++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingChimes::~SettingChimes() {
|
SettingChimes::~SettingChimes() {
|
||||||
|
@ -80,18 +61,10 @@ SettingChimes::~SettingChimes() {
|
||||||
|
|
||||||
void SettingChimes::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
void SettingChimes::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||||
if (event == LV_EVENT_VALUE_CHANGED) {
|
if (event == LV_EVENT_VALUE_CHANGED) {
|
||||||
for (uint8_t i = 0; i < optionsTotal; i++) {
|
for (uint8_t i = 0; i < options.size(); i++) {
|
||||||
if (object == cbOption[i]) {
|
if (object == cbOption[i]) {
|
||||||
lv_checkbox_set_checked(cbOption[i], true);
|
lv_checkbox_set_checked(cbOption[i], true);
|
||||||
if (i == 0) {
|
settingsController.SetChimeOption(options[i].chimesOption);
|
||||||
settingsController.SetChimeOption(Controllers::Settings::ChimesOption::None);
|
|
||||||
}
|
|
||||||
if (i == 1) {
|
|
||||||
settingsController.SetChimeOption(Controllers::Settings::ChimesOption::Hours);
|
|
||||||
}
|
|
||||||
if (i == 2) {
|
|
||||||
settingsController.SetChimeOption(Controllers::Settings::ChimesOption::HalfHours);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
lv_checkbox_set_checked(cbOption[i], false);
|
lv_checkbox_set_checked(cbOption[i], false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <lvgl/lvgl.h>
|
#include <lvgl/lvgl.h>
|
||||||
#include "components/settings/Settings.h"
|
#include "components/settings/Settings.h"
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
|
|
||||||
|
@ -12,15 +13,26 @@ namespace Pinetime {
|
||||||
|
|
||||||
class SettingChimes : public Screen {
|
class SettingChimes : public Screen {
|
||||||
public:
|
public:
|
||||||
|
struct Option {
|
||||||
|
Controllers::Settings::ChimesOption chimesOption;
|
||||||
|
const char* name;
|
||||||
|
};
|
||||||
|
|
||||||
SettingChimes(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
|
SettingChimes(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
|
||||||
~SettingChimes() override;
|
~SettingChimes() override;
|
||||||
|
|
||||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr std::array<Option, 3> options = {{
|
||||||
|
{Controllers::Settings::ChimesOption::None, " Off"},
|
||||||
|
{Controllers::Settings::ChimesOption::Hours, " Every hour"},
|
||||||
|
{Controllers::Settings::ChimesOption::HalfHours, " Every 30 mins"}
|
||||||
|
}};
|
||||||
|
|
||||||
|
lv_obj_t* cbOption[options.size()];
|
||||||
|
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
uint8_t optionsTotal;
|
|
||||||
lv_obj_t* cbOption[3];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue