Example #1
0
        public override void AwakeFromNib()
        {
            // Create a PHFetchResult object for each section in the table view.
            var allPhotosOptions = new PHFetchOptions();

            allPhotosOptions.SortDescriptors = new [] {
                new NSSortDescriptor("creationDate", true)
            };

            PHFetchResult allPhotos   = PHAsset.FetchAssets(allPhotosOptions);
            PHFetchResult smartAlbums = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum,
                                                                                PHAssetCollectionSubtype.AlbumRegular, null);

            PHFetchResult topLevelUserCollections = PHCollection.FetchTopLevelUserCollections(null);

            // Store the PHFetchResult objects and localized titles for each section.
            sectionFetchResults = new [] {
                allPhotos, smartAlbums, topLevelUserCollections
            };

            sectionLocalizedTitles = new [] {
                string.Empty, "Smart Albums", "Albums", string.Empty
            };

            PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this);
        }
Example #2
0
        public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
        {
            var destination = (segue.DestinationViewController as UINavigationController)?.TopViewController as AssetGridViewController;

            if (destination == null)
            {
                throw new InvalidProgramException("unexpected view controller for segue");
            }

            var cell = sender as UITableViewCell;

            if (destination == null)
            {
                throw new InvalidProgramException("unexpected cell for segue");
            }

            destination.Title = cell.TextLabel.Text;

            switch (segue.Identifier)
            {
            case showAllPhotos:
                destination.FetchResult = allPhotos;
                break;

            case showCollection:
                // get the asset collection for the selected row
                var          indexPath  = TableView.IndexPathForCell(cell);
                PHCollection collection = null;
                switch ((Section)indexPath.Section)
                {
                case Section.SmartAlbums:
                    collection = (PHAssetCollection)smartAlbums.ObjectAt(indexPath.Row);
                    break;

                case Section.UserCollections:
                    collection = (PHCollection)userCollections.ObjectAt(indexPath.Row);
                    break;
                }

                // configure the view controller with the asset collection
                var assetCollection = collection as PHAssetCollection;
                if (assetCollection == null)
                {
                    throw new InvalidProgramException("expected asset collection");
                }

                destination.FetchResult     = PHAsset.FetchAssets(assetCollection, null);
                destination.AssetCollection = assetCollection;
                break;
            }
        }
Example #3
0
        public void Test()
        {
            // Fetch PHAssetCollections
            var topLevelUserCollections = PHCollection.FetchTopLevelUserCollections(null);
            var smartAlbums             = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.AlbumRegular, null);

            _collectionsFetchResults = new List <PHFetchResult> {
                topLevelUserCollections, smartAlbums
            };
            _collectionsLocalizedTitles = new List <string> {
                "picker.table.user-albums-header".Translate(defaultValue: "Albums"), "picker.table.smart-albums-header".Translate("Smart Albums")
            };

            UpdateFetchResults();
        }
Example #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, AddAlbum);

            // Create a PHFetchResult object for each section in the table view.
            var allPhotosOptions = new PHFetchOptions {
                SortDescriptors = new NSSortDescriptor [] { new NSSortDescriptor("creationDate", true) },
            };

            allPhotos       = PHAsset.FetchAssets(allPhotosOptions);
            smartAlbums     = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.AlbumRegular, null);
            userCollections = PHCollection.FetchTopLevelUserCollections(null);

            PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this);
        }
Example #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _picker = (GMImagePickerController)NavigationController.ParentViewController;
            View.BackgroundColor = _picker.PickerBackgroundColor;

            // Navigation bar customization
            if (!string.IsNullOrWhiteSpace(_picker.CustomNavigationBarPrompt))
            {
                NavigationItem.Prompt = _picker.CustomNavigationBarPrompt;
            }

            _imageManager = new PHCachingImageManager();

            // Table view aspect
            TableView.RowHeight      = AlbumRowHeight;
            TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
            TableView.Source         = new GMAlbumsViewTableViewSource(this);

            // Buttons
            var barButtonItemAttributes = new UITextAttributes
            {
                Font = UIFont.FromName(_picker.PickerFontName, _picker.PickerFontHeaderSize)
            };

            var cancelTitle = _picker.CustomCancelButtonTitle ?? "picker.navigation.cancel-button".Translate(defaultValue: "Cancel");

            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(cancelTitle,
                                                                   UIBarButtonItemStyle.Plain,
                                                                   Dismiss);

            if (_picker.UseCustomFontForNavigationBar)
            {
                NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal);
                NavigationItem.LeftBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted);
            }

            if (_picker.AllowsMultipleSelection)
            {
                var doneTitle = _picker.CustomDoneButtonTitle ?? "picker.navigation.done-button".Translate(defaultValue: "Done");
                NavigationItem.RightBarButtonItem = new UIBarButtonItem(doneTitle,
                                                                        UIBarButtonItemStyle.Done,
                                                                        FinishPickingAssets);
                if (_picker.UseCustomFontForNavigationBar)
                {
                    NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal);
                    NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted);
                }
                NavigationItem.RightBarButtonItem.Enabled = !_picker.AutoDisableDoneButton || _picker.SelectedAssets.Any();
            }

            // Bottom toolbar
            ToolbarItems = _picker.GetToolbarItems();

            // Title
            Title = _picker.Title ?? "picker.navigation.title".Translate(defaultValue: "Navigation bar default title");

            // Fetch PHAssetCollections
            var topLevelUserCollections = PHCollection.FetchTopLevelUserCollections(null);
            var smartAlbums             = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.AlbumRegular, null);

            _collectionsFetchResults = new List <PHFetchResult> {
                topLevelUserCollections, smartAlbums
            };
            _collectionsLocalizedTitles = new List <string> {
                "picker.table.user-albums-header".Translate(defaultValue: "Albums"), "picker.table.smart-albums-header".Translate("Smart Albums")
            };

            UpdateFetchResults();

            // Register for changes
            PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this);
        }