//Catch failure / dismiss progress dialog //Populate textviews with the correponding pieces of weather information //Populate imageview with image from api protected override void OnPostExecute(string result) { base.OnPostExecute(result); Console.WriteLine(result); if (result.Contains("Error: Not found city")) { pd.Dismiss(); return; } //Deserialise openWeatherMap = JsonConvert.DeserializeObject <OpenWeatherMap>(result); pd.Dismiss(); //Control activity.txtCity = activity.FindViewById <TextView>(Resource.Id.txtCity); activity.txtDescription = activity.FindViewById <TextView>(Resource.Id.txtDescription); activity.txtHumidity = activity.FindViewById <TextView>(Resource.Id.txtHumidity); activity.txtLastUpdate = activity.FindViewById <TextView>(Resource.Id.txtLastUpdate); activity.txtTime = activity.FindViewById <TextView>(Resource.Id.txtTime); activity.txtCelcius = activity.FindViewById <TextView>(Resource.Id.txtCelcius); activity.imgView = activity.FindViewById <ImageView>(Resource.Id.imageViewHomeScreen); //Add data activity.txtCity.Text = $"{openWeatherMap.name},{openWeatherMap.sys.country}"; activity.txtLastUpdate.Text = $"Last Updated: {DateTime.Now.ToString("dd MMMM yyyy HH:mm")}"; activity.txtDescription.Text = $"{openWeatherMap.weather[0].description}"; activity.txtHumidity.Text = $"Humidity: {openWeatherMap.main.humidity} %"; activity.txtTime.Text = $"Sunrise: {Common.UnixTimeStampToDateTime(openWeatherMap.sys.sunrise)}/Sunset: {Common.UnixTimeStampToDateTime(openWeatherMap.sys.sunset)}"; activity.txtCelcius.Text = $"{openWeatherMap.main.temp}°C"; //Add image if (!String.IsNullOrEmpty(openWeatherMap.weather[0].icon)) { Picasso.With(activity.ApplicationContext).Load(Common.GetImage(openWeatherMap.weather[0].icon)) .Into(activity.imgView); } }
//Constructor public GetWeather(HomeScreen activity, OpenWeatherMap openWeatherMap) { this.activity = activity; this.openWeatherMap = openWeatherMap; }