Cleaned up redundant if statements, spacing
Removed redundant if statements in hour button logic. Spacing is now in line with repo guidelines.
This commit is contained in:
parent
698288d822
commit
2bc338ceed
2 changed files with 43 additions and 47 deletions
|
@ -24,9 +24,9 @@ namespace {
|
|||
}
|
||||
|
||||
SettingSetTime::SettingSetTime(
|
||||
Pinetime::Applications::DisplayApp *app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Controllers::Settings& settingsController)
|
||||
Pinetime::Applications::DisplayApp *app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Controllers::Settings& settingsController)
|
||||
: Screen(app),
|
||||
dateTimeController {dateTimeController},
|
||||
settingsController {settingsController} {
|
||||
|
@ -82,16 +82,16 @@ SettingSetTime::SettingSetTime(
|
|||
lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT - 40);
|
||||
lv_label_set_text_fmt(lblampm, "%02c", ampmValue);
|
||||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24)
|
||||
lv_label_set_text(lblampm, " ");
|
||||
lv_label_set_text(lblampm, " ");
|
||||
else {
|
||||
if (hoursValue > 11)
|
||||
if (hoursValue > 11)
|
||||
lv_label_set_text(lblampm, "PM");
|
||||
else
|
||||
lv_label_set_text(lblampm, "AM");
|
||||
if (hoursValue > 12)
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue-12);
|
||||
else if (hoursValue == 0)
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue+1);
|
||||
lv_label_set_text(lblampm, "AM");
|
||||
if (hoursValue > 12)
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue-12);
|
||||
else if (hoursValue == 0)
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue+1);
|
||||
}
|
||||
|
||||
btnHoursPlus = lv_btn_create(lv_scr_act(), nullptr);
|
||||
|
@ -135,20 +135,20 @@ SettingSetTime::~SettingSetTime() {
|
|||
}
|
||||
|
||||
int timeConvert(int time24H) {
|
||||
switch (time24H) {
|
||||
case 0:
|
||||
return 12;
|
||||
break;
|
||||
case 1 ... 12:
|
||||
return time24H;
|
||||
break;
|
||||
case 13 ... 23:
|
||||
return time24H - 12;
|
||||
break;
|
||||
default:
|
||||
return 99;
|
||||
break;
|
||||
}
|
||||
switch (time24H) {
|
||||
case 0:
|
||||
return 12;
|
||||
break;
|
||||
case 1 ... 12:
|
||||
return time24H;
|
||||
break;
|
||||
case 13 ... 23:
|
||||
return time24H - 12;
|
||||
break;
|
||||
default:
|
||||
return 99;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
||||
|
@ -156,41 +156,36 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
|||
return;
|
||||
|
||||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
|
||||
is24H = true;
|
||||
is24H = true;
|
||||
}
|
||||
else {
|
||||
is24H = false;
|
||||
is24H = false;
|
||||
}
|
||||
|
||||
if (object == btnHoursPlus) {
|
||||
hoursValue++;
|
||||
if (hoursValue > 23)
|
||||
hoursValue = 0;
|
||||
if (!is24H) {
|
||||
if (hoursValue < 12)
|
||||
lv_label_set_text(lblampm, "AM");
|
||||
else
|
||||
lv_label_set_text(lblampm, "PM");
|
||||
}
|
||||
if (!is24H)
|
||||
if (!is24H) {
|
||||
if (hoursValue < 12)
|
||||
lv_label_set_text(lblampm, "AM");
|
||||
else
|
||||
lv_label_set_text(lblampm, "PM");
|
||||
lv_label_set_text_fmt(lblHours, "%02d", timeConvert(hoursValue));
|
||||
else
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
} else
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
} else if (object == btnHoursMinus) {
|
||||
hoursValue--;
|
||||
if (hoursValue < 0)
|
||||
hoursValue = 23;
|
||||
if (!is24H) {
|
||||
if (hoursValue < 12)
|
||||
lv_label_set_text(lblampm, "AM");
|
||||
else
|
||||
lv_label_set_text(lblampm, "PM");
|
||||
}
|
||||
if (!is24H)
|
||||
if (!is24H) {
|
||||
if (hoursValue < 12)
|
||||
lv_label_set_text(lblampm, "AM");
|
||||
else
|
||||
lv_label_set_text(lblampm, "PM");
|
||||
lv_label_set_text_fmt(lblHours, "%02d", timeConvert(hoursValue));
|
||||
else
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
} else
|
||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
} else if (object == btnMinutesPlus) {
|
||||
minutesValue++;
|
||||
|
@ -217,3 +212,4 @@ void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
|
|||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ namespace Pinetime {
|
|||
class SettingSetTime : public Screen{
|
||||
public:
|
||||
SettingSetTime(DisplayApp* app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Controllers::Settings& settingsController);
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Controllers::Settings& settingsController);
|
||||
~SettingSetTime() override;
|
||||
|
||||
void HandleButtonPress(lv_obj_t *object, lv_event_t event);
|
||||
|
|
Loading…
Reference in a new issue