Consolidated label changes, optimizations
Consolidated 12 hour label changes to function. Removed use of strings, struct.
This commit is contained in:
parent
5be2f57a78
commit
c8d998e82c
|
@ -2,7 +2,6 @@
|
||||||
#include <lvgl/lvgl.h>
|
#include <lvgl/lvgl.h>
|
||||||
#include <hal/nrf_rtc.h>
|
#include <hal/nrf_rtc.h>
|
||||||
#include <nrf_log.h>
|
#include <nrf_log.h>
|
||||||
#include <string.h>
|
|
||||||
#include "displayapp/DisplayApp.h"
|
#include "displayapp/DisplayApp.h"
|
||||||
#include "displayapp/screens/Symbols.h"
|
#include "displayapp/screens/Symbols.h"
|
||||||
#include "components/settings/Settings.h"
|
#include "components/settings/Settings.h"
|
||||||
|
@ -24,12 +23,7 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Time12H {
|
void set12HourLabels(int time24H, lv_obj_t* lblampm, lv_obj_t* lblHours);
|
||||||
std::string ampm;
|
|
||||||
int hours;
|
|
||||||
};
|
|
||||||
|
|
||||||
Time12H timeConvert(int time24H);
|
|
||||||
|
|
||||||
SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app,
|
SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app,
|
||||||
Pinetime::Controllers::DateTime& dateTimeController,
|
Pinetime::Controllers::DateTime& dateTimeController,
|
||||||
|
@ -123,13 +117,7 @@ SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app,
|
||||||
lv_obj_set_event_cb(btnSetTime, event_handler);
|
lv_obj_set_event_cb(btnSetTime, event_handler);
|
||||||
|
|
||||||
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
||||||
struct Time12H convertedTime = timeConvert(hoursValue);
|
set12HourLabels(hoursValue, lblampm, lblHours);
|
||||||
if (hoursValue < 12) {
|
|
||||||
lv_label_set_text_static(lblampm, "AM");
|
|
||||||
} else {
|
|
||||||
lv_label_set_text_static(lblampm, "PM");
|
|
||||||
}
|
|
||||||
lv_label_set_text_fmt(lblHours, "%02d", convertedTime.hours);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,45 +125,38 @@ SettingSetTime::~SettingSetTime() {
|
||||||
lv_obj_clean(lv_scr_act());
|
lv_obj_clean(lv_scr_act());
|
||||||
}
|
}
|
||||||
|
|
||||||
Time12H timeConvert(int time24H) {
|
void set12HourLabels(int time24H, lv_obj_t* lblampm, lv_obj_t* lblHours) {
|
||||||
struct Time12H time12H;
|
|
||||||
switch (time24H) {
|
switch (time24H) {
|
||||||
case 0:
|
case 0:
|
||||||
time12H.hours = 12;
|
lv_label_set_text_fmt(lblHours, "%02d", 12);
|
||||||
time12H.ampm = "AM";
|
lv_label_set_text_static(lblampm, "AM");
|
||||||
break;
|
break;
|
||||||
case 1 ... 11:
|
case 1 ... 11:
|
||||||
time12H.hours = time24H;
|
lv_label_set_text_fmt(lblHours, "%02d", time24H);
|
||||||
time12H.ampm = "AM";
|
lv_label_set_text_static(lblampm, "AM");
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
time12H.hours = 12;
|
lv_label_set_text_fmt(lblHours, "%02d", 12);
|
||||||
time12H.ampm = "PM";
|
lv_label_set_text_static(lblampm, "PM");
|
||||||
break;
|
break;
|
||||||
case 13 ... 23:
|
case 13 ... 23:
|
||||||
time12H.hours = time24H - 12;
|
lv_label_set_text_fmt(lblHours, "%02d", time24H - 12);
|
||||||
time12H.ampm = "PM";
|
lv_label_set_text_static(lblampm, "PM");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return time12H;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingSetTime::HandleButtonPress(lv_obj_t* object, lv_event_t event) {
|
void SettingSetTime::HandleButtonPress(lv_obj_t* object, lv_event_t event) {
|
||||||
bool is24H;
|
|
||||||
if (event != LV_EVENT_CLICKED)
|
if (event != LV_EVENT_CLICKED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
is24H = (settingsController.GetClockType() == Controllers::Settings::ClockType::H24);
|
|
||||||
|
|
||||||
if (object == btnHoursPlus) {
|
if (object == btnHoursPlus) {
|
||||||
hoursValue++;
|
hoursValue++;
|
||||||
if (hoursValue > 23) {
|
if (hoursValue > 23) {
|
||||||
hoursValue = 0;
|
hoursValue = 0;
|
||||||
}
|
}
|
||||||
struct Time12H convertedTime = timeConvert(hoursValue);
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
||||||
if (!is24H) {
|
set12HourLabels(hoursValue, lblampm, lblHours);
|
||||||
lv_label_set_text_static(lblampm, convertedTime.ampm.c_str());
|
|
||||||
lv_label_set_text_fmt(lblHours, "%02d", convertedTime.hours);
|
|
||||||
} else {
|
} else {
|
||||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||||
}
|
}
|
||||||
|
@ -185,10 +166,8 @@ void SettingSetTime::HandleButtonPress(lv_obj_t* object, lv_event_t event) {
|
||||||
if (hoursValue < 0) {
|
if (hoursValue < 0) {
|
||||||
hoursValue = 23;
|
hoursValue = 23;
|
||||||
}
|
}
|
||||||
struct Time12H convertedTime = timeConvert(hoursValue);
|
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
|
||||||
if (!is24H) {
|
set12HourLabels(hoursValue, lblampm, lblHours);
|
||||||
lv_label_set_text_static(lblampm, convertedTime.ampm.c_str());
|
|
||||||
lv_label_set_text_fmt(lblHours, "%02d", convertedTime.hours);
|
|
||||||
} else {
|
} else {
|
||||||
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user