Pebble TimeStyle: support night icons finally

This commit is contained in:
Andreas Shimokawa
2025-11-09 09:52:27 +01:00
parent f898eb912c
commit c31f4e7c82
@@ -30,8 +30,8 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
import nodomain.freeyourgadget.gadgetbridge.model.weather.Weather;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.model.weather.Weather;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
class AppMessageHandlerTimeStylePebble extends AppMessageHandler { class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
@@ -70,7 +70,7 @@ class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
} }
} }
} catch (JSONException e) { } 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) { } catch (IOException ignore) {
} }
} }
@@ -136,19 +136,24 @@ class AppMessageHandlerTimeStylePebble extends AppMessageHandler {
} }
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>(); ArrayList<Pair<Integer, Object>> 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) { boolean isNight = false;
WeatherSpec.Daily tomorrow = weatherSpec.getForecasts().get(0); if (weatherSpec.getSunRise() != 0 && weatherSpec.getSunSet() != 0) {
pairs.add(new Pair<>(messageKeys.get("WeatherForecastCondition"), (Object) (getIconForConditionCode(tomorrow.getConditionCode(), isNight)))); 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("SettingUseMetric"), 1)); //celsius
pairs.add(new Pair<>(messageKeys.get("WeatherForecastLowTemp"), (Object) (weatherSpec.getTodayMinTemp() - 273))); 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); return mPebbleProtocol.encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, mUUID, pairs, null);
} }