mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-05 13:32:14 +02:00
c7c723134e
Add weather info for TimeStylePebble. Add further fields to the ParcelableWeather class. Add reverse mapping to ParcelableWeather to get back the original OpenWeatherMap API condition codes.
45 lines
1.7 KiB
Java
45 lines
1.7 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.preference.PreferenceManager;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.Weather;
|
|
import ru.gelin.android.weather.notification.ParcelableWeather2;
|
|
|
|
|
|
public class WeatherNotificationReceiver extends BroadcastReceiver {
|
|
private static final Logger LOG = LoggerFactory.getLogger(WeatherNotificationReceiver.class);
|
|
|
|
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
if (!intent.getAction().contains("WEATHER_UPDATE_2")) {
|
|
LOG.info("Wrong action");
|
|
return;
|
|
}
|
|
ParcelableWeather2 weather = null;
|
|
try {
|
|
weather = intent.getParcelableExtra("ru.gelin.android.weather.notification.EXTRA_WEATHER");
|
|
} catch (RuntimeException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
if (weather != null) {
|
|
Weather.getInstance().setWeather2(weather);
|
|
LOG.info("weather in " + weather.location + " is " + weather.currentCondition + " (" + (weather.currentTemp - 273) + "°C)");
|
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
SharedPreferences.Editor edit = sharedPrefs.edit();
|
|
edit.putString("weather_location", weather.location);
|
|
edit.putString("weather_current_condition", weather.currentCondition);
|
|
edit.putInt("weather_current_temp", weather.currentTemp);
|
|
edit.apply();
|
|
}
|
|
}
|
|
} |