2017-03-10 14:53:19 +01:00
|
|
|
/* Copyright (C) 2015-2017 Andreas Shimokawa, Daniele Gobbetti
|
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-12-27 19:44:33 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2016-12-31 15:56:05 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2016-01-03 18:28:32 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
2016-12-31 15:56:05 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
|
2015-12-28 20:55:59 +01:00
|
|
|
import ru.gelin.android.weather.notification.ParcelableWeather2;
|
|
|
|
|
2015-12-27 19:44:33 +01:00
|
|
|
|
2015-12-28 11:33:22 +01:00
|
|
|
public class WeatherNotificationReceiver extends BroadcastReceiver {
|
2015-12-27 19:44:33 +01:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(WeatherNotificationReceiver.class);
|
2015-12-28 11:33:22 +01:00
|
|
|
|
2015-12-27 19:44:33 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
if (!intent.getAction().contains("WEATHER_UPDATE_2")) {
|
|
|
|
LOG.info("Wrong action");
|
|
|
|
return;
|
|
|
|
}
|
2015-12-28 20:55:59 +01:00
|
|
|
ParcelableWeather2 weather = null;
|
|
|
|
try {
|
|
|
|
weather = intent.getParcelableExtra("ru.gelin.android.weather.notification.EXTRA_WEATHER");
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
e.printStackTrace();
|
2015-12-28 11:33:22 +01:00
|
|
|
}
|
|
|
|
|
2015-12-28 20:55:59 +01:00
|
|
|
if (weather != null) {
|
2016-01-03 18:28:32 +01:00
|
|
|
Weather.getInstance().setWeather2(weather);
|
2015-12-29 22:10:38 +01:00
|
|
|
LOG.info("weather in " + weather.location + " is " + weather.currentCondition + " (" + (weather.currentTemp - 273) + "°C)");
|
|
|
|
|
2016-12-31 15:56:05 +01:00
|
|
|
WeatherSpec weatherSpec = new WeatherSpec();
|
|
|
|
weatherSpec.timestamp = (int) (weather.queryTime / 1000);
|
|
|
|
weatherSpec.location = weather.location;
|
|
|
|
weatherSpec.currentTemp = weather.currentTemp;
|
|
|
|
weatherSpec.currentCondition = weather.currentCondition;
|
|
|
|
weatherSpec.currentConditionCode = weather.currentConditionCode;
|
|
|
|
weatherSpec.todayMaxTemp = weather.todayHighTemp;
|
|
|
|
weatherSpec.todayMinTemp = weather.todayLowTemp;
|
|
|
|
weatherSpec.tomorrowConditionCode = weather.forecastConditionCode;
|
|
|
|
weatherSpec.tomorrowMaxTemp = weather.forecastHighTemp;
|
|
|
|
weatherSpec.tomorrowMinTemp = weather.forecastLowTemp;
|
2016-12-31 19:17:08 +01:00
|
|
|
Weather.getInstance().setWeatherSpec(weatherSpec);
|
2016-12-31 15:56:05 +01:00
|
|
|
GBApplication.deviceService().onSendWeather(weatherSpec);
|
2015-12-28 11:33:22 +01:00
|
|
|
}
|
2015-12-27 19:44:33 +01:00
|
|
|
}
|
|
|
|
}
|