private void ReloadData () { mAlert = new UIAlertView ("Downloading...", "", null, null, null); mAlert.Show (); // Show the user that data is about to be downloaded UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; using (var downloader = new GzipWebClient ()) { downloader.DownloadStringCompleted += DownloadCompleted; downloader.DownloadStringAsync (RssFeedUrl); } }
private void DownloadCompleted (object sender, DownloadStringCompletedEventArgs e) { UIApplication.SharedApplication.BeginInvokeOnMainThread (() => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; mAlert.DismissWithClickedButtonIndex (0, true); if (e.Error != null) { DisplayError ("Warning", "The rss feed could not be downloaded: " + e.Error.Message); } else { try { //clear the selected items this.GridView.ClearSelectedItems(); //Clear the rows mDatasource.ClearRows(); mDatasource.Apps.Clear (); foreach (var v in RssParser.Parse (e.Result)) mDatasource.Apps.Add (v); mAlert = new UIAlertView ("Fetching Icons...", "", null, null, null); mAlert.Show (); UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; Task.Run (() => { foreach (var anApp in mDatasource.Apps) { byte[] data = null; using (var c = new GzipWebClient ()) { data = c.DownloadData (anApp.ImageUrl); } anApp.Image = UIImage.LoadFromData (NSData.FromArray (data)); } }).ContinueWith (prevTask => { mAlert.DismissWithClickedButtonIndex (0, true); UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; GridView.ReloadData (); }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext ()); } catch { DisplayError ("Warning", "Malformed Xml was found in the Rss Feed."); } } }); }