Skip to content

Commit 9204b56

Browse files
committed
Move the TemperatureColor function to the Temperature class in
SimpleWeatherService as the method `Color` for easier reusability.
1 parent 7b39d81 commit 9204b56

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/components/ble/SimpleWeatherService.h

+14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#undef min
3333

3434
#include "components/datetime/DateTimeController.h"
35+
#include <lvgl/lvgl.h>
36+
#include "displayapp/InfiniTimeTheme.h"
3537

3638
int WeatherCallback(uint16_t connHandle, uint16_t attrHandle, struct ble_gatt_access_ctxt* ctxt, void* arg);
3739

@@ -82,6 +84,18 @@ namespace Pinetime {
8284
return (PreciseFahrenheit() + 50) / 100;
8385
}
8486

87+
[[nodiscard]] lv_color_t Color() const {
88+
int16_t celsius = Celsius();
89+
if (celsius <= 0) { // freezing
90+
return Colors::blue;
91+
} else if (celsius <= 4) { // ice
92+
return LV_COLOR_CYAN;
93+
} else if (celsius >= 27) { // hot
94+
return Colors::deepOrange;
95+
}
96+
return Colors::orange; // normal
97+
}
98+
8599
bool operator==(const Temperature& other) const {
86100
return raw == other.raw;
87101
}

src/displayapp/screens/Weather.cpp

+1-15
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@
1212
using namespace Pinetime::Applications::Screens;
1313

1414
namespace {
15-
lv_color_t TemperatureColor(Pinetime::Controllers::SimpleWeatherService::Temperature temp) {
16-
if (temp.Celsius() <= 0) { // freezing
17-
return Colors::blue;
18-
} else if (temp.Celsius() <= 4) { // ice
19-
return LV_COLOR_CYAN;
20-
} else if (temp.Celsius() >= 27) { // hot
21-
return Colors::deepOrange;
22-
}
23-
return Colors::orange; // normal
24-
}
25-
2615
uint8_t TemperatureStyle(Pinetime::Controllers::SimpleWeatherService::Temperature temp) {
2716
if (temp.Celsius() <= 0) { // freezing
2817
return LV_TABLE_PART_CELL3;
@@ -128,10 +117,7 @@ void Weather::Refresh() {
128117
maxTemp = optCurrentWeather->maxTemperature.Fahrenheit();
129118
tempUnit = 'F';
130119
}
131-
lv_obj_set_style_local_text_color(temperature,
132-
LV_LABEL_PART_MAIN,
133-
LV_STATE_DEFAULT,
134-
TemperatureColor(optCurrentWeather->temperature));
120+
lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, optCurrentWeather->temperature.Color());
135121
lv_label_set_text(icon, Symbols::GetSymbol(optCurrentWeather->iconId));
136122
lv_label_set_text(condition, Symbols::GetCondition(optCurrentWeather->iconId));
137123
lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit);

0 commit comments

Comments
 (0)