private void FillScreenData(WeatherModel weather) { //Dados superior Icon = weather.Currently.Icon.Replace('-', '_'); Date = UnixTimeStampToDateTime(weather.Currently.Time); Temperature = (int)weather.Currently.Temperature; //Backup da Lista do clima durante 24H foreach (var item in weather.Hourly.Data) { BackupHourlyWeatherList.Add(new HourlyWeather() { //O replace é para o aplicativo encontrar as imagens corretamente, pois a api disponibiliza os nomes do sicones com o padrão "-". Icon = item.Icon.Replace('-', '_'), Time = UnixTimeStampToDateTime(item.Time), Temperature = (int)item.Temperature }); } //Preencher Lista do clima durante 24H FillClimateList(); //Informações da parte inferior. AverageTemperature = $"Min: {(int)weather.Daily.Data[0].TemperatureMin}° Max: {(int)weather.Daily.Data[0].TemperatureMax}°"; SunriseTime = UnixTimeStampToDateTime(weather.Daily.Data[0].SunriseTime); SunsetTime = UnixTimeStampToDateTime(weather.Daily.Data[0].SunsetTime); //O Substring é para remoção do 0 PrecipProbability = $"{(weather.Currently.PrecipProbability.ToString("n").Substring(2).StartsWith('0') ? $"{weather.Currently.PrecipProbability.ToString("n").Substring(3)}%" : $"{weather.Currently.PrecipProbability.ToString("n").Substring(2)}%")}"; Humidity = $"{weather.Currently.Humidity.ToString("n").Substring(2)}%"; //A multiplicação é para tranformar Milhas em KM/h WindSpeed = $"{(int)(weather.Currently.WindSpeed * 1.609)} km/h"; ApparentTemperature = $"{(int)weather.Currently.ApparentTemperature}°"; //Formula para transformar polegas em centimetros. Fonte: https://www.metric-conversions.org/pt-br/comprimento/polegadas-em-centimetros.htm PrecipIntensity = $"{Math.Round(weather.Currently.PrecipIntensity / 0.39370, 1)} cm"; Pressure = $"{(int)weather.Currently.Pressure} hPa"; //O método Round foi utilizado para diminuir as casas decimais Visibility = $"{Math.Round(weather.Currently.Visibility, 1)} km"; UvIndex = weather.Currently.UvIndex; }
private void FillClimateList() { HourlyWeatherList.Clear(); //Estou usado ForEach porque no método "ADD" que é chamado o evento "property change". if (IsToday) { foreach (var hourlyWeather in BackupHourlyWeatherList.Take(25)) { HourlyWeatherList.Add(hourlyWeather); } } else if (IsTomorrow) { foreach (var hourlyWeather in BackupHourlyWeatherList.Skip(24).Take(25)) { HourlyWeatherList.Add(hourlyWeather); } } }