Ejemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var rotateTap = new UITapGestureRecognizer(RotateTap);

            rotate.AddGestureRecognizer(rotateTap);

            var zoomTap = new UITapGestureRecognizer(ZoomTap);

            resize.AddGestureRecognizer(zoomTap);

            var multiselectTap = new UITapGestureRecognizer(MultiSelectTap);

            multiSelect.AddGestureRecognizer(multiselectTap);

            bottomArrow.Transform = CGAffineTransform.MakeRotation((float)(Math.PI));

            source = new PhotoCollectionViewSource();
            photoCollection.Source = source;
            photoCollection.RegisterClassForCell(typeof(PhotoCollectionViewCell), nameof(PhotoCollectionViewCell));

            photoCollection.SetCollectionViewLayout(new UICollectionViewFlowLayout()
            {
                ItemSize                = Constants.CellSize,
                MinimumLineSpacing      = 1,
                MinimumInteritemSpacing = 1,
            }, false);

            delegateP = new PhotoCollectionViewFlowDelegate(source);
            photoCollection.Delegate = delegateP;

            delegateP.CellClicked += CellAction;

            _cropView = new CropView(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Width));

            _cropView.ZoomingStarted += (object sender, UIScrollViewZoomingEventArgs e) =>
            {
                NavigationItem.RightBarButtonItem.Enabled = false;
            };

            _cropView.ZoomingEnded += (object sender, ZoomingEndedEventArgs e) =>
            {
                NavigationItem.RightBarButtonItem.Enabled = true;
            };

            cropBackgroundView.BackgroundColor = Constants.R245G245B245;
            cropBackgroundView.AddSubview(_cropView);
            NavigationController.NavigationBar.Translucent = false;
            SetBackButton();
        }
Ejemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var rotateTap = new UITapGestureRecognizer(RotateTap);

            rotate.AddGestureRecognizer(rotateTap);

            var zoomTap = new UITapGestureRecognizer(ZoomTap);

            resize.AddGestureRecognizer(zoomTap);

            var multiselectTap = new UITapGestureRecognizer(MultiSelectTap);

            multiSelect.AddGestureRecognizer(multiselectTap);

            bottomArrow.Transform = CGAffineTransform.MakeRotation((float)(Math.PI));

            source = new PhotoCollectionViewSource(_m);
            photoCollection.Source = source;
            photoCollection.RegisterClassForCell(typeof(PhotoCollectionViewCell), nameof(PhotoCollectionViewCell));

            photoCollection.SetCollectionViewLayout(new UICollectionViewFlowLayout()
            {
                ItemSize                = Constants.CellSize,
                MinimumLineSpacing      = 1,
                MinimumInteritemSpacing = 1,
            }, false);

            delegateP = new PhotoCollectionViewFlowDelegate(source);
            photoCollection.Delegate = delegateP;

            delegateP.CellClicked += CellAction;

            _cropView = new CropView(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Width));

            _cropView.ZoomingStarted += (object sender, UIScrollViewZoomingEventArgs e) =>
            {
                NavigationItem.RightBarButtonItem.Enabled = false;
            };

            _cropView.ZoomingEnded += (object sender, ZoomingEndedEventArgs e) =>
            {
                NavigationItem.RightBarButtonItem.Enabled = true;
            };

            var albums       = new List <PHAssetCollection>();
            var sortedAlbums = new List <Tuple <string, PHFetchResult> >();
            var fetchOptions = new PHFetchOptions();

            var allAlbums = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.Album, PHAssetCollectionSubtype.AlbumRegular, null)
                            .Cast <PHAssetCollection>();

            albums.AddRange(allAlbums);
            var smartAlbums = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.AlbumRegular, null)
                              .Cast <PHAssetCollection>();

            albums.AddRange(smartAlbums);
            fetchOptions.Predicate = NSPredicate.FromFormat("mediaType == %d", FromObject(PHAssetMediaType.Image));

            foreach (var item in albums)
            {
                var firstAsset = PHAsset.FetchAssets(item, fetchOptions);
                if (firstAsset.Count > 0)
                {
                    sortedAlbums.Add(new Tuple <string, PHFetchResult>(item.LocalizedTitle, firstAsset));
                }
            }

            sortedAlbums = sortedAlbums.OrderByDescending(a => a.Item2.Count).ToList();

            _modalFolderView.BackgroundColor = UIColor.White;

            var folderTable = new UITableView();

            folderTable.Bounces         = false;
            folderTable.AllowsSelection = false;
            folderTable.RowHeight       = 90;
            folderTable.SeparatorStyle  = UITableViewCellSeparatorStyle.None;
            var folderSource = new FolderTableViewSource(sortedAlbums);

            folderSource.CellAction += (ActionType arg1, Tuple <string, PHFetchResult> arg2) =>
            {
                TitleTapped();
                _titleLabel.Text = arg2.Item1;
                source.UpdateFetchResult(arg2.Item2);
                photoCollection.SetContentOffset(new CGPoint(0, 0), false);
                photoCollection.ReloadData();
                if (!source.MultiPickMode)
                {
                    delegateP.ItemSelected(photoCollection, NSIndexPath.FromItemSection(0, 0));
                }
            };
            folderTable.Source = folderSource;
            _modalFolderView.AddSubview(folderTable);
            folderTable.RegisterClassForCellReuse(typeof(AlbumTableViewCell), nameof(AlbumTableViewCell));
            folderTable.AutoPinEdgesToSuperviewEdges();
            folderTable.ReloadData();

            cropBackgroundView.BackgroundColor = Constants.R245G245B245;
            cropBackgroundView.AddSubview(_cropView);
            NavigationController.NavigationBar.Translucent = false;
            SetBackButton();

            _titleLabel.Text = sortedAlbums.FirstOrDefault()?.Item1;
            source.UpdateFetchResult(sortedAlbums.FirstOrDefault()?.Item2);
        }