Exemplo n.º 1
0
 /// <summary>
 /// Creates a new data source for showing images and video from a local folder
 /// </summary>
 /// <param name="albumView"><see cref="AlbumView"/> this data source is feeding</param>
 /// <param name="cellSize">Optional: <see cref="CGSize"/> with the desired cell size.
 /// Defaults to 100x100.</param>
 /// <param name="mediaTypes"><see cref="MediaType"/> media types to show.
 /// Default is both <see cref="MediaType.Image"/> and <see cref="MediaType.Video"/>.</param>
 public LocalFilesDataSource(AlbumView albumView, CGSize cellSize = default(CGSize),
                             MediaType mediaTypes = MediaType.Image | MediaType.Video)
 {
     _albumView  = albumView;
     _cellSize   = cellSize != CGSize.Empty ? cellSize : new CGSize(100, 100);
     _mediaTypes = mediaTypes;
 }
Exemplo n.º 2
0
        private static void ChangeVideo(MediaItem item, AlbumView albumView)
        {
            ChangeAlbumViewVisibility(item, albumView);

            var sourceMovieUrl = new NSUrl(item.Path);

            albumView.MoviePlayerController.ContentUrl = sourceMovieUrl;
            albumView.MoviePlayerController.PrepareToPlay();
        }
Exemplo n.º 3
0
        private static void ChangeImage(MediaItem item, AlbumView albumView)
        {
            ChangeAlbumViewVisibility(item, albumView);

            var image = UIImage.FromFile(item.Path);

            albumView.ImageCropView.ImageSize = image.Size;
            albumView.ImageCropView.Image     = image;
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            AlbumView.LayoutIfNeeded();
            _cameraView.LayoutIfNeeded();

            var albumDataSource = LazyDataSource(AlbumView, AlbumView.CellSize, MediaTypes);
            var albumDelegate   = LazyDelegate(AlbumView, albumDataSource);

            AlbumDataSource = albumDataSource;
            AlbumDelegate   = albumDelegate;

            var local = AlbumDataSource as LocalFilesDataSource;

            if (local != null)
            {
                local.InitialSelectedImagePath = InitialSelectedImagePath;
            }

            AlbumView.Initialize(AlbumDataSource, AlbumDelegate);
            _cameraView.Initialize(OnImageFinished);

            local?.ShowFirstImage();

            if (HasVideo)
            {
                _videoView.LayoutIfNeeded();
                _videoView.Initialize(OnVideoFinished);
                _videoView.CameraUnauthorized += OnCameraUnauthorized;
            }

            _libraryButton.TouchUpInside += LibraryButtonPressed;
            _menuView.Closed             += CloseButtonPressed;
            _menuView.Done += DoneButtonPressed;
            _cameraButton.TouchUpInside += CameraButtonPressed;
            _videoButton.TouchUpInside  += VideoButtonPressed;

            AlbumDataSource.CameraRollUnauthorized += OnCameraRollUnauthorized;
            _cameraView.CameraUnauthorized         += OnCameraUnauthorized;

            switch (Configuration.ModeOrder)
            {
            case ModeOrder.CameraFirst:
                ChangeMode(Mode.Camera);
                break;

            case ModeOrder.VideoFirst:
                ChangeMode(HasVideo ? Mode.Video : Mode.Library);     // Fallback to Library if the Video is disabled
                break;

            case ModeOrder.LibraryFirst:
                ChangeMode(Mode.Library);
                break;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create an instance of <see cref="PhotoGalleryDataSource"/>
        /// </summary>
        /// <param name="albumView"><see cref="AlbumView"/> attached to</param>
        /// <param name="cellSize"><see cref="CGSize"/> with cell size. If <see cref="CGSize.Empty"/>
        /// it will default to 100x100</param>
        /// <param name="mediaTypes"><see cref="MediaType"/> media types to show.
        /// Default is both <see cref="MediaType.Image"/> and <see cref="MediaType.Video"/>.</param>
        public PhotoGalleryDataSource(AlbumView albumView, CGSize cellSize,
                                      MediaType mediaTypes = MediaType.Image | MediaType.Video)
        {
            _albumView  = albumView;
            _cellSize   = cellSize != CGSize.Empty ? cellSize : new CGSize(100, 100);
            _scale      = UIScreen.MainScreen.Scale;
            _mediaTypes = mediaTypes;

            CheckPhotoAuthorization(OnAuthorized);
        }
Exemplo n.º 6
0
        private void CreateViews()
        {
            View.BackgroundColor = Configuration.BackgroundColor;

            if (CellSize == CGSize.Empty)
            {
                CellSize = CalculateCellSize();
            }

            _album = new AlbumView(CellSize)
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = Configuration.BackgroundColor
            };

            _menu = new MenuView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = Configuration.BackgroundColor
            };

            Add(_menu);
            Add(_album);
        }
