Example #1
0
        protected static bool IsInlineMedia(TLMessageMediaBase media)
        {
            if (media == null)
            {
                return(false);
            }

            if (media.TypeId == TLType.MessageMediaContact)
            {
                return(true);
            }
            else if (media.TypeId == TLType.MessageMediaGeoLive)
            {
                return(true);
            }
            else if (media.TypeId == TLType.MessageMediaVenue)
            {
                return(true);
            }
            else if (media.TypeId == TLType.MessageMediaPhoto)
            {
                var photoMedia = media as TLMessageMediaPhoto;
                if (string.IsNullOrWhiteSpace(photoMedia.Caption))
                {
                    return(false);
                }

                return(true);
            }
            else if (media.TypeId == TLType.MessageMediaDocument)
            {
                var documentMedia = media as TLMessageMediaDocument;
                if (TLMessage.IsMusic(documentMedia.Document))
                {
                    return(true);
                }
                else if (TLMessage.IsVoice(documentMedia.Document))
                {
                    return(true);
                }
                else if (TLMessage.IsVideo(documentMedia.Document))
                {
                    if (string.IsNullOrWhiteSpace(documentMedia.Caption))
                    {
                        return(false);
                    }
                }
                else if (TLMessage.IsGif(documentMedia.Document))
                {
                    if (string.IsNullOrWhiteSpace(documentMedia.Caption))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
        private string UpdateGlyph(TLDocument document)
        {
            Visibility = Visibility.Visible;

            var fileName = document.GetFileName();

            if (File.Exists(FileUtils.GetTempFileName(fileName)))
            {
                if (TLMessage.IsVideo(document) || TLMessage.IsRoundVideo(document) || TLMessage.IsGif(document) || TLMessage.IsMusic(document))
                {
                    return("\uE102");
                }

                return("\uE160");
            }
            else if (document.IsTransferring)
            {
                return("\uE10A");
            }
            else if (document.DownloadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }
            else if (document.UploadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }

            return("\uE118");
        }
        private IUploadManager ChooseUploadManager(TLDocument document)
        {
            if (TLMessage.IsVideo(document))
            {
                return(UnigramContainer.Current.ResolveType <IUploadVideoManager>());
            }

            return(UnigramContainer.Current.ResolveType <IUploadDocumentManager>());
        }
Example #4
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var documentMedia = value as TLMessageMediaDocument;

            if (documentMedia != null)
            {
                var document = documentMedia.Document as TLDocument;
                if (document != null)
                {
                    var fileName = document.GetFileName();
                    if (File.Exists(Path.Combine(ApplicationData.Current.TemporaryFolder.Path, fileName)))
                    {
                        if (TLMessage.IsVideo(document))
                        {
                            return(Symbol.Play);
                        }

                        if (TLMessage.IsVoice(document))
                        {
                            return(Symbol.Play);
                        }

                        return(Symbol.Page2);
                    }
                }
            }

            //var videoMedia = value as TLMessageMediaVideo;
            //if (videoMedia != null)
            //{
            //    var video = videoMedia.Video as TLVideo;
            //    if (video != null)
            //    {
            //        var fileName = video.GetFileName();
            //        if (File.Exists(Path.Combine(ApplicationData.Current.LocalFolder.Path, fileName)) || Task.Run(() => File.Exists(videoMedia.IsoFileName)).Result)
            //        {
            //            return Symbol.Play;
            //        }
            //    }
            //}

            //var audioMedia = value as TLMessageMediaAudio;
            //if (audioMedia != null)
            //{
            //    var audio = audioMedia.Audio as TLAudio;
            //    if (audio != null)
            //    {
            //        var fileName = audio.GetFileName();
            //        if (File.Exists(Path.Combine(ApplicationData.Current.LocalFolder.Path, fileName)))
            //        {
            //            return Symbol.Play;
            //        }
            //    }
            //}

            return(Symbol.Download);
        }
Example #5
0
        protected static bool IsFullMedia(TLMessageMediaBase media, bool width = false)
        {
            if (media == null)
            {
                return(false);
            }

            if (media.TypeId == TLType.MessageMediaGeo)
            {
                return(true);
            }
            else if (media.TypeId == TLType.MessageMediaGeoLive)
            {
                return(true);
            }
            else if (media.TypeId == TLType.MessageMediaVenue)
            {
                return(true);
            }
            else if (media.TypeId == TLType.MessageMediaPhoto)
            {
                return(true);
            }
            else if (media.TypeId == TLType.MessageMediaDocument)
            {
                var documentMedia = media as TLMessageMediaDocument;
                if (TLMessage.IsGif(documentMedia.Document))
                {
                    return(true);
                }
                else if (TLMessage.IsVideo(documentMedia.Document))
                {
                    return(true);
                }
            }
            else if (media.TypeId == TLType.MessageMediaInvoice && width)
            {
                var invoiceMedia = media as TLMessageMediaInvoice;
                if (invoiceMedia.HasPhoto && invoiceMedia.Photo != null)
                {
                    return(true);
                }
            }
            //else if (media.TypeId == TLType.MessageMediaWebPage && width)
            //{
            //    var webPageMedia = media as TLMessageMediaWebPage;
            //    var webPage = webPageMedia.WebPage as TLWebPage;
            //    if (webPage != null && MediaTemplateSelector.IsWebPagePhotoTemplate(webPage))
            //    {
            //        return true;
            //    }
            //}

            return(false);
        }
Example #6
0
 public DialogGalleryViewModel(TLInputPeerBase peer, TLMessage selected, IMTProtoService protoService)
     : base(protoService, null, null)
 {
     if (selected.Media is TLMessageMediaPhoto photoMedia || selected.IsVideo() || selected.IsRoundVideo() || selected.IsGif())
     {
         Items = new MvxObservableCollection <GalleryItem> {
             new GalleryMessageItem(selected)
         };
         SelectedItem = Items[0];
         FirstItem    = Items[0];
     }
Example #7
0
        public TLBitmapSource(TLDocument document, bool thumbnail)
        {
            _source = document;

            if (TLMessage.IsSticker(document))
            {
                if (thumbnail)
                {
                    SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                    return;
                }

                if (TrySetWebPSource(document, PHASE_FULL))
                {
                    return;
                }

                SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                SetWebPSource(document, document, document.Size, PHASE_FULL);
            }
            else if (TLMessage.IsGif(document))
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);

                if (ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.GIF))
                {
                    SetDownloadSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else if (TLMessage.IsVideo(document))
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);

                if (ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.Video))
                {
                    SetDownloadSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else if (TLMessage.IsRoundVideo(document))
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);

                if (ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.Round))
                {
                    SetDownloadSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);
            }
        }
