async void BeginDownloadingImage(VehicleForDownloadWithImage dv, NSIndexPath path) { // Queue the image to be downloaded. This task will execute // as soon as the existing ones have finished. byte[] data = null; data = await GetImageData(dv); if (data != null) { dv.image = UIImage.LoadFromData(NSData.FromArray(data)); } else { dv.image = placeHolder; } InvokeOnMainThread(() => { var cell = controller.tvDownload.VisibleCells.Where(c => c.Tag == controller.listOfVehicles.IndexOf(dv)).FirstOrDefault(); if (cell != null) { cell.ImageView.Image = dv.image; } }); }
async Task <byte[]> GetImageData(VehicleForDownloadWithImage dv) { byte[] data = null; try { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; using (var c = new GzipWebClient()) data = await c.DownloadDataTaskAsync(dv.vehicle.thumbURL); } catch { return(null); } finally { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; } return(data); }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { ChangeVehicleCell cell = tableView.DequeueReusableCell(kCellIdentifier) as ChangeVehicleCell; if (cell == null) { var views = NSBundle.MainBundle.LoadNib("ChangeVehicleCell", tableView, null); cell = Runtime.GetNSObject(views.ValueAt(0)) as ChangeVehicleCell; //cell.Layer.CornerRadius = 7.5f; cell.Layer.BorderColor = UIColor.White.CGColor; cell.Layer.BorderWidth = 0.5f; } cell.Tag = indexPath.Row; VehicleForDownloadWithImage dv = list [indexPath.Row]; string imagePath = dv.vehicle.thumbURL; string YearMakeModel = dv.vehicle.Year + " " + dv.vehicle.Make + " " + dv.vehicle.Model; string Price = dv.vehicle.Price.ToString("C0").ToNullableString(string.Empty); cell.UpdateCell(YearMakeModel, dv.vehicle.StockNumber, dv.vehicle.VIN, Price); if (dv.image == null) { dv.image = placeHolder; if (!string.IsNullOrWhiteSpace(imagePath)) { BeginDownloadingImage(dv, indexPath); } } cell.ImageView.Image = dv.image; if (controller.selectedVehicleIds.Contains(dv.vehicle.BoostVehicleID)) { cell.Accessory = UITableViewCellAccessory.Checkmark; } else { cell.Accessory = UITableViewCellAccessory.None; } return(cell); }