Skip to content

Commit f78c9bf

Browse files
committed
Code optimizations in SettingSetDate
1 parent 5ae4192 commit f78c9bf

1 file changed

Lines changed: 12 additions & 28 deletions

File tree

src/displayapp/screens/settings/SettingSetDate.cpp

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ SettingSetDate::SettingSetDate(
2626
Screen(app),
2727
dateTimeController {dateTimeController}
2828
{
29-
30-
lv_obj_t * container1 = lv_cont_create(lv_scr_act(), nullptr);
31-
32-
//lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
33-
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
34-
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
35-
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
36-
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
37-
lv_obj_set_pos(container1, 30, 60);
38-
lv_obj_set_width(container1, LV_HOR_RES - 50);
39-
lv_obj_set_height(container1, LV_VER_RES - 60);
40-
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
41-
4229
lv_obj_t * title = lv_label_create(lv_scr_act(), NULL);
4330
lv_label_set_text_static(title, "Set current date");
4431
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
@@ -116,8 +103,8 @@ SettingSetDate::SettingSetDate(
116103

117104
btnSetTime = lv_btn_create(lv_scr_act(), NULL);
118105
btnSetTime->user_data = this;
119-
lv_obj_set_size(btnSetTime, 70, 40);
120-
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90);
106+
lv_obj_set_size(btnSetTime, 120, 48);
107+
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
121108
lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
122109
lv_obj_set_event_cb(btnSetTime, event_handler);
123110
}
@@ -133,59 +120,56 @@ bool SettingSetDate::Refresh() {
133120

134121
void SettingSetDate::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
135122

136-
if(object == btnDayPlus && (event == LV_EVENT_PRESSED)) {
123+
if (event != LV_EVENT_CLICKED)
124+
return;
125+
126+
if (object == btnDayPlus) {
137127
dayValue++;
138128
if (dayValue > MaximumDayOfMonth())
139129
dayValue = 1;
140130
lv_label_set_text_fmt(lblDay, "%d", dayValue);
141131
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
142132
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
143133
}
144-
145-
if(object == btnDayMinus && (event == LV_EVENT_PRESSED)) {
134+
else if (object == btnDayMinus) {
146135
dayValue--;
147136
if (dayValue < 1)
148137
dayValue = MaximumDayOfMonth();
149138
lv_label_set_text_fmt(lblDay, "%d", dayValue);
150139
lv_obj_align(lblDay, lv_scr_act(), LV_ALIGN_CENTER, POS_X_DAY, POS_Y_TEXT);
151140
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
152141
}
153-
154-
if(object == btnMonthPlus && (event == LV_EVENT_PRESSED)) {
142+
else if (object == btnMonthPlus) {
155143
monthValue++;
156144
if (monthValue > 12)
157145
monthValue = 1;
158146
UpdateMonthLabel();
159147
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
160148
CheckDay();
161149
}
162-
163-
if(object == btnMonthMinus && (event == LV_EVENT_PRESSED)) {
150+
else if (object == btnMonthMinus) {
164151
monthValue--;
165152
if (monthValue < 1)
166153
monthValue = 12;
167154
UpdateMonthLabel();
168155
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
169156
CheckDay();
170157
}
171-
172-
if(object == btnYearPlus && (event == LV_EVENT_PRESSED)) {
158+
else if (object == btnYearPlus) {
173159
yearValue++;
174160
lv_label_set_text_fmt(lblYear, "%d", yearValue);
175161
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
176162
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
177163
CheckDay();
178164
}
179-
180-
if(object == btnYearMinus && (event == LV_EVENT_PRESSED)) {
165+
else if (object == btnYearMinus) {
181166
yearValue--;
182167
lv_label_set_text_fmt(lblYear, "%d", yearValue);
183168
lv_obj_align(lblYear, lv_scr_act(), LV_ALIGN_CENTER, POS_X_YEAR, POS_Y_TEXT);
184169
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
185170
CheckDay();
186171
}
187-
188-
if(object == btnSetTime && (event == LV_EVENT_PRESSED)) {
172+
else if (object == btnSetTime) {
189173
NRF_LOG_INFO("Setting date (manually) to %04d-%02d-%02d", yearValue, monthValue, dayValue);
190174
dateTimeController.SetTime(static_cast<uint16_t>(yearValue),
191175
static_cast<uint8_t>(monthValue),

0 commit comments

Comments
 (0)