Example #8
0
        public DialogGalleryViewModel(IMTProtoService protoService, ICacheService cacheService, TLInputPeerBase peer, TLMessage selected)
            : base(protoService, cacheService, null)
        {
            _group = new MvxObservableCollection <GalleryItem>();
            _peer  = peer;

            if (selected.Media is TLMessageMediaPhoto photoMedia || selected.IsVideo())
            {
                Items = new MvxObservableCollection <GalleryItem> {
                    new GalleryMessageItem(selected)
                };
                SelectedItem = Items[0];
                FirstItem    = Items[0];
            }
Example #9
0
        public TLBitmapSource(TLDocument document, bool thumbnail)
        {
            _source = document;

            if (TLMessage.IsSticker(document))
            {
                if (thumbnail)
                {
                    SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                    return;
                }

                if (TrySetWebPSource(document, PHASE_FULL) == false)
                {
                    SetWebPSource(null, document.Thumb, PHASE_THUMBNAIL);
                    SetWebPSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else if (TLMessage.IsGif(document))
            {
                if (thumbnail)
                {
                    SetSource(null, document.Thumb, PHASE_THUMBNAIL);
                    return;
                }

                _renderer = _animatedFactory.CreateRenderer(320, 320);
                Image     = _renderer.ImageSource;

                if (TrySetAnimatedSource(document, PHASE_FULL) == false && ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.GIF))
                {
                    SetAnimatedSource(document, document, document.Size, PHASE_FULL);
                }
            }
            else if (TLMessage.IsVideo(document))
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);

                if (ApplicationSettings.Current.AutoDownload[_protoService.NetworkType].HasFlag(AutoDownloadType.Video))
                {
                    //SetSource(photo, photo.Full, PHASE_FULL);
                }
            }
            else
            {
                SetSource(null, document.Thumb, PHASE_THUMBNAIL);
            }
        }
