Beispiel #1
0
            public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
            {
                var cell = (GMAlbumsViewCell)tableView.DequeueReusableCell(CellReuseIdentifier);

                if (cell == null)
                {
                    cell           = new GMAlbumsViewCell(UITableViewCellStyle.Subtitle, CellReuseIdentifier);
                    cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
                }

                // Increment the cell's tag
                var currentTag = cell.Tag + 1;

                cell.Tag = currentTag;

                // Set the label
                cell.TextLabel.Font      = UIFont.FromName(_parent._picker.PickerFontName, _parent._picker.PickerFontHeaderSize);
                cell.TextLabel.Text      = _parent._collectionsFetchResultsTitles [indexPath.Section][indexPath.Row];
                cell.TextLabel.TextColor = _parent._picker.PickerTextColor;

                // Retrieve the pre-fetched assets for this album:
                var assetsFetchResult = _parent._collectionsFetchResultsAssets[indexPath.Section][indexPath.Row];

                // Display the number of assets
                if (_parent._picker.DisplayAlbumsNumberOfAssets)
                {
                    cell.DetailTextLabel.Font = UIFont.FromName(_parent._picker.PickerFontName, _parent._picker.PickerFontNormalSize);
                    // Just use the number of assets. Album app does this:
                    cell.DetailTextLabel.Text      = string.Format("{0:0}", assetsFetchResult.Count);
                    cell.DetailTextLabel.TextColor = _parent._picker.PickerTextColor;
                }

                var numberOfAssets = assetsFetchResult.Count;

                // Set the 3 images (if exists):
                if (numberOfAssets > 0)
                {
                    var scale = UIScreen.MainScreen.Scale;

                    var options = new PHImageRequestOptions
                    {
                        Synchronous          = false,
                        NetworkAccessAllowed = true,
                        DeliveryMode         = PHImageRequestOptionsDeliveryMode.Opportunistic,
                        ResizeMode           = PHImageRequestOptionsResizeMode.Fast
                    };

                    // Compute the thumbnail pixel size:
                    var tableCellThumbnailSize1 = new CGSize(AlbumThumbnailSize1.Width * scale, AlbumThumbnailSize1.Height * scale);
                    var asset = (PHAsset)assetsFetchResult[_parent._picker.GridSortOrder == SortOrder.Ascending ? numberOfAssets - 1 : 0];
                    cell.SetVideoLayout(asset.MediaType == PHAssetMediaType.Video);
                    _parent._imageManager.RequestImageForAsset(asset,
                                                               tableCellThumbnailSize1,
                                                               PHImageContentMode.AspectFill,
                                                               options,
                                                               (image, info) => {
                        if (cell.Tag == currentTag && cell.ImageView1 != null && image != null)
                        {
                            cell.ImageView1.Image = image;
                        }
                    });

                    // Second & third images:
                    // TODO: Only preload the 3pixels height visible frame!
                    if (numberOfAssets > 1)
                    {
                        // Compute the thumbnail pixel size:
                        var tableCellThumbnailSize2 = new CGSize(AlbumThumbnailSize2.Width * scale, AlbumThumbnailSize2.Height * 2);
                        asset = (PHAsset)assetsFetchResult [_parent._picker.GridSortOrder == SortOrder.Ascending ? numberOfAssets - 2 : 1];
                        _parent._imageManager.RequestImageForAsset(asset,
                                                                   tableCellThumbnailSize2,
                                                                   PHImageContentMode.AspectFill,
                                                                   options,
                                                                   (image, info) => {
                            if (cell.Tag == currentTag && cell.ImageView2 != null && image != null)
                            {
                                cell.ImageView2.Image = image;
                            }
                        });
                    }
                    else
                    {
                        cell.ImageView2.Image = null;
                    }

                    if (numberOfAssets > 2)
                    {
                        // Compute the thumbnail pixel size:
                        var tableCellThumbnailSize3 = new CGSize(AlbumThumbnailSize3.Width * scale, AlbumThumbnailSize3.Height * 2);
                        asset = (PHAsset)assetsFetchResult [_parent._picker.GridSortOrder == SortOrder.Ascending ? numberOfAssets - 3 : 2];
                        _parent._imageManager.RequestImageForAsset(asset,
                                                                   tableCellThumbnailSize3,
                                                                   PHImageContentMode.AspectFill,
                                                                   options,
                                                                   (image, info) => {
                            if (cell.Tag == currentTag && cell.ImageView3 != null && image != null)
                            {
                                cell.ImageView3.Image = image;
                            }
                        });
                    }
                    else
                    {
                        cell.ImageView3.Image = null;
                    }
                }
                else
                {
                    cell.SetVideoLayout(false);
                    var emptyFolder = UIImage.FromFile("GMEmptyFolder");
                    cell.ImageView3.Image = emptyFolder;
                    cell.ImageView2.Image = emptyFolder;
                    cell.ImageView1.Image = emptyFolder;
                }
                return(cell);
            }
			public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
			{
				var cell = (GMAlbumsViewCell)tableView.DequeueReusableCell (CellReuseIdentifier);
				if (cell == null) {
					cell = new GMAlbumsViewCell (UITableViewCellStyle.Subtitle, CellReuseIdentifier);
					cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
				}

				// Increment the cell's tag
				var currentTag = cell.Tag + 1;
				cell.Tag = currentTag;

				// Set the label
				cell.TextLabel.Font = UIFont.FromName (_parent._picker.PickerFontName, _parent._picker.PickerFontHeaderSize);
				cell.TextLabel.Text = _parent._collectionsFetchResultsTitles [indexPath.Section][indexPath.Row];
				cell.TextLabel.TextColor = _parent._picker.PickerTextColor;

				// Retrieve the pre-fetched assets for this album:
				var assetsFetchResult = (PHFetchResult) _parent._collectionsFetchResultsAssets[indexPath.Section][indexPath.Row];

				// Display the number of assets
				if (_parent._picker.DisplayAlbumsNumberOfAssets) {
					cell.DetailTextLabel.Font = UIFont.FromName (_parent._picker.PickerFontName, _parent._picker.PickerFontNormalSize);
					// Just use the number of assets. Album app does this:
					cell.DetailTextLabel.Text = string.Format("{0:0}", assetsFetchResult.Count);
					cell.DetailTextLabel.TextColor = _parent._picker.PickerTextColor;
				}

                var numberOfAssets = assetsFetchResult.Count;

				// Set the 3 images (if exists):
				if (numberOfAssets > 0) {
					var scale = UIScreen.MainScreen.Scale;

					// Compute the thumbnail pixel size:
					var tableCellThumbnailSize1 = new CGSize (AlbumThumbnailSize1.Width * scale, AlbumThumbnailSize1.Height * scale);
					var asset = (PHAsset)assetsFetchResult[_parent._picker.GridSortOrder == SortOrder.Ascending ? numberOfAssets - 1 : 0];
					cell.SetVideoLayout (asset.MediaType == PHAssetMediaType.Video);
					_parent._imageManager.RequestImageForAsset (asset, tableCellThumbnailSize1, PHImageContentMode.AspectFill, null, (image, info) => {
						if (cell.Tag == currentTag) {
							cell.ImageView1.Image = image;
						}
					});

					// Second & third images:
					// TODO: Only preload the 3pixels height visible frame!
					if (numberOfAssets > 1) {
						// Compute the thumbnail pixel size:
						var tableCellThumbnailSize2 = new CGSize (AlbumThumbnailSize2.Width * scale, AlbumThumbnailSize2.Height * 2);
						asset = (PHAsset)assetsFetchResult [_parent._picker.GridSortOrder == SortOrder.Ascending ? numberOfAssets - 2 : 1];
						_parent._imageManager.RequestImageForAsset (asset, tableCellThumbnailSize2, PHImageContentMode.AspectFill, null, (image, info) => {
							if (cell.Tag == currentTag) {
								cell.ImageView2.Image = image;
							}
						});
					} else {
						cell.ImageView2.Image = null;
					}

					if (numberOfAssets > 2) {
						// Compute the thumbnail pixel size:
						var tableCellThumbnailSize3 = new CGSize (AlbumThumbnailSize3.Width * scale, AlbumThumbnailSize3.Height * 2);
						asset = (PHAsset)assetsFetchResult [_parent._picker.GridSortOrder == SortOrder.Ascending ? numberOfAssets - 3 : 2];
						_parent._imageManager.RequestImageForAsset (asset, tableCellThumbnailSize3, PHImageContentMode.AspectFill, null, (image, info) => {
							if (cell.Tag == currentTag) {
								cell.ImageView3.Image = image;
							}
						});
					} else {
						cell.ImageView3.Image = null;
					}
				} else {
					cell.SetVideoLayout (false);
					var emptyFolder = UIImage.FromFile ("GMEmptyFolder");
					cell.ImageView3.Image = emptyFolder;
					cell.ImageView2.Image = emptyFolder;
					cell.ImageView1.Image = emptyFolder;
				}
				return cell;
			}