示例#1
0
        private void SetupButtons()
        {
            if (_picker.AllowsMultipleSelection)
            {
                var doneTitle = _picker.CustomDoneButtonTitle ?? "picker.navigation.done-button".Translate(defaultValue: "Done");
                NavigationItem.RightBarButtonItem = new UIBarButtonItem(doneTitle,
                                                                        UIBarButtonItemStyle.Done,
                                                                        FinishPickingAssets);

                NavigationItem.RightBarButtonItem.Enabled = !_picker.AutoDisableDoneButton || _picker.SelectedAssets.Any();
            }
            else
            {
                var cancelTitle = _picker.CustomCancelButtonTitle ?? "picker.navigation.cancel-button".Translate(defaultValue: "Cancel");
                NavigationItem.RightBarButtonItem = new UIBarButtonItem(cancelTitle,
                                                                        UIBarButtonItemStyle.Done,
                                                                        Dismiss);
            }
            if (_picker.UseCustomFontForNavigationBar)
            {
                var barButtonItemAttributes = new UITextAttributes {
                    Font = FontParser.GetFont(_picker.PickerFontName, _picker.PickerFontHeaderSize)
                };
                NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal);
                NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted);
            }
        }
示例#2
0
        public override void WillDisplayHeaderView(UITableView tableView, UIView headerView, nint section)
        {
            var header = (UITableViewHeaderFooterView)headerView;

            header.ContentView.BackgroundColor    = UIColor.Clear;
            header.BackgroundView.BackgroundColor = _picker.PickerBackgroundColor;

            // Default is a bold font, but keep this styled as a normal font
            header.TextLabel.Font      = FontParser.GetFont(_picker.PickerFontName, _picker.PickerFontNormalSize);
            header.TextLabel.TextColor = _picker.PickerTextColor;
        }
        public sealed override async void ViewWillAppear(bool animated)
        {
            try {
                await _viewDidLoadAsyncTask;
                base.ViewWillAppear(animated);

                _finishedPickingAssets = false;

                // Ensure nav and toolbar customisations are set. Defaults are in place, but the user may have changed them
                View.BackgroundColor = PickerBackgroundColor;

                _navigationController.Toolbar.Translucent = true;

                _navigationController.Toolbar.BarTintColor    = ToolbarBarTintColor;
                _navigationController.Toolbar.TintColor       = ToolbarTintColor;
                _navigationController.Toolbar.BackgroundColor = ToolbarBackgroundColor;

                _navigationController.NavigationBar.TintColor       = NavigationBarTintColor;
                _navigationController.NavigationBar.BarTintColor    = NavigationBarBarTintColor;
                _navigationController.NavigationBar.BackgroundColor = NavigationBarBackgroundColor;

                UIStringAttributes attributes;
                if (UseCustomFontForNavigationBar)
                {
                    attributes = new UIStringAttributes {
                        ForegroundColor = NavigationBarTextColor,
                        Font            = FontParser.GetFont(PickerBoldFontName, PickerFontHeaderSize)
                    };
                }
                else
                {
                    attributes = new UIStringAttributes {
                        ForegroundColor = NavigationBarTextColor
                    };
                }
                _navigationController.NavigationBar.TitleTextAttributes = attributes;

                UpdateToolbar();
                _viewWillAppearAsyncTask = ViewWillAppearAsync();
                await _viewWillAppearAsyncTask;
            }
            catch (Exception ex)
            {
                //Handle
                Console.WriteLine(ex);
            }
        }
示例#4
0
        private void SetupButtons()
        {
            if (_picker.AllowsMultipleSelection)
            {
                var doneTitle = _picker.CustomDoneButtonTitle ?? "picker.navigation.done-button".Translate(defaultValue: "Done");
                NavigationItem.RightBarButtonItem = new UIBarButtonItem(doneTitle,
                                                                        UIBarButtonItemStyle.Done,
                                                                        FinishPickingAssets);

                NavigationItem.RightBarButtonItem.Enabled = !_picker.AutoDisableDoneButton || _picker.SelectedAssets.Any();
            }
            else
            {
                var cancelTitle = _picker.CustomCancelButtonTitle ?? "picker.navigation.cancel-button".Translate(defaultValue: "Cancel");
                NavigationItem.RightBarButtonItem = new UIBarButtonItem(cancelTitle,
                                                                        UIBarButtonItemStyle.Done,
                                                                        Dismiss);
            }

            if (!string.IsNullOrWhiteSpace(_picker.CustomBackButtonTitle))
            {
                NavigationItem.BackButtonTitle = _picker.CustomBackButtonTitle;
            }
            if (UIDevice.CurrentDevice.CheckSystemVersion(14, 0))
            {
                NavigationItem.BackButtonDisplayMode = _picker.BackButtonDisplayMode;
            }
            else
            {
                if (_picker.BackButtonDisplayMode == UINavigationItemBackButtonDisplayMode.Minimal)
                {
                    NavigationItem.BackButtonTitle = "";
                }
            }

            if (_picker.UseCustomFontForNavigationBar)
            {
                var barButtonItemAttributes = new UITextAttributes {
                    Font = FontParser.GetFont(_picker.PickerFontName, _picker.PickerFontHeaderSize)
                };
                NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Normal);
                NavigationItem.RightBarButtonItem.SetTitleTextAttributes(barButtonItemAttributes, UIControlState.Highlighted);
            }
        }
示例#5
0
        public override void WillDisplayHeaderView(UITableView tableView, UIView headerView, nint section)
        {
            var header = (UITableViewHeaderFooterView)headerView;

            header.ContentView.BackgroundColor = UIColor.Clear;

            if (header.BackgroundView != null)
            {
                header.BackgroundView.BackgroundColor = _picker.PickerBackgroundColor;
            }
            else if (UIDevice.CurrentDevice.CheckSystemVersion(14, 0))
            {
                if (header.BackgroundConfiguration != null)
                {
                    header.BackgroundConfiguration.BackgroundColor = _picker.PickerBackgroundColor;
                }
            }

            // Default is a bold font, but keep this styled as a normal font
            header.TextLabel.Font      = FontParser.GetFont(_picker.PickerFontName, _picker.PickerFontNormalSize);
            header.TextLabel.TextColor = _picker.PickerTextColor;
        }
示例#6
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      = FontParser.GetFont(_picker.PickerFontName, _picker.PickerFontHeaderSize);
            cell.TextLabel.Text      = _collectionsFetchResultsTitles[indexPath.Section][indexPath.Row];
            cell.TextLabel.TextColor = _picker.PickerTextColor;

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

            // Display the number of assets
            if (_picker.DisplayAlbumsNumberOfAssets)
            {
                cell.DetailTextLabel.Font = FontParser.GetFont(_picker.PickerFontName, _picker.PickerFontNormalSize);
                // Just use the number of assets. Album app does this:
                cell.DetailTextLabel.Text      = string.Format("{0:0}", assetsFetchResult.Count);
                cell.DetailTextLabel.TextColor = _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[_picker.GridSortOrder == SortOrder.Ascending ? numberOfAssets - 1 : 0];
                cell.SetVideoLayout(asset.MediaType == PHAssetMediaType.Video);
                _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[_picker.GridSortOrder == SortOrder.Ascending ? numberOfAssets - 2 : 1];
                    _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[_picker.GridSortOrder == SortOrder.Ascending ? numberOfAssets - 3 : 2];
                    _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);
        }
示例#7
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;

            // Buttons
            var barButtonItemAttributes = new UITextAttributes
            {
                Font = FontParser.GetFont(_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);

            // Test
            SelectAllAlbumsCell();
        }