private async Task Resume() { // Save index before update int index = TextForecastControl.SelectedIndex; // Check pin tile status CheckTiles(); if (wLoader.GetWeather()?.IsValid() == true) { Weather weather = wLoader.GetWeather(); // Update weather if needed on resume if (Settings.FollowGPS && await UpdateLocation()) { // Setup loader from updated location wLoader = new WeatherDataLoader(location, this, this); await RefreshWeather(false); } else { // Check weather data expiration if (!int.TryParse(weather.ttl, out int ttl)) { ttl = Settings.DefaultInterval; } TimeSpan span = DateTimeOffset.Now - weather.update_time; if (span.TotalMinutes > ttl) { await RefreshWeather(false); } else { WeatherView.UpdateView(wLoader.GetWeather()); Shell.Instance.HamburgerButtonColor = WeatherView.PendingBackgroundColor; if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { // Mobile StatusBar.GetForCurrentView().BackgroundColor = WeatherView.PendingBackgroundColor; } else { // Desktop var titlebar = ApplicationView.GetForCurrentView().TitleBar; titlebar.BackgroundColor = WeatherView.PendingBackgroundColor; titlebar.ButtonBackgroundColor = titlebar.BackgroundColor; } } } } // Set saved index from before update // Note: needed since ItemSource is cleared and index is reset if (index == 0) // Note: UWP Mobile Bug { TextForecastControl.SelectedIndex = index + 1; } TextForecastControl.SelectedIndex = index; }
public static async Task TileUpdater(LocationData location) { var wloader = new WeatherDataLoader(location); await wloader.LoadWeatherData(false); if (wloader.GetWeather() != null) { TileUpdater(location, wloader.GetWeather()); } }
private async Task <Weather> GetWeather() { Weather weather = null; try { if (Settings.DataSync == WearableDataSync.Off && Settings.FollowGPS) { await UpdateLocation(); } var wloader = new WeatherDataLoader(Settings.HomeData); if (Settings.DataSync == WearableDataSync.Off) { await wloader.LoadWeatherData(false); } else { await wloader.ForceLoadSavedWeatherData(); } locData = Settings.HomeData; weather = wloader.GetWeather(); } catch (Exception ex) { Logger.WriteLine(LoggerLevel.Error, ex, "SimpleWeather: {0}: GetWeather: error", TAG); } return(weather); }
private async Task <Weather> GetWeather() { Weather weather = null; try { if (Settings.FollowGPS) { await UpdateLocation(); } cts.Token.ThrowIfCancellationRequested(); var wloader = new WeatherDataLoader(Settings.HomeData); await wloader.LoadWeatherData(false); weather = wloader.GetWeather(); } catch (OperationCanceledException cancelEx) { Logger.WriteLine(LoggerLevel.Info, cancelEx, "{0}: GetWeather cancelled", taskName); return(null); } catch (Exception ex) { Logger.WriteLine(LoggerLevel.Error, ex, "{0}: GetWeather error", taskName); return(null); } return(weather); }
private async Task Resume() { /* Update view on resume * ex. If temperature unit changed */ // New Page = loaded - true // Navigating back to frag = !loaded - false if (loaded || wLoader == null) { await Restore(); loaded = true; } else if (wLoader != null && !loaded) { var culture = System.Globalization.CultureInfo.CurrentCulture; var locale = wm.LocaleToLangCode(culture.TwoLetterISOLanguageName, culture.Name); // Reset if source || locale is different if (weatherView.WeatherSource != Settings.API || wm.SupportsWeatherLocale && weatherView.WeatherLocale != locale) { await Restore(); loaded = true; } else if (wLoader.GetWeather()?.IsValid() == true) { var weather = wLoader.GetWeather(); // Update weather if needed on resume if (Settings.FollowGPS && await UpdateLocation()) { // Setup loader from updated location wLoader = new WeatherDataLoader(this.location, this, this); await RefreshWeather(false); loaded = true; } else { // Check weather data expiration TimeSpan span = DateTimeOffset.Now - weather.update_time; if (span.TotalMinutes > Settings.DefaultInterval) { await RefreshWeather(false); } else { weatherView.UpdateView(wLoader.GetWeather()); SetView(weatherView); mCallback?.OnWeatherViewUpdated(weatherView); loaded = true; } } } } }
private async Task Resume() { /* Update view on resume * ex. If temperature unit changed */ LocationData homeData = Settings.HomeData; // Did home change? bool homeChanged = false; if (location != null && FragmentManager.BackStackEntryCount == 0) { if (!location.Equals(homeData) && Tag == "home") { location = homeData; wLoader = null; homeChanged = true; } } // New Page = loaded - true // Navigating back to frag = !loaded - false if (loaded || homeChanged || wLoader == null) { await Restore(); loaded = true; } else if (wLoader != null && !loaded) { var culture = System.Globalization.CultureInfo.CurrentCulture; var locale = wm.LocaleToLangCode(culture.TwoLetterISOLanguageName, culture.Name); // Reset if source || locale is different if (weatherView.WeatherSource != Settings.API || wm.SupportsWeatherLocale && weatherView.WeatherLocale != locale) { await Restore(); loaded = true; } else if (wLoader.GetWeather()?.IsValid() == true) { Weather weather = wLoader.GetWeather(); // Update weather if needed on resume if (Settings.FollowGPS && await UpdateLocation()) { // Setup loader from updated location wLoader = new WeatherDataLoader(this.location, this, this); await RefreshWeather(false); loaded = true; } else { // Check weather data expiration if (!int.TryParse(weather.ttl, out int ttl)) { ttl = Settings.DefaultInterval; } TimeSpan span = DateTimeOffset.Now - weather.update_time; if (span.TotalMinutes > ttl) { await RefreshWeather(false); } else { weatherView.UpdateView(wLoader.GetWeather()); SetView(weatherView); loaded = true; } } } } }