Example #10
0
        protected static bool IsFullMedia(TLMessageMediaBase media, bool width = false)
        {
            if (media == null)
            {
                return(false);
            }

            if (media is TLMessageMediaGeo)
            {
                return(true);
            }
            else if (media is TLMessageMediaGeoLive)
            {
                return(true);
            }
            else if (media is TLMessageMediaVenue)
            {
                return(true);
            }
            else if (media is TLMessageMediaPhoto)
            {
                return(true);
            }
            else if (media is TLMessageMediaDocument documentMedia)
            {
                if (TLMessage.IsGif(documentMedia.Document))
                {
                    return(true);
                }
                else if (TLMessage.IsVideo(documentMedia.Document))
                {
                    return(true);
                }
            }
            else if (media is TLMessageMediaInvoice invoiceMedia && width)
            {
                if (invoiceMedia.HasPhoto && invoiceMedia.Photo != null)
                {
                    return(true);
                }
            }
Example #11
0
        private string UpdateGlyph(TLDocument document)
        {
            Visibility = Visibility.Visible;

            var fileName = document.GetFileName();

            if (File.Exists(FileUtils.GetTempFileName(fileName)))
            {
                var message = DataContext as TLMessage;
                if (message != null && message.Media is TLMessageMediaDocument documentMedia && documentMedia.HasTTLSeconds)
                {
                    return("\uE60D");
                }

                if (TLMessage.IsVideo(document) || TLMessage.IsRoundVideo(document) || TLMessage.IsMusic(document))
                {
                    return("\uE102");
                }
                else if (TLMessage.IsGif(document))
                {
                    Visibility = Visibility.Collapsed;
                    return("\uE102");
                }

                return("\uE160");
            }
            else if (document.IsTransferring)
            {
                return("\uE10A");
            }
            else if (document.DownloadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }
            else if (document.UploadingProgress > 0 && document.DownloadingProgress < 1)
            {
                return("\uE10A");
            }

            return("\uE118");
        }
Example #12
0
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            var boh = DataTemplate.GetExtensionInstance(container as FrameworkElement);

            var presenter = container as ContentControl;

            if (presenter != null && item is TLDocument doc)
            {
                presenter.Content = new TLMessage {
                    Media = new TLMessageMediaDocument {
                        Document = doc
                    }
                };
            }

            if (item is TLMessage message)
            {
                item = message.Media;
            }

            if (item is TLMessageMediaEmpty)
            {
                return(EmptyTemplate);
            }
            else if (item is TLMessageMediaContact)
            {
                return(ContactTemplate);
            }
            else if (item is TLMessageMediaPhoto)
            {
                return(PhotoTemplate);
            }
            else if (item is TLMessageMediaGame)
            {
                return(GameTemplate);
            }
            else if (item is TLMessageMediaVenue)
            {
                return(VenueTemplate);
            }
            else if (item is TLMessageMediaGeo)
            {
                return(GeoPointTemplate);
            }
            else if (item is TLMessageMediaInvoice invoiceMedia)
            {
                if (invoiceMedia.HasPhoto && invoiceMedia.Photo != null)
                {
                    return(InvoicePhotoTemplate);
                }

                return(InvoiceTemplate);
            }
            else if (item is TLMessageMediaDocument || item is TLDocument)
            {
                if (item is TLMessageMediaDocument documentMedia)
                {
                    item = documentMedia.Document;
                }

                if (item is TLDocument document)
                {
                    if (TLMessage.IsVoice(document))
                    {
                        return(AudioTemplate);
                    }
                    else if (TLMessage.IsVideo(document))
                    {
                        return(VideoTemplate);
                    }
                    else if (TLMessage.IsRoundVideo(document))
                    {
                        return(RoundVideoTemplate);
                    }
                    else if (TLMessage.IsGif(document))
                    {
                        return(GifTemplate);
                    }
                    else if (TLMessage.IsSticker(document))
                    {
                        return(StickerTemplate);
                    }
                    else if (TLMessage.IsMusic(document))
                    {
                        return(MusicTemplate);
                    }

                    // TODO: ???
                    //var externalDocument = documentMedia.Document as TLDocumentExternal;
                    //if (externalDocument != null && TLMessage.IsGif(externalDocument))
                    //{
                    //    return GifTemplate;
                    //}

                    if (document.Thumb != null && !(document.Thumb is TLPhotoSizeEmpty))
                    {
                        return(DocumentThumbTemplate);
                    }
                }

                return(DocumentTemplate);
            }
            else if (item is TLMessageMediaWebPage webpageMedia)
            {
                if (webpageMedia.WebPage is TLWebPageEmpty)
                {
                    return(EmptyTemplate);
                }
                else if (webpageMedia.WebPage is TLWebPagePending)
                {
                    return(EmptyTemplate);
                }
                else if (webpageMedia.WebPage is TLWebPage webpage)
                {
                    /*if (TLMessage.IsGif(webpage.Document))
                     * {
                     *  return WebPageGifTemplate;
                     * }
                     * else
                     * if (webpage.Document != null && webpage.Type.Equals("document", StringComparison.OrdinalIgnoreCase))
                     * {
                     *  return WebPageDocumentTemplate;
                     * }*/

                    if (webpage.Document != null)
                    {
                        return(WebPageDocumentTemplate);
                    }

                    if (webpage.Photo != null && webpage.Type != null)
                    {
                        if (IsWebPagePhotoTemplate(webpage))
                        {
                            return(WebPagePhotoTemplate);
                        }

                        return(WebPageSmallPhotoTemplate);
                    }
                }
                return(WebPageTemplate);
            }
            else if (item is TLMessageMediaUnsupported)
            {
                return(UnsupportedTemplate);
            }

            return(null);
        }
