Improved UI and fixed a bug

This commit is contained in:
Avamander 2021-12-01 01:15:11 +02:00
parent c870f8ed30
commit 06b022fc4d
2 changed files with 31 additions and 10 deletions

View File

@ -29,6 +29,7 @@ namespace Pinetime {
WeatherService::WeatherService(System::SystemTask& system, DateTime& dateTimeController)
: system(system), dateTimeController(dateTimeController) {
nullHeader = &nullTimelineheader;
nullTimelineheader->timestamp = 0;
}
void WeatherService::Init() {
@ -211,7 +212,7 @@ namespace Pinetime {
}
}
return reinterpret_cast<std::unique_ptr<WeatherData::Clouds>&>(this->nullHeader);
return reinterpret_cast<std::unique_ptr<WeatherData::Clouds>&>(*this->nullHeader);
}
std::unique_ptr<WeatherData::Obscuration>& WeatherService::GetCurrentObscuration() {
@ -222,7 +223,7 @@ namespace Pinetime {
}
}
return reinterpret_cast<std::unique_ptr<WeatherData::Obscuration>&>(this->nullHeader);
return reinterpret_cast<std::unique_ptr<WeatherData::Obscuration>&>(*this->nullHeader);
}
std::unique_ptr<WeatherData::Precipitation>& WeatherService::GetCurrentPrecipitation() {
@ -233,7 +234,7 @@ namespace Pinetime {
}
}
return reinterpret_cast<std::unique_ptr<WeatherData::Precipitation>&>(this->nullHeader);
return reinterpret_cast<std::unique_ptr<WeatherData::Precipitation>&>(*this->nullHeader);
}
std::unique_ptr<WeatherData::Wind>& WeatherService::GetCurrentWind() {
@ -244,7 +245,7 @@ namespace Pinetime {
}
}
return reinterpret_cast<std::unique_ptr<WeatherData::Wind>&>(this->nullHeader);
return reinterpret_cast<std::unique_ptr<WeatherData::Wind>&>(*this->nullHeader);
}
std::unique_ptr<WeatherData::Temperature>& WeatherService::GetCurrentTemperature() {
@ -255,7 +256,7 @@ namespace Pinetime {
}
}
return reinterpret_cast<std::unique_ptr<WeatherData::Temperature>&>(this->nullHeader);
return reinterpret_cast<std::unique_ptr<WeatherData::Temperature>&>(*this->nullHeader);
}
std::unique_ptr<WeatherData::Humidity>& WeatherService::GetCurrentHumidity() {
@ -266,7 +267,7 @@ namespace Pinetime {
}
}
return reinterpret_cast<std::unique_ptr<WeatherData::Humidity>&>(this->nullHeader);
return reinterpret_cast<std::unique_ptr<WeatherData::Humidity>&>(*this->nullHeader);
}
std::unique_ptr<WeatherData::Pressure>& WeatherService::GetCurrentPressure() {
@ -277,7 +278,7 @@ namespace Pinetime {
}
}
return reinterpret_cast<std::unique_ptr<WeatherData::Pressure>&>(this->nullHeader);
return reinterpret_cast<std::unique_ptr<WeatherData::Pressure>&>(*this->nullHeader);
}
std::unique_ptr<WeatherData::Location>& WeatherService::GetCurrentLocation() {
@ -288,7 +289,7 @@ namespace Pinetime {
}
}
return reinterpret_cast<std::unique_ptr<WeatherData::Location>&>(this->nullHeader);
return reinterpret_cast<std::unique_ptr<WeatherData::Location>&>(*this->nullHeader);
}
std::unique_ptr<WeatherData::AirQuality>& WeatherService::GetCurrentQuality() {
@ -299,7 +300,7 @@ namespace Pinetime {
}
}
return reinterpret_cast<std::unique_ptr<WeatherData::AirQuality>&>(this->nullHeader);
return reinterpret_cast<std::unique_ptr<WeatherData::AirQuality>&>(*this->nullHeader);
}
size_t WeatherService::GetTimelineLength() const {
@ -330,7 +331,7 @@ namespace Pinetime {
timeline.erase(std::remove_if(std::begin(timeline),
std::end(timeline),
[&](std::unique_ptr<WeatherData::TimelineHeader> const& header) {
return isEventStillValid(header, timeCurrent);
return !isEventStillValid(header, timeCurrent);
}),
std::end(timeline));

View File

@ -74,6 +74,16 @@ std::unique_ptr<Screen> Weather::CreateScreenTemperature() {
std::unique_ptr<Controllers::WeatherData::Temperature>& current = weatherService.GetCurrentTemperature();
if (current->timestamp == 0) {
// Do not use the data, it's invalid
lv_label_set_text_fmt(label,
"#FFFF00 Temperature#\n\n"
"#444444 %d#\n\n"
"#444444 %d#\n\n"
"%d\n"
"%d\n",
0,
0,
0,
0);
} else {
lv_label_set_text_fmt(label,
"#FFFF00 Temperature#\n\n"
@ -97,6 +107,16 @@ std::unique_ptr<Screen> Weather::CreateScreenAir() {
std::unique_ptr<Controllers::WeatherData::AirQuality>& current = weatherService.GetCurrentQuality();
if (current->timestamp == 0) {
// Do not use the data, it's invalid
lv_label_set_text_fmt(label,
"#FFFF00 Air quality#\n\n"
"#444444 %s#\n"
"#444444 %d#\n\n"
"%d\n"
"%d\n",
"",
0,
0,
0);
} else {
lv_label_set_text_fmt(label,
"#FFFF00 Air quality#\n\n"