Exemplo n.º 7
0
 private static void ChangeAlbumViewVisibility(MediaItem item, AlbumView albumView)
 {
     albumView.ImageCropView.Hidden = item.MediaType == MediaType.Video;
     albumView.MovieView.Hidden     = item.MediaType == MediaType.Image;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Create a new Delegate for Local Files
 /// </summary>
 /// <param name="albumView"><see cref="AlbumView"/> delegate attached to</param>
 /// <param name="dataSource"><see cref="LocalFilesDataSource"/> data source attached to</param>
 public LocalFilesDelegate(AlbumView albumView, LocalFilesDataSource dataSource)
     : base(albumView)
 {
     _dataSource = dataSource;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Create a new delegate
 /// </summary>
 /// <param name="albumView"><see cref="AlbumView"/> attached to</param>
 /// <param name="dataSource"><see cref="PhotoGalleryDataSource"/> attached to</param>
 public PhotoGalleryDelegate(AlbumView albumView, PhotoGalleryDataSource dataSource)
     : base(albumView)
 {
     _albumView  = albumView;
     _dataSource = dataSource;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Instantiate a AlbumDelegate
 /// </summary>
 /// <param name="albumView"><see cref="AlbumView"/> the delegate is attached to</param>
 protected BaseAlbumDelegate(AlbumView albumView)
 {
     _albumView = albumView;
 }
Exemplo n.º 11
0
        /// <inheritdoc />
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _menuView = new MenuView
            {
                BackgroundColor = Configuration.BackgroundColor,
                TranslatesAutoresizingMaskIntoConstraints = false,
                Opaque             = false,
                AccessibilityLabel = "MenuView"
            };
            _menuView.AddBottomBorder(UIColor.Black, 1);
            View.AddSubviews(_menuView);

            _libraryButton = new UIButton {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LineBreakMode       = UILineBreakMode.MiddleTruncation,
                HorizontalAlignment = UIControlContentHorizontalAlignment.Center,
                VerticalAlignment   = UIControlContentVerticalAlignment.Center,
                ContentMode         = UIViewContentMode.ScaleToFill,
                ContentEdgeInsets   = new UIEdgeInsets(2, 2, 2, 2),
                AccessibilityLabel  = "LibraryButton"
            };

            _videoButton = new UIButton {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LineBreakMode       = UILineBreakMode.MiddleTruncation,
                HorizontalAlignment = UIControlContentHorizontalAlignment.Center,
                VerticalAlignment   = UIControlContentVerticalAlignment.Center,
                ContentMode         = UIViewContentMode.ScaleToFill,
                ContentEdgeInsets   = new UIEdgeInsets(2, 2, 2, 2),
                AccessibilityLabel  = "VideoButton"
            };

            _cameraButton = new UIButton {
                TranslatesAutoresizingMaskIntoConstraints = false,
                LineBreakMode       = UILineBreakMode.MiddleTruncation,
                HorizontalAlignment = UIControlContentHorizontalAlignment.Center,
                VerticalAlignment   = UIControlContentVerticalAlignment.Center,
                ContentMode         = UIViewContentMode.ScaleToFill,
                ContentEdgeInsets   = new UIEdgeInsets(2, 2, 2, 2),
                AccessibilityLabel  = "PhotoButton"
            };

            View.AddSubviews(_libraryButton, _cameraButton);

            _cameraView = new CameraView {
                BackgroundColor = Configuration.BackgroundColor,
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            if (CellSize == CGSize.Empty)
            {
                CellSize = CalculateCellSize();
            }

            AlbumView = new AlbumView(CellSize)
            {
                BackgroundColor = Configuration.BackgroundColor,
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            View.AddSubviews(_cameraView, AlbumView);

            View.AddConstraints(
                _menuView.Height().EqualTo(50),
                _menuView.AtTopOf(View),
                _menuView.AtLeftOf(View),
                _menuView.AtRightOf(View),

                AlbumView.AtLeftOf(View),
                AlbumView.AtRightOf(View),
                AlbumView.Below(_menuView),

                _cameraView.WithSameLeft(AlbumView),
                _cameraView.WithSameRight(AlbumView),
                _cameraView.Below(_menuView),

                _libraryButton.AtLeftOf(View),
                _libraryButton.AtBottomOf(View),

                _cameraButton.ToRightOf(_libraryButton),
                _cameraButton.AtBottomOf(View),

                _libraryButton.Height().EqualTo(45),
                _cameraButton.Height().EqualTo(45),

                _cameraButton.WithSameWidth(_libraryButton),

                AlbumView.Above(_libraryButton),
                _cameraView.Above(_libraryButton)
                );

            View.BackgroundColor = Configuration.BackgroundColor;

            var albumImage  = Configuration.AlbumImage ?? UIImage.FromBundle("ic_insert_photo");
            var cameraImage = Configuration.CameraImage ?? UIImage.FromBundle("ic_photo_camera");
            var videoImage  = Configuration.VideoImage ?? UIImage.FromBundle("ic_videocam");

            if (Configuration.TintIcons)
            {
                albumImage  = albumImage?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                cameraImage = cameraImage?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                videoImage  = videoImage?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
            }

            _libraryButton.SetImage(albumImage, UIControlState.Normal);
            _libraryButton.SetImage(albumImage, UIControlState.Highlighted);
            _libraryButton.SetImage(albumImage, UIControlState.Selected);

            _cameraButton.SetImage(cameraImage, UIControlState.Normal);
            _cameraButton.SetImage(cameraImage, UIControlState.Highlighted);
            _cameraButton.SetImage(cameraImage, UIControlState.Selected);

            _videoButton.SetImage(videoImage, UIControlState.Normal);
            _videoButton.SetImage(videoImage, UIControlState.Highlighted);
            _videoButton.SetImage(videoImage, UIControlState.Selected);

            if (Configuration.TintIcons)
            {
                _libraryButton.TintColor = Configuration.TintColor;
                _libraryButton.AdjustsImageWhenHighlighted = false;
                _cameraButton.TintColor = Configuration.TintColor;
                _cameraButton.AdjustsImageWhenHighlighted = false;
                _videoButton.TintColor = Configuration.TintColor;
                _videoButton.AdjustsImageWhenHighlighted = false;
            }

            _cameraButton.ClipsToBounds  = true;
            _libraryButton.ClipsToBounds = true;
            _videoButton.ClipsToBounds   = true;

            if (HasVideo)
            {
                _videoView = new VideoView {
                    BackgroundColor = Configuration.BackgroundColor,
                    TranslatesAutoresizingMaskIntoConstraints = false
                };

                View.AddSubviews(_videoView, _videoButton);

                View.AddConstraints(
                    _videoView.WithSameLeft(AlbumView),
                    _videoView.WithSameRight(AlbumView),
                    _videoView.Below(_menuView),

                    _videoButton.ToRightOf(_cameraButton),
                    _videoButton.AtBottomOf(View),
                    _videoButton.AtRightOf(View),
                    _videoButton.WithSameWidth(_cameraButton),
                    _videoButton.Height().EqualTo(45),

                    _videoView.Above(_libraryButton)
                    );
            }
            else
            {
                View.AddConstraints(
                    _cameraButton.AtRightOf(View)
                    );
            }
        }