Example #13
0
        public static async void Download_Click(FrameworkElement sender, TransferCompletedEventArgs e)
        {
            var element = sender as FrameworkElement;

            var bubble = element.Ancestors <MessageBubbleBase>().FirstOrDefault() as MessageBubbleBase;

            if (bubble == null)
            {
                return;
            }

            if (element.DataContext is TLMessageService serviceMessage && serviceMessage.Action is TLMessageActionChatEditPhoto editPhotoAction)
            {
                var media = element.Parent as FrameworkElement;
                if (media == null)
                {
                    media = element;
                }

                var chat = serviceMessage.Parent as TLChatBase;
                if (chat == null)
                {
                    return;
                }

                var chatFull = InMemoryCacheService.Current.GetFullChat(chat.Id);
                if (chatFull != null && chatFull.ChatPhoto is TLPhoto && chat != null)
                {
                    var viewModel = new ChatPhotosViewModel(bubble.ContextBase.ProtoService, bubble.ContextBase.CacheService, chatFull, chat, serviceMessage);
                    await GalleryView.Current.ShowAsync(viewModel, () => media);
                }

                return;
            }

            var message = element.DataContext as TLMessage;

            if (message == null)
            {
                return;
            }

            var document = message.GetDocument();

            if (TLMessage.IsGif(document) && !ApplicationSettings.Current.IsAutoPlayEnabled)
            {
                var page = bubble.Ancestors <IGifPlayback>().FirstOrDefault() as IGifPlayback;
                if (page == null)
                {
                    return;
                }

                if (bubble.ViewModel is TLMessage inner)
                {
                    page.Play(inner);
                }
            }
            else if (TLMessage.IsVideo(document) || TLMessage.IsRoundVideo(document) || TLMessage.IsGif(document) || message.IsPhoto())
            {
                var media = element.Ancestors().FirstOrDefault(x => x is FrameworkElement && ((FrameworkElement)x).Name.Equals("Media")) as FrameworkElement;
                if (media == null)
                {
                    media = element;
                }

                //ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("FullScreenPicture", media);

                GalleryViewModelBase viewModel;
                if (message.Parent == null || TLMessage.IsRoundVideo(document) || TLMessage.IsGif(document))
                {
                    viewModel = new SingleGalleryViewModel(new GalleryMessageItem(message));
                }
                else
                {
                    viewModel = new DialogGalleryViewModel(bubble.ContextBase.ProtoService, bubble.ContextBase.CacheService, message.Parent.ToInputPeer(), message);
                }

                await GalleryView.Current.ShowAsync(viewModel, () => media);
            }
            else if (e != null)
            {
                var file = await StorageFile.GetFileFromApplicationUriAsync(FileUtils.GetTempFileUri(e.FileName));

                await Launcher.LaunchFileAsync(file);
            }
        }