private async void RequestImageForCell(UIEntityTableViewCell <TEntity> cell, NSIndexPath indexPath) { UIImage image = this.TryGetImageForCell(cell); if (image != null) { cell.SetImage(image); } else { string imageUrl = cell.ImageUrl; RemoteImageRequest imageRequest = this.imageCatalog.StartImageRequest(imageUrl, cell.ImageOptions); if (!imageRequest.IsRequestCompleted) { cell.SetImageDownloadInProgress(); } ServiceResult result = await imageRequest.Task; // Check if the requesting cell was new and ensure that it hasn't already been reused. if (indexPath.Length == 0 && imageUrl == cell.ImageUrl) { this.SetImageFromResult(result, cell); } else { this.SetImageFromResult(result, indexPath); } } }
private void SetImageFromResult(ServiceResult result, NSIndexPath indexPath) { if (!this.isDisposed) { UIEntityTableViewCell <TEntity> cell = this.TableView.CellAt(indexPath) as UIEntityTableViewCell <TEntity>; this.SetImageFromResult(result, cell); } }
/// <summary> /// Attempts to get the image that should be displayed with the specified cell if it is available locally. /// </summary> /// <param name="cell">The cell to get the image for.</param> /// <returns>The image for the cell or null if an image is not currently available.</returns> protected virtual UIImage TryGetImageForCell(UIEntityTableViewCell <TEntity> cell) { if (this.imageCatalog == null) { throw new InvalidOperationException("A remote image catalog has not been set so remote image downloading is not available."); } return (this.imageCatalog.TryGetImage( cell.ImageUrl, cell.ImageOptions, bytes => UIImageByteConverter.FromBytes(bytes, decompress: true))); }
/// <summary> /// Gets the cell for the specified table at the given index. /// </summary> /// <param name="tableView">The table view.</param> /// <param name="indexPath">The index path.</param> /// <returns>A table view cell.</returns> public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { if (this.IsLoadingIndicator(indexPath)) { return(this.createLoadingMorePagesCell()); } TEntity entity = this.items.ElementAt(indexPath.Row); UIEntityTableViewCell <TEntity> cell = this.createTableCell(entity); cell.Initialize(entity); if (cell.IsRemoteImageSupported) { this.requestImageForCell(cell, indexPath); } return(cell); }
private void SetImageFromResult(ServiceResult result, UIEntityTableViewCell <TEntity> cell) { if (cell != null) { if (result.ResultCode == ServiceResultCode.Success) { UIImage image = this.TryGetImageForCell(cell); if (image == null) { // is it possible the image was automatically removed from the cache in such a short period of time? throw new InvalidOperationException("An image was not found in the cache."); } cell.SetImage(image); } else { UIImage errorImage = result.ResultCode == ServiceResultCode.NetworkUnavailable ? this.GetDisconnectedImage() : this.GetImageDownloadFailedImage(result); UIViewContentMode contentMode = UIViewContentMode.Center; UIImageView imageView = cell.GetImageView(); if (errorImage != null && (errorImage.Size.Width > imageView.Bounds.Width || errorImage.Size.Height > imageView.Bounds.Height)) { contentMode = UIViewContentMode.ScaleAspectFit; } cell.SetImage(errorImage, contentMode); } cell.MarkImageDownloadComplete(result.ResultCode == ServiceResultCode.Success); } }
/// <summary> /// Occurs when a row has been deselected. /// </summary> /// <param name="cell">The cell that was deselected.</param> protected virtual void OnRowDeselected(UIEntityTableViewCell <TEntity> cell) { }