From c31f4e7c8232a892d0a5f023f1a6674ecd479141 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sun, 9 Nov 2025 09:52:27 +0100 Subject: [PATCH] Pebble TimeStyle: support night icons finally --- .../AppMessageHandlerTimeStylePebble.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java index f6ade074db..9d8b78c332 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/AppMessageHandlerTimeStylePebble.java @@ -30,8 +30,8 @@ import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; -import nodomain.freeyourgadget.gadgetbridge.model.weather.Weather; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; +import nodomain.freeyourgadget.gadgetbridge.model.weather.Weather; import nodomain.freeyourgadget.gadgetbridge.util.GB; class AppMessageHandlerTimeStylePebble extends AppMessageHandler { @@ -70,7 +70,7 @@ class AppMessageHandlerTimeStylePebble extends AppMessageHandler { } } } catch (JSONException e) { - GB.toast("There was an error accessing the timestyle watchface configuration.", Toast.LENGTH_LONG, GB.ERROR, e); + GB.toast("There was an error accessing the TimeStyle watchface configuration.", Toast.LENGTH_LONG, GB.ERROR, e); } catch (IOException ignore) { } } @@ -136,19 +136,24 @@ class AppMessageHandlerTimeStylePebble extends AppMessageHandler { } ArrayList> pairs = new ArrayList<>(); - boolean isNight = false; //TODO: use the night icons when night - pairs.add(new Pair<>(messageKeys.get("SettingUseMetric"), (Object) 1)); //celsius - pairs.add(new Pair<>(messageKeys.get("WeatherUseNightIcon"), (Object) (isNight ? 1 : 0))); - pairs.add(new Pair<>(messageKeys.get("WeatherTemperature"), (Object) (weatherSpec.getCurrentTemp() - 273))); - pairs.add(new Pair<>(messageKeys.get("WeatherCondition"), (Object) (getIconForConditionCode(weatherSpec.getCurrentConditionCode(), isNight)))); - if (weatherSpec.getForecasts().size() > 0) { - WeatherSpec.Daily tomorrow = weatherSpec.getForecasts().get(0); - pairs.add(new Pair<>(messageKeys.get("WeatherForecastCondition"), (Object) (getIconForConditionCode(tomorrow.getConditionCode(), isNight)))); + boolean isNight = false; + if (weatherSpec.getSunRise() != 0 && weatherSpec.getSunSet() != 0) { + isNight = weatherSpec.getSunRise() * 1000L > System.currentTimeMillis() || weatherSpec.getSunSet() * 1000L < System.currentTimeMillis(); } - pairs.add(new Pair<>(messageKeys.get("WeatherForecastHighTemp"), (Object) (weatherSpec.getTodayMaxTemp() - 273))); - pairs.add(new Pair<>(messageKeys.get("WeatherForecastLowTemp"), (Object) (weatherSpec.getTodayMinTemp() - 273))); + pairs.add(new Pair<>(messageKeys.get("SettingUseMetric"), 1)); //celsius + pairs.add(new Pair<>(messageKeys.get("WeatherUseNightIcon"), isNight ? 1 : 0)); + pairs.add(new Pair<>(messageKeys.get("WeatherTemperature"), weatherSpec.getCurrentTemp() - 273)); + pairs.add(new Pair<>(messageKeys.get("WeatherCondition"), getIconForConditionCode(weatherSpec.getCurrentConditionCode(), isNight))); + + if (!weatherSpec.getForecasts().isEmpty()) { + WeatherSpec.Daily tomorrow = weatherSpec.getForecasts().get(0); + pairs.add(new Pair<>(messageKeys.get("WeatherForecastCondition"), getIconForConditionCode(tomorrow.getConditionCode(), isNight))); + } + + pairs.add(new Pair<>(messageKeys.get("WeatherForecastHighTemp"), weatherSpec.getTodayMaxTemp() - 273)); + pairs.add(new Pair<>(messageKeys.get("WeatherForecastLowTemp"), weatherSpec.getTodayMinTemp() - 273)); return mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs, null); }