Skip to content

Commit 6cd3988

Browse files
committed
Updated labels, improved/simplified logic, and improved positioning
Use "Now" for the label until 31 seconds, then display the live time.
1 parent b542e26 commit 6cd3988

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/displayapp/screens/Weather.cpp

+21-10
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Weather::Weather(Controllers::Settings& settingsController,
5050
lastUpdated = lv_label_create(lv_scr_act(), nullptr);
5151
lv_obj_set_style_local_text_color(lastUpdated, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
5252
lv_label_set_text_fmt(lastUpdated, "");
53-
lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -40, -1);
5453

5554
minTemperature = lv_label_create(lv_scr_act(), nullptr);
5655
lv_obj_set_style_local_text_color(minTemperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
@@ -145,21 +144,33 @@ void Weather::Refresh() {
145144
lv_label_set_text_fmt(minTemperature, "%d°", minTemp);
146145
lv_label_set_text_fmt(maxTemperature, "%d°", maxTemp);
147146

148-
int64_t secondsSinceEpoch = dateTimeController.CurrentDateTime().time_since_epoch().count() / 1000000000;
149-
int64_t secondsSinceWeatherUpdate = secondsSinceEpoch - optCurrentWeather->timestamp;
150-
if (secondsSinceWeatherUpdate < 0) {
151-
lv_label_set_text_fmt(lastUpdated, "0s ago", secondsSinceWeatherUpdate);
152-
} else if (secondsSinceWeatherUpdate < 60) {
147+
std::chrono::seconds secondsSinceEpoch =
148+
std::chrono::duration_cast<std::chrono::seconds>(dateTimeController.CurrentDateTime().time_since_epoch());
149+
int32_t secondsSinceWeatherUpdate = secondsSinceEpoch.count() - optCurrentWeather->timestamp;
150+
int8_t minutesSinceWeatherUpdate = secondsSinceWeatherUpdate / 60;
151+
int8_t hoursSinceWeatherUpdate = secondsSinceWeatherUpdate / 3600;
152+
153+
lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -31, -1);
154+
if ((secondsSinceWeatherUpdate > 9 && secondsSinceWeatherUpdate < 60) ||
155+
(minutesSinceWeatherUpdate > 9 && minutesSinceWeatherUpdate < 60) || hoursSinceWeatherUpdate > 9) {
156+
lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -41, -1);
157+
}
158+
159+
if (hoursSinceWeatherUpdate > 0) {
160+
lv_label_set_text_fmt(lastUpdated, "%dh ago", hoursSinceWeatherUpdate);
161+
} else if (minutesSinceWeatherUpdate > 0) {
162+
lv_label_set_text_fmt(lastUpdated, "%dm ago", minutesSinceWeatherUpdate);
163+
} else if (secondsSinceWeatherUpdate > 30) {
153164
lv_label_set_text_fmt(lastUpdated, "%ds ago", secondsSinceWeatherUpdate);
154-
} else if (secondsSinceWeatherUpdate > 59 && secondsSinceWeatherUpdate < 3600) {
155-
lv_label_set_text_fmt(lastUpdated, "%dm ago", secondsSinceWeatherUpdate / 60);
156-
} else if (secondsSinceWeatherUpdate > 3599) {
157-
lv_label_set_text_fmt(lastUpdated, "%dh ago", secondsSinceWeatherUpdate / 3600);
165+
} else if (secondsSinceWeatherUpdate < 31) {
166+
lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -18, -1);
167+
lv_label_set_text_fmt(lastUpdated, "Now", secondsSinceWeatherUpdate);
158168
}
159169
} else {
160170
lv_label_set_text(icon, "");
161171
lv_label_set_text(condition, "");
162172
lv_label_set_text(temperature, "---");
173+
lv_label_set_text(lastUpdated, "");
163174
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
164175
lv_label_set_text(minTemperature, "");
165176
lv_label_set_text(maxTemperature, "");

0 commit comments

Comments
 (0)