void StartImageDownload(ListView listView, int position, IIconAndTitleItem audio) { if (_imageDownloadsInProgress.Contains(audio.Id)) { return; } var url = new Uri(audio.IconUrl); if (_imageDownloader.HasLocallyCachedCopy(url)) { var image = _imageDownloader.GetImage(url); FinishImageDownload(listView, position, audio, (Bitmap)image); } else { _imageDownloadsInProgress.Add(audio.Id); _imageDownloader.GetImageAsync(url).ContinueWith(t => { if (!t.IsFaulted) { FinishImageDownload(listView, position, audio, (Bitmap)t.Result); } }, TaskScheduler.FromCurrentSynchronizationContext() ); } }
void FinishImageDownload(ListView listView, int position, IIconAndTitleItem audio, Bitmap image) { _images [audio.Id] = image; _imageDownloadsInProgress.Remove(audio.Id); // Locate the the child view and update. var firstPostion = listView.FirstVisiblePosition - listView.HeaderViewsCount; var childIndex = position - firstPostion; if (0 <= childIndex && childIndex < listView.ChildCount) { var view = listView.GetChildAt(childIndex); var imageView = view.FindViewById <ImageView> (Resource.Id.Icon); imageView.SetImageBitmap(image); } }
void StartImageDownload (ListView listView, int position, IIconAndTitleItem audio) { if (_imageDownloadsInProgress.Contains (audio.Id)) { return; } var url = new Uri (audio.IconUrl); if (_imageDownloader.HasLocallyCachedCopy (url)) { var image = _imageDownloader.GetImage (url); FinishImageDownload (listView, position, audio, (Bitmap) image); } else { _imageDownloadsInProgress.Add (audio.Id); _imageDownloader.GetImageAsync (url).ContinueWith (t => { if (!t.IsFaulted) { FinishImageDownload (listView, position, audio, (Bitmap) t.Result); } }, TaskScheduler.FromCurrentSynchronizationContext () ); } }
void FinishImageDownload (ListView listView, int position, IIconAndTitleItem audio, Bitmap image) { _images [audio.Id] = image; _imageDownloadsInProgress.Remove (audio.Id); // Locate the the child view and update. var firstPostion = listView.FirstVisiblePosition - listView.HeaderViewsCount; var childIndex = position - firstPostion; if (0 <= childIndex && childIndex < listView.ChildCount) { var view = listView.GetChildAt (childIndex); var imageView = view.FindViewById<ImageView> (Resource.Id.Icon); imageView.SetImageBitmap (image); } }