Ejemplo n.º 1
0
        // its OK to be null
        public static FileLocation GetPreviewFileLocation(PhotoConstructor photo)
        {
            List <PhotoSize> photoSizes = photo.sizes;

            FileLocation desiredSize = null;

            foreach (var photoSize in photoSizes)
            {
                if (photoSize.Constructor != Constructor.photoSize)
                {
                    continue;
                }

                PhotoSizeConstructor photoSizeConstructor = (PhotoSizeConstructor)photoSize;
                if (photoSizeConstructor.type == "s")
                {
                    desiredSize = photoSizeConstructor.location;
                }
                else if (photoSizeConstructor.type == "m")
                {
                    desiredSize = photoSizeConstructor.location;
                    break;
                }
            }

            return(desiredSize);
        }
Ejemplo n.º 2
0
        public PinchAndZoom()
        {
            InitializeComponent();

            media = MediaTransitionHelper.Instance.Media;

            if (media.Constructor == Constructor.messageMediaPhoto)
            {
                ImageViewportElement.Visibility = Visibility.Visible;
                PlaybackControls.Visibility     = Visibility.Collapsed;

                MessageMediaPhotoConstructor cons = (MessageMediaPhotoConstructor)media;

                if (cons.photo.Constructor == Constructor.photoEmpty)
                {
                }
                else if (cons.photo.Constructor == Constructor.photo)
                {
                    PhotoConstructor photoConstructor = (PhotoConstructor)cons.photo;
                    author = TelegramSession.Instance.GetUser(photoConstructor.user_id);
                    MetaInfoAuthor.Text = author.FullName;
                    MetaInfoDate.Text   = Formatters.FormatDialogDateTimestampUnix(photoConstructor.date);
                }

                DoLoadPhoto();
                return;
            }
            else if (media.Constructor == Constructor.messageMediaVideo)
            {
                ImageViewportElement.Visibility = Visibility.Collapsed;
                PlaybackControls.Visibility     = Visibility.Visible;
                VideoPlayerElement.Visibility   = Visibility.Visible;
                PlaybackButton.Visibility       = Visibility.Visible;

                MessageMediaVideoConstructor cons = (MessageMediaVideoConstructor)media;

                if (cons.video.Constructor == Constructor.videoEmpty)
                {
                }
                else if (cons.video.Constructor == Constructor.video)
                {
                    VideoConstructor videoConstructor = (VideoConstructor)cons.video;
                    author = TelegramSession.Instance.GetUser(videoConstructor.user_id);

                    MetaInfoAuthor.Text = author.FullName;
                    MetaInfoDate.Text   = Formatters.FormatDialogDateTimestampUnix(videoConstructor.date);
                }

                VideoPlayerElement.MediaEnded += delegate {
                    PlaybackButton.Visibility = Visibility.Visible;
                };
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 3
0
        private void OnSaveClick(object sender, RoutedEventArgs e)
        {
            if (media.Constructor == Constructor.messageMediaPhoto)
            {
                WriteableBitmap wbm = new WriteableBitmap(_bitmap);

                Photo photo = ((MessageMediaPhotoConstructor)media).photo;
                if (photo.Constructor != Constructor.photo)
                {
                    return;
                }

                PhotoConstructor photoCons = (PhotoConstructor)photo;

                wbm.SaveToMediaLibrary(photoCons.caption == "" ? Helpers.GenerateRandomUlong().ToString("X") : photoCons.caption);
            }
        }
Ejemplo n.º 4
0
        // its OK to be null
        public static FileLocation GetPreviewFileLocation(PhotoConstructor photo) {
            List<PhotoSize> photoSizes = photo.sizes;

            FileLocation desiredSize = null;
            foreach (var photoSize in photoSizes) {
                if (photoSize.Constructor != Constructor.photoSize)
                    continue;

                PhotoSizeConstructor photoSizeConstructor = (PhotoSizeConstructor) photoSize;
                if (photoSizeConstructor.type == "s") {
                    desiredSize = photoSizeConstructor.location;
                } else if (photoSizeConstructor.type == "m") {
                    desiredSize = photoSizeConstructor.location;
                    break;
                }
            }

            return desiredSize;
        }
        TgMedia MapInternal(PhotoConstructor photo)
        {
            var biggestPhoto = photo.sizes?.OfType <PhotoSizeConstructor>()
                               .MaxBy <PhotoSizeConstructor, long>(photoSize => photoSize.h * photoSize.w);

            var location = biggestPhoto?.location as FileLocationConstructor;

            if (location != null)
            {
                return new TgMedia
                       {
                           Id       = photo.id,
                           Location = MapLocation(location)
                       }
            }
            ;

            return(MapCachedPhoto(photo));
        }
        static TgMedia MapCachedPhoto(PhotoConstructor photo)
        {
            var cachedPhoto = photo.sizes?.OfType <PhotoCachedSizeConstructor>().FirstOrDefault();

            if (cachedPhoto?.bytes == null || !cachedPhoto.bytes.Any())
            {
                return(null);
            }

            //var type = cachedPhoto.type;

            var path = $"{photo.id}.jpg";

            File.WriteAllBytes(path, cachedPhoto.bytes);

            return(new TgMedia
            {
                Id = photo.id,
                Location = MapLocation(cachedPhoto.location as FileLocationConstructor),
                Path = path
            });
        }