From 02e94acf185aa271e4b3773251efc3108c555fe2 Mon Sep 17 00:00:00 2001 From: Eli Weiss Date: Tue, 11 Jan 2022 16:23:49 -0500 Subject: [PATCH] Corrected code formatting Corrected formatting and removed unnecessary variable time24H --- .../screens/settings/SettingSetTime.cpp | 31 +++++++++++++++++-- .../screens/settings/SettingSetTime.h | 27 ++-------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/displayapp/screens/settings/SettingSetTime.cpp b/src/displayapp/screens/settings/SettingSetTime.cpp index b6d64dd3..fd0a8a3a 100644 --- a/src/displayapp/screens/settings/SettingSetTime.cpp +++ b/src/displayapp/screens/settings/SettingSetTime.cpp @@ -114,13 +114,38 @@ SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app, lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set"); lv_obj_set_event_cb(btnSetTime, event_handler); - setHourLabels(hoursValue); + setHourLabels(); } SettingSetTime::~SettingSetTime() { lv_obj_clean(lv_scr_act()); } +void SettingSetTime::setHourLabels() { + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { + switch (hoursValue) { + case 0: + lv_label_set_text_static(lblHours, "12"); + lv_label_set_text_static(lblampm, "AM"); + break; + case 1 ... 11: + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + lv_label_set_text_static(lblampm, "AM"); + break; + case 12: + lv_label_set_text_static(lblHours, "12"); + lv_label_set_text_static(lblampm, "PM"); + break; + case 13 ... 23: + lv_label_set_text_fmt(lblHours, "%02d", hoursValue - 12); + lv_label_set_text_static(lblampm, "PM"); + break; + } + } else { + lv_label_set_text_fmt(lblHours, "%02d", hoursValue); + } +} + void SettingSetTime::HandleButtonPress(lv_obj_t* object, lv_event_t event) { if (event != LV_EVENT_CLICKED) return; @@ -130,14 +155,14 @@ void SettingSetTime::HandleButtonPress(lv_obj_t* object, lv_event_t event) { if (hoursValue > 23) { hoursValue = 0; } - setHourLabels(hoursValue); + setHourLabels(); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnHoursMinus) { hoursValue--; if (hoursValue < 0) { hoursValue = 23; } - setHourLabels(hoursValue); + setHourLabels(); lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED); } else if (object == btnMinutesPlus) { minutesValue++; diff --git a/src/displayapp/screens/settings/SettingSetTime.h b/src/displayapp/screens/settings/SettingSetTime.h index cc4e4692..28515686 100644 --- a/src/displayapp/screens/settings/SettingSetTime.h +++ b/src/displayapp/screens/settings/SettingSetTime.h @@ -22,6 +22,8 @@ namespace Pinetime { Controllers::DateTime& dateTimeController; Controllers::Settings& settingsController; + void setHourLabels(); + int hoursValue; int minutesValue; lv_obj_t* lblHours; @@ -32,31 +34,6 @@ namespace Pinetime { lv_obj_t* btnMinutesPlus; lv_obj_t* btnMinutesMinus; lv_obj_t* btnSetTime; - - void setHourLabels(int time24H) { - switch (time24H) { - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { - case 0: - lv_label_set_text_static(lblHours, "12"); - lv_label_set_text_static(lblampm, "AM"); - break; - case 1 ... 11: - lv_label_set_text_fmt(lblHours, "%02d", time24H); - lv_label_set_text_static(lblampm, "AM"); - break; - case 12: - lv_label_set_text_static(lblHours, "12"); - lv_label_set_text_static(lblampm, "PM"); - break; - case 13 ... 23: - lv_label_set_text_fmt(lblHours, "%02d", time24H - 12); - lv_label_set_text_static(lblampm, "PM"); - break; - } else { - lv_label_set_text_fmt(lblHours, "%02d", hoursValue); - } - } - } }; } }