Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time since last weather update to weather app #2242

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed positioning
Move from `lv_obj_align` to `lv_obj_set_pos` to avoid weird positioning
errors when changing the position more than once.
  • Loading branch information
JustScott committed Feb 12, 2025
commit cb4e7d655b5fd867074755f82bc7f481acfffad4
24 changes: 17 additions & 7 deletions src/displayapp/screens/Weather.cpp
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ Weather::Weather(Controllers::Settings& settingsController,

lastUpdated = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(lastUpdated, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
lv_label_set_text_fmt(lastUpdated, "");
lv_label_set_text(lastUpdated, "");

minTemperature = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(minTemperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::bg);
@@ -150,20 +150,30 @@ void Weather::Refresh() {
int8_t minutesSinceWeatherUpdate = secondsSinceWeatherUpdate / 60;
int8_t hoursSinceWeatherUpdate = secondsSinceWeatherUpdate / 3600;

lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -31, -1);
if ((secondsSinceWeatherUpdate > 9 && secondsSinceWeatherUpdate < 60) ||
(minutesSinceWeatherUpdate > 9 && minutesSinceWeatherUpdate < 60) || hoursSinceWeatherUpdate > 9) {
lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -41, -1);
}
constexpr uint8_t Y_POSITION = 108;
constexpr uint8_t X_SINGLE_DIGIT_POSITION = 90;
constexpr uint8_t X_TWO_DIGIT_POSITION = 78;
constexpr uint8_t X_NOW_POSITION = 102;

lv_obj_set_pos(lastUpdated, X_SINGLE_DIGIT_POSITION, Y_POSITION);

if (hoursSinceWeatherUpdate > 0) {
if (hoursSinceWeatherUpdate > 9) {
lv_obj_set_pos(lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION);
}
lv_label_set_text_fmt(lastUpdated, "%dh ago", hoursSinceWeatherUpdate);
} else if (minutesSinceWeatherUpdate > 0) {
if (minutesSinceWeatherUpdate > 9 && minutesSinceWeatherUpdate < 60) {
lv_obj_set_pos(lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION);
}
lv_label_set_text_fmt(lastUpdated, "%dm ago", minutesSinceWeatherUpdate);
} else if (secondsSinceWeatherUpdate > 30) {
if (secondsSinceWeatherUpdate > 9 && secondsSinceWeatherUpdate < 60) {
lv_obj_set_pos(lastUpdated, X_TWO_DIGIT_POSITION, Y_POSITION);
}
lv_label_set_text_fmt(lastUpdated, "%ds ago", secondsSinceWeatherUpdate);
} else if (secondsSinceWeatherUpdate < 31) {
lv_obj_align(lastUpdated, nullptr, LV_ALIGN_CENTER, -18, -1);
lv_obj_set_pos(lastUpdated, X_NOW_POSITION, Y_POSITION);
lv_label_set_text_fmt(lastUpdated, "Now", secondsSinceWeatherUpdate);
}
} else {