protected override void OnDeactivate(bool close) { IsInited = false; _townsRepository.SaveTownsList(townsList); WeatherList?.Clear(); _eventAggregator.Unsubscribe(this); base.OnDeactivate(close); }
private async Task LoadWeatherData() { WeatherList.Clear(); IsLoading = true; var list = await new WeatherForecastService().GetWeatherInfo(City.Longitude, City.Latitude); IsLoading = false; foreach (var item in list) { WeatherList.Add(item); } }
public async Task UpdateWeather() { try { HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(); Uri serverUri = new Uri("http://api.openweathermap.org"); Uri relativeUri = new Uri("data/2.5/weather?q=Podolsk&appid=64bc9c5f639ff73c8de7f689df34817b", UriKind.Relative); Uri fullUri = new Uri(serverUri, relativeUri); request.RequestUri = fullUri; request.Method = HttpMethod.Get; request.Headers.Add("Accept", "application/json"); HttpResponseMessage response = await client.SendAsync(request); if (response.StatusCode == HttpStatusCode.OK) { HttpContent responseContent = response.Content; string s = await responseContent.ReadAsStringAsync(); weather = JsonConvert.DeserializeObject <OpenWeather>(s); WeatherList.Clear(); WeatherList.AddRange(new string[] { $"Координаты {weather.coord.lat},{weather.coord.lon}", $"Погода {weather.weather[0].description} (подробнее)", $"Температура {GetCelsius(weather.main.temp)} С (подробнее)", $"Облачность {weather.clouds.all}", $"Общая информация {weather.sys.country}", $"Город {weather.name}" }); } weatherScroll.ItemsSource = null; weatherScroll.ItemsSource = WeatherList; } catch (Exception) { await DisplayAlert("Ошибка", "Что-то пошло не так...", "Ок"); } }