private async Task SaveWeatherData() { // Save location query weather.query = location.query; // Save weather alerts await SaveWeatherAlerts(); await Settings.SaveWeatherData(weather); #if !__ANDROID_WEAR__ && __ANDROID__ // Update weather data for Wearables WearableDataListenerService.EnqueueWork(Application.Context, new Android.Content.Intent(Application.Context, typeof(WearableDataListenerService)) .SetAction(WearableDataListenerService.ACTION_SENDWEATHERUPDATE)); // Update cached weather data for widgets await Task.Run(() => { if (WidgetUtils.Exists(location.query)) { var ids = WidgetUtils.GetWidgetIds(location.query); foreach (int id in ids) { WidgetUtils.SaveWeatherData(id, weather); } } }); #elif __ANDROID_WEAR__ Settings.UpdateTime = weather.update_time.UtcDateTime; #endif }
private async Task LoadWeatherData() { /* * If unable to retrieve saved data, data is old, or units don't match * Refresh weather data */ Logger.WriteLine(LoggerLevel.Debug, "{0}: Loading weather data for {1}", TAG, location?.ToString()); bool gotData = await LoadSavedWeatherData(); if (!gotData) { Logger.WriteLine(LoggerLevel.Debug, "{0}: Saved weather data invalid for {1}", TAG, location?.ToString()); Logger.WriteLine(LoggerLevel.Debug, "{0}: Retrieving data from weather provider", TAG); try { if ((weather != null && weather.source != Settings.API) || (weather == null && location != null && location.source != Settings.API)) { // Update location query and source for new API string oldKey = location.query; if (weather != null) { location.query = await wm.UpdateLocationQuery(weather); } else { location.query = await wm.UpdateLocationQuery(location); } location.source = Settings.API; // Update database as well #if !__ANDROID_WEAR__ if (location.locationType == LocationType.GPS) { Settings.SaveLastGPSLocData(location); #if __ANDROID__ WearableDataListenerService.EnqueueWork(App.Context, new Android.Content.Intent(App.Context, typeof(WearableDataListenerService)) .SetAction(WearableDataListenerService.ACTION_SENDLOCATIONUPDATE)); #endif } else { await Settings.UpdateLocationWithKey(location, oldKey); } #else Settings.SaveHomeData(location); #endif #if WINDOWS_UWP // Update tile id for location if (SecondaryTileUtils.Exists(oldKey)) { await SecondaryTileUtils.UpdateTileId(oldKey, location.query); } #elif __ANDROID__ && !__ANDROID_WEAR__ if (WidgetUtils.Exists(oldKey)) { WidgetUtils.UpdateWidgetIds(oldKey, location); } #endif } await GetWeatherData(); } catch (WeatherException wEx) { errorCallback?.OnWeatherError(wEx); } } }