Skip to content

Commit 06dfe14

Browse files
committed
Code optimizations in SettingSetTime
1 parent f78c9bf commit 06dfe14

1 file changed

Lines changed: 10 additions & 24 deletions

File tree

src/displayapp/screens/settings/SettingSetTime.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@ SettingSetTime::SettingSetTime(
1919
Screen(app),
2020
dateTimeController {dateTimeController}
2121
{
22-
23-
lv_obj_t * container1 = lv_cont_create(lv_scr_act(), nullptr);
24-
25-
//lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
26-
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
27-
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
28-
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
29-
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
30-
lv_obj_set_pos(container1, 30, 60);
31-
lv_obj_set_width(container1, LV_HOR_RES - 50);
32-
lv_obj_set_height(container1, LV_VER_RES - 60);
33-
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
34-
3522
lv_obj_t * title = lv_label_create(lv_scr_act(), NULL);
3623
lv_label_set_text_static(title, "Set current time");
3724
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
@@ -106,8 +93,8 @@ SettingSetTime::SettingSetTime(
10693

10794
btnSetTime = lv_btn_create(lv_scr_act(), NULL);
10895
btnSetTime->user_data = this;
109-
lv_obj_set_size(btnSetTime, 70, 40);
110-
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_CENTER, 0, 90);
96+
lv_obj_set_size(btnSetTime, 120, 48);
97+
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
11198
lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
11299
lv_obj_set_event_cb(btnSetTime, event_handler);
113100
}
@@ -123,43 +110,42 @@ bool SettingSetTime::Refresh() {
123110

124111
void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
125112

126-
if(object == btnHoursPlus && (event == LV_EVENT_PRESSED)) {
113+
if (event != LV_EVENT_CLICKED)
114+
return;
115+
116+
if (object == btnHoursPlus) {
127117
hoursValue++;
128118
if (hoursValue > 23)
129119
hoursValue = 0;
130120
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
131121
lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6);
132122
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
133123
}
134-
135-
if(object == btnHoursMinus && (event == LV_EVENT_PRESSED)) {
124+
else if (object == btnHoursMinus) {
136125
hoursValue--;
137126
if (hoursValue < 0)
138127
hoursValue = 23;
139128
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
140129
lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, -72, -6);
141130
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
142131
}
143-
144-
if(object == btnMinutesPlus && (event == LV_EVENT_PRESSED)) {
132+
else if (object == btnMinutesPlus) {
145133
minutesValue++;
146134
if (minutesValue > 59)
147135
minutesValue = 0;
148136
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
149137
lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6);
150138
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
151139
}
152-
153-
if(object == btnMinutesMinus && (event == LV_EVENT_PRESSED)) {
140+
else if (object == btnMinutesMinus) {
154141
minutesValue--;
155142
if (minutesValue < 0)
156143
minutesValue = 59;
157144
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
158145
lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, 0, -6);
159146
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
160147
}
161-
162-
if(object == btnSetTime && (event == LV_EVENT_PRESSED)) {
148+
else if (object == btnSetTime) {
163149
NRF_LOG_INFO("Setting time (manually) to %02d:%02d:00", hoursValue, minutesValue);
164150
dateTimeController.SetTime(dateTimeController.Year(),
165151
static_cast<uint8_t>(dateTimeController.Month()),

0 commit comments

Comments
 (0)