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:
Eli Weiss 2022-01-03 18:13:47 -05:00 committed by JF
parent 698288d822
commit 2bc338ceed
2 changed files with 43 additions and 47 deletions

View file

@ -24,9 +24,9 @@ namespace {
} }
SettingSetTime::SettingSetTime( SettingSetTime::SettingSetTime(
Pinetime::Applications::DisplayApp *app, Pinetime::Applications::DisplayApp *app,
Pinetime::Controllers::DateTime& dateTimeController, Pinetime::Controllers::DateTime& dateTimeController,
Pinetime::Controllers::Settings& settingsController) Pinetime::Controllers::Settings& settingsController)
: Screen(app), : Screen(app),
dateTimeController {dateTimeController}, dateTimeController {dateTimeController},
settingsController {settingsController} { 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_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT - 40);
lv_label_set_text_fmt(lblampm, "%02c", ampmValue); lv_label_set_text_fmt(lblampm, "%02c", ampmValue);
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24)
lv_label_set_text(lblampm, " "); lv_label_set_text(lblampm, " ");
else { else {
if (hoursValue > 11) if (hoursValue > 11)
lv_label_set_text(lblampm, "PM"); lv_label_set_text(lblampm, "PM");
else else
lv_label_set_text(lblampm, "AM"); lv_label_set_text(lblampm, "AM");
if (hoursValue > 12) if (hoursValue > 12)
lv_label_set_text_fmt(lblHours, "%02d", hoursValue-12); lv_label_set_text_fmt(lblHours, "%02d", hoursValue-12);
else if (hoursValue == 0) else if (hoursValue == 0)
lv_label_set_text_fmt(lblHours, "%02d", hoursValue+1); lv_label_set_text_fmt(lblHours, "%02d", hoursValue+1);
} }
btnHoursPlus = lv_btn_create(lv_scr_act(), nullptr); btnHoursPlus = lv_btn_create(lv_scr_act(), nullptr);
@ -135,20 +135,20 @@ SettingSetTime::~SettingSetTime() {
} }
int timeConvert(int time24H) { int timeConvert(int time24H) {
switch (time24H) { switch (time24H) {
case 0: case 0:
return 12; return 12;
break; break;
case 1 ... 12: case 1 ... 12:
return time24H; return time24H;
break; break;
case 13 ... 23: case 13 ... 23:
return time24H - 12; return time24H - 12;
break; break;
default: default:
return 99; return 99;
break; break;
} }
} }
void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) { 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; return;
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
is24H = true; is24H = true;
} }
else { else {
is24H = false; is24H = false;
} }
if (object == btnHoursPlus) { if (object == btnHoursPlus) {
hoursValue++; hoursValue++;
if (hoursValue > 23) if (hoursValue > 23)
hoursValue = 0; hoursValue = 0;
if (!is24H) { if (!is24H) {
if (hoursValue < 12) if (hoursValue < 12)
lv_label_set_text(lblampm, "AM"); lv_label_set_text(lblampm, "AM");
else else
lv_label_set_text(lblampm, "PM"); lv_label_set_text(lblampm, "PM");
}
if (!is24H)
lv_label_set_text_fmt(lblHours, "%02d", timeConvert(hoursValue)); lv_label_set_text_fmt(lblHours, "%02d", timeConvert(hoursValue));
else } else
lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
} else if (object == btnHoursMinus) { } else if (object == btnHoursMinus) {
hoursValue--; hoursValue--;
if (hoursValue < 0) if (hoursValue < 0)
hoursValue = 23; hoursValue = 23;
if (!is24H) { if (!is24H) {
if (hoursValue < 12) if (hoursValue < 12)
lv_label_set_text(lblampm, "AM"); lv_label_set_text(lblampm, "AM");
else else
lv_label_set_text(lblampm, "PM"); lv_label_set_text(lblampm, "PM");
}
if (!is24H)
lv_label_set_text_fmt(lblHours, "%02d", timeConvert(hoursValue)); lv_label_set_text_fmt(lblHours, "%02d", timeConvert(hoursValue));
else } else
lv_label_set_text_fmt(lblHours, "%02d", hoursValue); lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
} else if (object == btnMinutesPlus) { } else if (object == btnMinutesPlus) {
minutesValue++; 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); lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED);
} }
} }
}

View file

@ -12,8 +12,8 @@ namespace Pinetime {
class SettingSetTime : public Screen{ class SettingSetTime : public Screen{
public: public:
SettingSetTime(DisplayApp* app, SettingSetTime(DisplayApp* app,
Pinetime::Controllers::DateTime& dateTimeController, Pinetime::Controllers::DateTime& dateTimeController,
Pinetime::Controllers::Settings& settingsController); Pinetime::Controllers::Settings& settingsController);
~SettingSetTime() override; ~SettingSetTime() override;
void HandleButtonPress(lv_obj_t *object, lv_event_t event); void HandleButtonPress(lv_obj_t *object, lv_event_t event);