// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.oliodevices.assist.app.detectors; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.Loader; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; import com.olio.communication.messages.MessageBuilder; import com.olio.communication.messages.MessagePayload; import com.olio.data.object.bluetooth_status.BluetoothStatus; import com.olio.data.object.context.PersonalAssistantContext; import com.olio.data.object.location.OlioLocation; import com.olio.data.object.unit.ui.TimeZone; import com.olio.data.object.unit.ui.TimeZones; import com.olio.data.object.unit.ui.TimeZonesLoader; import com.olio.data.object.user.Location; import com.olio.olios.detector.ManagedDetector; import com.olio.phone_state.Weather; import com.olio.phone_state.WeatherComplicationData; import com.olio.util.ALog; import com.olio.util.SharedUtils; import com.oliodevices.assist.app.api.WeatherApi; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.concurrent.TimeUnit; import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; // Referenced classes of package com.oliodevices.assist.app.detectors: // BroadcastDelegate public class WeatherDetector implements ManagedDetector { private class WatchProfileObserver extends BroadcastReceiver { final WeatherDetector this$0; public void onReceive(Context context, Intent intent) { ALog.v("onReceive", new Object[0]); fetchAndPushWeatherForTimezones(intent); mContext.unregisterReceiver(mWatchProfileObserver); } private WatchProfileObserver() { this$0 = WeatherDetector.this; super(); } } public static final String CONTEXT_WEATHER = "weather"; private static final long UPDATE_FREQUENCY_MILLIS = 0x6ddd00L; Context mContext; BroadcastDelegate mDelegate; private ContentObserver mLocationObserver; OlioLocation mOlioLocation; private WatchProfileObserver mWatchProfileObserver; private String mWeatherContext; private TimeZonesLoader timeZoneLoader; android.content.Loader.OnLoadCompleteListener timeZonesListener; public WeatherDetector(Context context, BroadcastDelegate broadcastdelegate) { timeZonesListener = new android.content.Loader.OnLoadCompleteListener() { final WeatherDetector this$0; public void onLoadComplete(Loader loader, TimeZones timezones) { fetchAndPushWeatherData(); } public volatile void onLoadComplete(Loader loader, Object obj) { onLoadComplete(loader, (TimeZones)obj); } { this$0 = WeatherDetector.this; super(); } }; mDelegate = broadcastdelegate; mContext = context; timeZoneLoader = new TimeZonesLoader(context); } private void fetchAndPushWeatherForTimezones(Intent intent) { if (intent != null && mContext != null && "com.oliodevices.assist.intent.action.WATCH_VERSION".equals(intent.getAction())) { intent = intent.getStringExtra("watch_fw_version"); ALog.v("Watch version: %s", new Object[] { intent }); if (intent != null && !intent.isEmpty() && SharedUtils.getBuildNumberFromVersionString(intent) >= 79) { intent = TimeZones.get(mContext.getContentResolver()); ALog.v("Found %d time zones", new Object[] { Integer.valueOf(intent.getTimeZones().size()) }); intent = intent.getTimeZones().iterator(); do { if (!intent.hasNext()) { break; } TimeZone timezone = (TimeZone)intent.next(); String s = timezone.getDisplayName(); ALog.v("%s", new Object[] { s }); if (timezone.getLocation() != null) { double d = timezone.getLocation().getLatitude(); double d1 = timezone.getLocation().getLongitude(); fetchForecast(String.format("%.6f", new Object[] { Double.valueOf(d) }), String.format("%.6f", new Object[] { Double.valueOf(d1) }), s); } } while (true); } } } private void fetchForecast(String s, String s1, final String cityName) { ALog.v("fetchForecast: %s", new Object[] { cityName }); WeatherApi.forecast(s, s1, new Callback() { final WeatherDetector this$0; final String val$cityName; public void failure(RetrofitError retrofiterror) { ALog.e("Error retrieving weather forecast", retrofiterror, new Object[0]); } public void success(com.oliodevices.assist.app.api.WeatherService.Forecast forecast, Response response) { label0: { response = new ArrayList(); HashMap hashmap = new HashMap(); for (int i = 1; i <= 12; i++) { com.oliodevices.assist.app.api.WeatherService.WeatherData weatherdata = (com.oliodevices.assist.app.api.WeatherService.WeatherData)forecast.hourly.data.get(i); long l = TimeUnit.SECONDS.toMillis(weatherdata.time); Weather weather = new Weather(); weather.setTemperature((int)weatherdata.temperature); weather.setWeatherState(weatherdata.summary); weather.setWeatherIcon(weatherdata.icon); weather.setCityName(cityName); hashmap.put(Long.valueOf(l), weather); } WeatherComplicationData weathercomplicationdata = new WeatherComplicationData(); weathercomplicationdata.setWeatherStateForecast(hashmap); weathercomplicationdata.setCityName(cityName); response.add(weathercomplicationdata); sendMessages(response); forecast = getCurrentWeatherContext(forecast.currently.precipIntensity); if (!forecast.equals(mWeatherContext)) { mWeatherContext = forecast; forecast = PersonalAssistantContext.personalAssistantContext(mContext.getContentResolver(), "weather"); if (forecast != null) { break label0; } (new PersonalAssistantContext("weather", mWeatherContext)).save(mContext.getContentResolver()); } return; } forecast.setContextValue(mWeatherContext); forecast.save(mContext.getContentResolver()); } public volatile void success(Object obj, Response response) { success((com.oliodevices.assist.app.api.WeatherService.Forecast)obj, response); } { this$0 = WeatherDetector.this; cityName = s; super(); } }); } private String getCurrentWeatherContext(double d) { if (d > 0.0D) { return "wet"; } else { return "dry"; } } private void registerForLocationChanges() { Uri uri = OlioLocation.olioLocation(mContext.getContentResolver()).tableUri(); if (uri == null) { return; } else { mLocationObserver = new ContentObserver(this) { final WeatherDetector this$0; final WeatherDetector val$detector; public void onChange(boolean flag, Uri uri1) { super.onChange(flag, uri1); uri1 = OlioLocation.olioLocation(mContext.getContentResolver()); if (detector.shouldUpdate() && !Objects.equals(uri1, mOlioLocation)) { detector.update(); } } { this$0 = WeatherDetector.this; detector = weatherdetector1; super(final_handler); } }; mContext.getContentResolver().registerContentObserver(uri, true, mLocationObserver); return; } } private void sendMessages(List list) { Object obj; for (list = list.iterator(); list.hasNext(); mDelegate.sendMessage(((com.olio.communication.messages.Message) (obj)))) { obj = (MessagePayload)list.next(); obj = (new MessageBuilder()).setAction(com.olio.communication.messages.Message.Action.CREATE_OR_UPDATE).setPayload(((MessagePayload) (obj))).build(); } } private void unregisterForLocationChanges() { while (OlioLocation.olioLocation(mContext.getContentResolver()).tableUri() == null || mLocationObserver == null) { return; } mContext.getContentResolver().unregisterContentObserver(mLocationObserver); mLocationObserver = null; } public void fetchAndPushWeatherData() { mOlioLocation = OlioLocation.olioLocation(mContext.getContentResolver()); if (mOlioLocation.getLatitude() != null && mOlioLocation.getLongitude() != null) { fetchForecast(mOlioLocation.getLatitude(), mOlioLocation.getLongitude(), ""); } Object obj = new IntentFilter("com.oliodevices.assist.intent.action.WATCH_VERSION"); obj = mContext.registerReceiver(null, ((IntentFilter) (obj))); if (obj != null) { fetchAndPushWeatherForTimezones(((Intent) (obj))); return; } obj = new IntentFilter("com.oliodevices.assist.intent.action.WATCH_VERSION"); if (mWatchProfileObserver == null) { mWatchProfileObserver = new WatchProfileObserver(); } mContext.registerReceiver(mWatchProfileObserver, ((IntentFilter) (obj))); } public void onDisconnect() { } public void register() { registerForLocationChanges(); timeZoneLoader.registerListener(0, timeZonesListener); timeZoneLoader.startLoading(); } public boolean shouldUpdate() { return BluetoothStatus.bluetoothStatus(mContext.getContentResolver()).getBluetooth3ConnectionStatus() == 3; } public void unregister() { unregisterForLocationChanges(); timeZoneLoader.stopLoading(); timeZoneLoader.unregisterListener(timeZonesListener); } public void update() { fetchAndPushWeatherData(); } public Long updateFrequency() { return Long.valueOf(0x6ddd00L); } public boolean updateOnReconnect() { return true; } /* static String access$502(WeatherDetector weatherdetector, String s) { weatherdetector.mWeatherContext = s; return s; } */ }