예제 #1
0
        private void FeetchAddPhotos()
        {
            PHPhotoLibrary.RequestAuthorization(status =>
            {
                if (status != PHAuthorizationStatus.Authorized)
                {
                    return;
                }

                var galleryTemp = new List <PHAssetCollection>();

                var allAlbums   = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.Album, PHAssetCollectionSubtype.Any, null).Cast <PHAssetCollection>();
                var smartAlbums = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.SmartAlbumUserLibrary, null).Cast <PHAssetCollection>();

                galleryTemp.AddRange(allAlbums);
                galleryTemp.AddRange(smartAlbums);

                var gallerySort = galleryTemp.OrderBy(obj => obj.LocalizedTitle);

                NSOperationQueue.MainQueue.AddOperation(() =>
                {
                    foreach (var itemRaw in gallerySort)
                    {
                        var sortOptions             = new PHFetchOptions();
                        sortOptions.SortDescriptors = new NSSortDescriptor[] { new NSSortDescriptor("creationDate", false) };

                        var items = PHAsset.FetchAssets(itemRaw, sortOptions).Cast <PHAsset>().ToList();

                        if (items.Count > 0)
                        {
                            var colec = new GalleryNative()
                            {
                                Collection = itemRaw,
                            };
                            colec.Images.Add(new PhotoSetNative());

                            foreach (var item in items)
                            {
                                var newPhoto = new PhotoSetNative();
                                newPhoto.galleryImageXF.OriginalPath = item.LocalIdentifier;
                                newPhoto.Image = item;
                                colec.Images.Add(newPhoto);
                            }
                            galleryDirectories.Add(colec);
                        }
                    }

                    tableView.ReloadData();

                    if (galleryDirectories.Count > 0)
                    {
                        CurrentParent = 0;
                        IF_ItemSelectd(CurrentParent);
                    }
                });
            });
        }
예제 #2
0
        public void BindDataToCell(PhotoSetNative photoSetNative, IGalleryPickerSelected action, int index, bool IsCamera)
        {
            imgIcon.ClipsToBounds = true;
            bttClick.Hidden       = false;

            if (IsCamera)
            {
                imgIcon.Image       = UIImage.FromBundle("camera").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
                imgIcon.ContentMode = UIViewContentMode.ScaleAspectFit;
                CheckBox.Hidden     = true;
                bttClick.Tag        = index;

                if (ActionClick == null)
                {
                    ActionClick = delegate {
                        action.IF_CameraSelected((int)CheckBox.Tag);
                    };
                    bttClick.TouchUpInside += (sender, e) =>
                    {
                        ActionClick();
                    };
                }
            }
            else
            {
                imgIcon.ContentMode = UIViewContentMode.ScaleAspectFill;
                CheckBox.Hidden     = false;
                CheckBox.Checked    = photoSetNative.galleryImageXF.Checked;
                CheckBox.Tag        = index;

                if (photoSetNative.galleryImageXF.Checked)
                {
                    bttClick.BackgroundColor = UIColor.DarkGray.ColorWithAlpha(0.5f);
                }
                else
                {
                    bttClick.BackgroundColor = UIColor.Clear;
                }

                var options = new PHImageRequestOptions
                {
                    Synchronous  = true,
                    DeliveryMode = PHImageRequestOptionsDeliveryMode.FastFormat
                };

                PHImageManager.DefaultManager.RequestImageForAsset(photoSetNative.Image, Bounds.Size, PHImageContentMode.AspectFit, options, (result, info) => {
                    imgIcon.Image = result;
                });


                if (ActionClick == null)
                {
                    ActionClick = delegate {
                        var stream = imgIcon.Image.AsJPEG().AsStream().ToByteArray();
                        action.IF_ImageSelected(0, (int)CheckBox.Tag, ImageSource.FromStream(() => new System.IO.MemoryStream(stream)), null);
                    };
                    CheckBox.TouchUpInside += (sender, e) =>
                    {
                        ActionClick();
                    };
                }
            }
        }