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