public async Task Load48HoursWeatherInfo() { if (IsBusy) { return; } IsBusy = true; try { await GeolocationHelper.GetGeolocationInfo(geoModel); var result = await HttpConnection.Get48HoursWeatherInfoAsync(geoModel.Lat, geoModel.Lon, "apiKey"); if (result.Hourly != null) { foreach (var item in result.Hourly) { Hourly48ForecastList.Add(new Forecast48HoursModel { Dt = DateAndTimeHelper.ConvertToDateAndTime(item.Dt, DateAndTimeHelper.TypeForDateAndTimeFormat.TIME), DateAndTime = DateAndTimeHelper.ConvertToDateAndTime(item.Dt, DateAndTimeHelper.TypeForDateAndTimeFormat.DATE_AND_TIME_FOR_48FORECAST), Temp = Math.Round(item.Temp.Value, 1).ToString(), Icon = HttpConnection.GetIconForWeather(item.Weather.First().Icon), WindDeg = WindHelper.DegreesToGeogrpahicalDirections(item.WindDeg.Value), GroupName = DateAndTimeHelper.ConvertToDateAndTime(item.Dt, DateAndTimeHelper.TypeForDateAndTimeFormat.COMMON_DATETIME), ColorOfTemperatureLabel = item.Weather.First().Icon.Contains("n")?"#000000": "#008000", Humidity = item.Humidity, WindSpeed = WindHelper.MpsToKmph(item.WindSpeed.Value), Rain = string.IsNullOrEmpty(item.Rain) ? "0" : item.Rain, Clouds = item.Clouds, Pressure = item.Pressure, Description = item.Weather.First().Description, FeelsTemp = Math.Round(item.FeelsLike.Value, 1).ToString() }); } List <string> groupNamesList = new List <string>(); foreach (var item in Hourly48ForecastList) { groupNamesList.Add(item.GroupName); } var distinctGroupNamesList = groupNamesList.Distinct().ToList(); foreach (var item in distinctGroupNamesList) { GroupedHourly48ForecastList.Add(new GroupingForListClass <string, Forecast48HoursModel>(item, Hourly48ForecastList.Where(x => x.GroupName == item))); } } else { await App.Current.MainPage.DisplayAlert("Błąd", "Coś poszło nie tak.", "OK"); } } catch (Exception ex) { await App.Current.MainPage.DisplayAlert("Błąd", "Coś poszło nie tak.", "OK"); } finally { IsBusy = false; } }
protected override async void OnAppearing() { base.OnAppearing(); //if (String.IsNullOrEmpty(Preferences.Get("Latitude", "")) && String.IsNullOrEmpty(Preferences.Get("Longitude", ""))) //{ // //} await GeolocationHelper.GetGeolocationInfo(viewModel.geoModel); await viewModel.LoadActualAndDailyWeatherInfoForSevenDays(); timer = new PollingTimerHelper(TimeSpan.FromMinutes(1), async() => { await GeolocationHelper.GetGeolocationInfo(viewModel.geoModel); await viewModel.LoadActualAndDailyWeatherInfoForSevenDays(); }); timer.Start(); }