public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var images = new List <ImageWithInfo>();

            var albums = value as Albums;

            if (!(albums?.Count > 0))
            {
                return(null);
            }

            foreach (Album album in albums)
            {
                var image = new ImageWithInfo
                {
                    Title            = album.Name,
                    TitleColor       = Color.White,
                    Description      = album.Artists?.Count > 0 ? album.Artists[0].Name : string.Empty,
                    DescriptionColor = Color.Silver,
                    Source           = album.Images?.Count > 0 ? album.Images[1].Url : string.Empty,
                };

                image.GestureRecognizers.Add(new TapGestureRecognizer
                {
                    Command          = TapCommand,
                    CommandParameter = album.Id
                });

                images.Add(image);
            }

            return(images);
        }
        private async void OnPickPictureCommand()
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await Application.Current.MainPage.DisplayAlert("Alert", "Can't open album", "OK");

                return;
            }

            var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
            {
                PhotoSize = PhotoSize.Full
            });

            if (file == null)
            {
                return;
            }

            var image = new ImageWithInfo();

            image.Name = "New picture";
            //image.Url = ImageSource.FromStream(file.Path);


            image.Source = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                return(stream);
            });

            Images.Add(image);
        }
Esempio n. 3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var images = new List <ImageWithInfo>();

            var artists = value as Artists;

            if (!(artists?.Count > 0))
            {
                return(null);
            }

            foreach (Artist artist in artists)
            {
                var image = new ImageWithInfo
                {
                    Title      = artist.Name,
                    TitleColor = Color.White,
                    Source     = artist.Images?.Count > 0 ? artist.Images[1].Url : string.Empty
                };

                image.GestureRecognizers.Add(new TapGestureRecognizer
                {
                    Command          = TapCommand,
                    CommandParameter = artist.Id
                });

                images.Add(image);
            }

            return(images);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var images = new List <ImageWithInfo>();

            var tracks = value as Tracks;

            if (tracks?.Count <= 0)
            {
                return(null);
            }

            foreach (Track track in tracks)
            {
                var image = new ImageWithInfo
                {
                    Title            = track.Name,
                    TitleColor       = Color.White,
                    Description      = track.Artists[0].Name,
                    DescriptionColor = Color.Silver,
                    Source           = track.Album.Images[1].Url,
                };

                image.GestureRecognizers.Add(new TapGestureRecognizer
                {
                    Command          = TapCommand,
                    CommandParameter = track.Id
                });

                images.Add(image);
            }

            return(images);
        }
        private async void OnTakePictureCommand()
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await Application.Current.MainPage.DisplayAlert("Alert", "Camera can't be opened right now", "OK");

                return;
            }

            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                Directory = "Sample",
                Name      = "test.jpg"
            });

            if (file == null)
            {
                return;
            }

            var image = new ImageWithInfo();

            image.Name = "New picture";
            //image.Url = ImageSource.FromStream(file.Path);


            image.Source = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                return(stream);
            });

            Images.Add(image);
        }