Skip to content

Commit 2a1f143

Browse files
committed
Create a Color function in SimpleWeatherService's Temperature class
Move the TemperatureColor function to SimpleWeatherService's Temperature class and rename it to Color for simple reuse across the code base.
1 parent 1bdf756 commit 2a1f143

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/components/ble/SimpleWeatherService.h

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <array>
2323
#include <memory>
2424

25+
#include <lvgl/lvgl.h>
26+
#include "displayapp/InfiniTimeTheme.h"
27+
2528
#define min // workaround: nimble's min/max macros conflict with libstdc++
2629
#define max
2730
#include <host/ble_gap.h>
@@ -86,6 +89,17 @@ namespace Pinetime {
8689
return raw == other.raw;
8790
}
8891

92+
[[nodiscard]] lv_color_t Color() const {
93+
if (Celsius() <= 0) { // freezing
94+
return Colors::blue;
95+
} else if (Celsius() <= 4) { // ice
96+
return LV_COLOR_CYAN;
97+
} else if (Celsius() >= 27) { // hot
98+
return Colors::deepOrange;
99+
}
100+
return Colors::orange; // normal
101+
}
102+
89103
private:
90104
int16_t raw;
91105
};

src/displayapp/screens/WatchFaceTerminal.cpp

+1-14
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@
1515

1616
using namespace Pinetime::Applications::Screens;
1717

18-
namespace {
19-
lv_color_t TemperatureColor(Pinetime::Controllers::SimpleWeatherService::Temperature temp) {
20-
if (temp.Celsius() <= 0) { // freezing
21-
return Colors::blue;
22-
} else if (temp.Celsius() <= 4) { // ice
23-
return LV_COLOR_CYAN;
24-
} else if (temp.Celsius() >= 27) { // hot
25-
return Colors::deepOrange;
26-
}
27-
return Colors::orange; // normal
28-
}
29-
}
30-
3118
WatchFaceTerminal::WatchFaceTerminal(Controllers::DateTime& dateTimeController,
3219
const Controllers::Battery& batteryController,
3320
const Controllers::Ble& bleController,
@@ -177,7 +164,7 @@ void WatchFaceTerminal::Refresh() {
177164
if (optCurrentWeather) {
178165
int16_t temp = optCurrentWeather->temperature.Celsius();
179166
char tempUnit = 'C';
180-
lv_obj_set_style_local_text_color(weather, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, TemperatureColor(optCurrentWeather->temperature));
167+
lv_obj_set_style_local_text_color(weather, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, optCurrentWeather->temperature.Color());
181168
if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) {
182169
temp = optCurrentWeather->temperature.Fahrenheit();
183170
tempUnit = 'F';

0 commit comments

Comments
 (0)