2024-01-10 18:54:00 +01:00
|
|
|
/* Copyright (C) 2015-2024 Andreas Shimokawa, Daniele Gobbetti
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
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
|
2024-01-10 18:54:00 +01:00
|
|
|
along with this program. If not, see <https://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;
|
|
|
|
|
2024-03-29 22:10:40 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
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) {
|
2017-11-29 23:57:36 +01:00
|
|
|
if (intent.getAction() == null || !intent.getAction().contains("WEATHER_UPDATE_2")) {
|
2015-12-27 19:44:33 +01:00
|
|
|
LOG.info("Wrong action");
|
|
|
|
return;
|
|
|
|
}
|
2017-11-30 10:24:31 +01:00
|
|
|
ParcelableWeather2 parcelableWeather2 = null;
|
2015-12-28 20:55:59 +01:00
|
|
|
try {
|
2017-11-30 10:24:31 +01:00
|
|
|
parcelableWeather2 = intent.getParcelableExtra("ru.gelin.android.weather.notification.EXTRA_WEATHER");
|
2015-12-28 20:55:59 +01:00
|
|
|
} catch (RuntimeException e) {
|
2017-11-30 10:24:31 +01:00
|
|
|
LOG.error("cannot get ParcelableWeather2", e);
|
2015-12-28 11:33:22 +01:00
|
|
|
}
|
|
|
|
|
2017-11-30 10:24:31 +01:00
|
|
|
if (parcelableWeather2 != null) {
|
|
|
|
Weather weather = Weather.getInstance();
|
|
|
|
weather.setReconstructedOWMForecast(parcelableWeather2.reconstructedOWMForecast);
|
|
|
|
|
|
|
|
WeatherSpec weatherSpec = parcelableWeather2.weatherSpec;
|
|
|
|
LOG.info("weather in " + weatherSpec.location + " is " + weatherSpec.currentCondition + " (" + (weatherSpec.currentTemp - 273) + "°C)");
|
2015-12-29 22:10:38 +01:00
|
|
|
|
2024-03-29 22:10:40 +01:00
|
|
|
ArrayList<WeatherSpec> weatherSpecs = new ArrayList<>(Collections.singletonList(weatherSpec));
|
|
|
|
Weather.getInstance().setWeatherSpec(weatherSpecs);
|
|
|
|
GBApplication.deviceService().onSendWeather(weatherSpecs);
|
2015-12-28 11:33:22 +01:00
|
|
|
}
|
2015-12-27 19:44:33 +01:00
|
|
|
}
|
|
|
|
}
|