mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 12:26:48 +01:00
Add getLocation method to WeatherSpec and use it for Zepp OS and Fossil/Skagen
This commit is contained in:
parent
6d828260d0
commit
d10745b0b3
@ -18,9 +18,12 @@
|
||||
|
||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
import android.location.Location;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -95,6 +98,17 @@ public class WeatherSpec implements Parcelable, Serializable {
|
||||
return toBeaufort(this.windSpeed);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Location getLocation() {
|
||||
if (latitude == 0 && longitude == 0) {
|
||||
return null;
|
||||
}
|
||||
final Location location = new Location("weatherSpec");
|
||||
location.setLatitude(latitude);
|
||||
location.setLatitude(longitude);
|
||||
return location;
|
||||
}
|
||||
|
||||
protected WeatherSpec(Parcel in) {
|
||||
int version = in.readInt();
|
||||
if (version >= 2) {
|
||||
|
@ -202,11 +202,8 @@ public class Huami2021Weather {
|
||||
weather.add(new Range(currentWeatherCode, currentWeatherCode));
|
||||
if (weatherSpec.sunRise != 0 && weatherSpec.sunSet != 0) {
|
||||
sunRiseSet.add(getSunriseSunset(new Date(weatherSpec.sunRise * 1000L), new Date(weatherSpec.sunSet * 1000L)));
|
||||
} else if (weatherSpec.latitude != 0 && weatherSpec.longitude != 0) {
|
||||
final Location weatherSpecLocation = new Location("weatherSpec");
|
||||
weatherSpecLocation.setLatitude(weatherSpec.latitude);
|
||||
weatherSpecLocation.setLatitude(weatherSpec.longitude);
|
||||
sunRiseSet.add(getSunriseSunset(sunriseDate, weatherSpecLocation));
|
||||
} else if (weatherSpec.getLocation() != null) {
|
||||
sunRiseSet.add(getSunriseSunset(sunriseDate, weatherSpec.getLocation()));
|
||||
} else {
|
||||
sunRiseSet.add(getSunriseSunset(sunriseDate, lastKnownLocation));
|
||||
}
|
||||
|
@ -1443,10 +1443,17 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
|
||||
@Override
|
||||
public void onSendWeather(WeatherSpec weatherSpec) {
|
||||
// TODO: We should send sunrise on the same location as the weather
|
||||
final Location lastKnownLocation = new CurrentPosition().getLastKnownLocation();
|
||||
GregorianCalendar[] sunrise = SPA.calculateSunriseTransitSet(new GregorianCalendar(), lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), DeltaT.estimate(new GregorianCalendar()));
|
||||
Boolean isNight = sunrise[0].getTimeInMillis() > System.currentTimeMillis() || sunrise[2].getTimeInMillis() < System.currentTimeMillis();
|
||||
boolean isNight;
|
||||
if (weatherSpec.sunRise != 0 && weatherSpec.sunSet != 0) {
|
||||
isNight = weatherSpec.sunRise * 1000L > System.currentTimeMillis() || weatherSpec.sunSet * 1000L < System.currentTimeMillis();
|
||||
} else {
|
||||
Location location = weatherSpec.getLocation();
|
||||
if (location == null) {
|
||||
location = new CurrentPosition().getLastKnownLocation();
|
||||
}
|
||||
GregorianCalendar[] sunrise = SPA.calculateSunriseTransitSet(new GregorianCalendar(), location.getLatitude(), location.getLongitude(), DeltaT.estimate(new GregorianCalendar()));
|
||||
isNight = sunrise[0].getTimeInMillis() > System.currentTimeMillis() || sunrise[2].getTimeInMillis() < System.currentTimeMillis();
|
||||
}
|
||||
|
||||
long ts = System.currentTimeMillis();
|
||||
ts /= 1000;
|
||||
|
Loading…
Reference in New Issue
Block a user