Esempio n. 1
0
        private GalleryItem GetBlock(TLMessage message, TLWebPage webPage, TLPageBlockBase pageBlock)
        {
            if (pageBlock is TLPageBlockPhoto photoBlock)
            {
                var photo = TLWebPage.GetPhotoWithId(webPage, photoBlock.PhotoId) as TLPhoto;
                if (photo == null)
                {
                    return(null);
                }

                return(new GalleryPhotoItem(photo, message.From));
            }
            else if (pageBlock is TLPageBlockVideo videoBlock)
            {
                var document = TLWebPage.GetDocumentWithId(webPage, videoBlock.VideoId) as TLDocument;
                if (document == null)
                {
                    return(null);
                }

                return(new GalleryDocumentItem(document, message.From));
            }

            return(null);
        }
Esempio n. 2
0
        private static int CountBlock(TLWebPage webPage, TLPageBlockBase pageBlock, int count)
        {
            if (pageBlock is TLPageBlockPhoto photoBlock)
            {
                var photo = GetPhotoWithId(webPage, photoBlock.PhotoId) as TLPhoto;
                if (photo == null)
                {
                    return(count);
                }

                return(count + 1);
            }
            else if (pageBlock is TLPageBlockVideo videoBlock)
            {
                var document = GetDocumentWithId(webPage, videoBlock.VideoId) as TLDocument;
                if (document == null)
                {
                    return(count);
                }

                return(count + 1);
            }

            return(count);
        }
Esempio n. 3
0
        public override TLObject FromBytes(byte[] bytes, ref int position)
        {
            bytes.ThrowExceptionIfIncorrect(ref position, Signature);

            Cover = GetObject <TLPageBlockBase>(bytes, ref position);

            return(this);
        }
Esempio n. 4
0
        private double PaddingForBlock(TLPageBlockBase block)
        {
            if (block is TLPageBlockCover || block is TLPageBlockPreformatted ||
                block is TLPageBlockPhoto || block is TLPageBlockVideo ||
                block is TLPageBlockSlideshow || block is TLPageBlockChannel)
            {
                return(0.0);
            }

            return(_padding);
        }
Esempio n. 5
0
        private FrameworkElement ProcessEmbedPost(TLPageBase page, TLPageBlockEmbedPost block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            var element = new StackPanel {
                Style = Resources["BlockEmbedPostStyle"] as Style
            };

            var header = new Grid();

            header.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            header.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Auto)
            });
            header.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Auto)
            });
            header.ColumnDefinitions.Add(new ColumnDefinition());
            header.Margin = new Thickness(_padding, 0, 0, _padding);

            var photo   = photos.FirstOrDefault(x => x.Id == block.AuthorPhotoId);
            var ellipse = new Ellipse();

            ellipse.Width  = 36;
            ellipse.Height = 36;
            ellipse.Margin = new Thickness(0, 0, _padding, 0);
            ellipse.Fill   = new ImageBrush {
                ImageSource = (ImageSource)DefaultPhotoConverter.Convert(photo, true), Stretch = Stretch.UniformToFill, AlignmentX = AlignmentX.Center, AlignmentY = AlignmentY.Center
            };
            Grid.SetRowSpan(ellipse, 2);

            var textAuthor = new TextBlock();

            textAuthor.Text = block.Author;
            textAuthor.VerticalAlignment = VerticalAlignment.Bottom;
            Grid.SetColumn(textAuthor, 1);
            Grid.SetRow(textAuthor, 0);

            var textDate = new TextBlock();

            textDate.Text = BindConvert.Current.DateTime(block.Date).ToString("dd MMMM yyyy");
            textDate.VerticalAlignment = VerticalAlignment.Top;
            textDate.Style             = (Style)Resources["CaptionTextBlockStyle"];
            textDate.Foreground        = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
            Grid.SetColumn(textDate, 1);
            Grid.SetRow(textDate, 1);

            header.Children.Add(ellipse);
            header.Children.Add(textAuthor);
            header.Children.Add(textDate);

            element.Children.Add(header);

            TLPageBlockBase  previousBlock   = null;
            FrameworkElement previousElement = null;

            foreach (var subBlock in block.Blocks)
            {
                var subLayout = ProcessBlock(page, subBlock, photos, documents);
                var spacing   = SpacingBetweenBlocks(previousBlock, block);

                if (subLayout != null)
                {
                    subLayout.Margin = new Thickness(_padding, spacing, _padding, 0);
                    element.Children.Add(subLayout);
                }

                previousBlock   = block;
                previousElement = subLayout;
            }

            return(element);
        }
Esempio n. 6
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            ScrollingHost.Items.Clear();
            ViewModel.Gallery.Items.Clear();
            ViewModel.Gallery.TotalItems   = 0;
            ViewModel.Gallery.SelectedItem = null;
            _anchors.Clear();

            var parameter = TLSerializationService.Current.Deserialize((string)e.Parameter);

            var webpageMedia = parameter as TLMessageMediaWebPage;

            if (webpageMedia != null)
            {
                parameter = webpageMedia.WebPage as TLWebPage;
            }

            var webpage = parameter as TLWebPage;

            if (webpage != null && webpage.HasCachedPage)
            {
                var url = webpage.Url;
                if (url.StartsWith("http") == false)
                {
                    url = "http://" + url;
                }

                if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri))
                {
                    ViewModel.ShareLink  = uri;
                    ViewModel.ShareTitle = webpage.HasTitle ? webpage.Title : webpage.Url;
                }

                _webpageId = webpage.Id;

                var photos    = new List <TLPhotoBase>(webpage.CachedPage.Photos);
                var documents = new List <TLDocumentBase>(webpage.CachedPage.Videos);

                if (webpage.HasPhoto)
                {
                    photos.Insert(0, webpage.Photo);
                }

                var              processed       = 0;
                TLPageBlockBase  previousBlock   = null;
                FrameworkElement previousElement = null;
                foreach (var block in webpage.CachedPage.Blocks)
                {
                    var element = ProcessBlock(webpage.CachedPage, block, photos, documents);
                    var spacing = SpacingBetweenBlocks(previousBlock, block);
                    var padding = PaddingForBlock(block);

                    if (element != null)
                    {
                        element.Margin = new Thickness(padding, spacing, padding, 0);
                        ScrollingHost.Items.Add(element);
                    }

                    previousBlock   = block;
                    previousElement = element;
                    processed++;
                }

                var part = webpage.CachedPage as TLPagePart;
                if (part != null)
                {
                    var response = await MTProtoService.Current.GetWebPageAsync(webpage.Url, webpage.Hash);

                    if (response.IsSucceeded)
                    {
                        var newpage = response.Result as TLWebPage;
                        if (newpage != null && newpage.HasCachedPage)
                        {
                            photos    = new List <TLPhotoBase>(newpage.CachedPage.Photos);
                            documents = new List <TLDocumentBase>(newpage.CachedPage.Videos);

                            if (webpage.HasPhoto)
                            {
                                photos.Insert(0, webpage.Photo);
                            }

                            for (int i = processed; i < newpage.CachedPage.Blocks.Count; i++)
                            {
                                var block   = newpage.CachedPage.Blocks[i];
                                var element = ProcessBlock(newpage.CachedPage, block, photos, documents);
                                var spacing = SpacingBetweenBlocks(previousBlock, block);
                                var padding = PaddingForBlock(block);

                                if (element != null)
                                {
                                    element.Margin = new Thickness(padding, spacing, padding, 0);
                                    ScrollingHost.Items.Add(element);
                                }

                                previousBlock   = newpage.CachedPage.Blocks[i];
                                previousElement = element;
                            }
                        }
                    }
                }
            }

            base.OnNavigatedTo(e);
        }
Esempio n. 7
0
        private FrameworkElement ProcessText(TLPageBase page, TLPageBlockBase block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents, bool caption)
        {
            TLRichTextBase text = null;

            switch (block)
            {
            case TLPageBlockTitle title:
                text = title.Text;
                break;

            case TLPageBlockSubtitle subtitle:
                text = subtitle.Text;
                break;

            case TLPageBlockHeader header:
                text = header.Text;
                break;

            case TLPageBlockSubheader subheader:
                text = subheader.Text;
                break;

            case TLPageBlockFooter footer:
                text = footer.Text;
                break;

            case TLPageBlockParagraph paragraph:
                text = paragraph.Text;
                break;

            case TLPageBlockPreformatted preformatted:
                text = preformatted.Text;
                break;

            case TLPageBlockPhoto photo:
                text = photo.Caption;
                break;

            case TLPageBlockVideo video:
                text = video.Caption;
                break;

            case TLPageBlockSlideshow slideshow:
                text = slideshow.Caption;
                break;

            case TLPageBlockEmbed embed:
                text = embed.Caption;
                break;

            case TLPageBlockEmbedPost embedPost:
                text = embedPost.Caption;
                break;

            case TLPageBlockBlockquote blockquote:
                text = caption ? blockquote.Caption : blockquote.Text;
                break;

            case TLPageBlockPullquote pullquote:
                text = caption ? pullquote.Caption : pullquote.Text;
                break;
            }

            if (text != null && text.TypeId != TLType.TextEmpty)
            {
                var textBlock = new RichTextBlock();
                var span      = new Span();
                var paragraph = new Paragraph();
                paragraph.Inlines.Add(span);
                textBlock.Blocks.Add(paragraph);
                textBlock.TextWrapping = TextWrapping.Wrap;

                //textBlock.Margin = new Thickness(12, 0, 12, 12);
                ProcessRichText(text, span);

                switch (block.TypeId)
                {
                case TLType.PageBlockTitle:
                    textBlock.FontSize   = 28;
                    textBlock.FontFamily = new FontFamily("Times New Roman");
                    //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                    break;

                case TLType.PageBlockSubtitle:
                    textBlock.FontSize = 17;
                    //textBlock.FontFamily = new FontFamily("Times New Roman");
                    //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                    break;

                case TLType.PageBlockHeader:
                    textBlock.FontSize   = 24;
                    textBlock.FontFamily = new FontFamily("Times New Roman");
                    //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                    break;

                case TLType.PageBlockSubheader:
                    textBlock.FontSize   = 19;
                    textBlock.FontFamily = new FontFamily("Times New Roman");
                    //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                    break;

                case TLType.PageBlockParagraph:
                    textBlock.FontSize = 17;
                    break;

                case TLType.PageBlockPreformatted:
                    textBlock.FontSize = 16;
                    break;

                case TLType.PageBlockFooter:
                    textBlock.FontSize   = 15;
                    textBlock.Foreground = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                    //textBlock.TextAlignment = TextAlignment.Center;
                    break;

                case TLType.PageBlockPhoto:
                case TLType.PageBlockVideo:
                    textBlock.FontSize      = 15;
                    textBlock.Foreground    = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                    textBlock.TextAlignment = TextAlignment.Center;
                    break;

                case TLType.PageBlockSlideshow:
                case TLType.PageBlockEmbed:
                case TLType.PageBlockEmbedPost:
                    textBlock.FontSize   = 15;
                    textBlock.Foreground = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                    //textBlock.TextAlignment = TextAlignment.Center;
                    break;

                case TLType.PageBlockBlockquote:
                    textBlock.FontSize = caption ? 15 : 17;
                    if (caption)
                    {
                        textBlock.Foreground    = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                        textBlock.TextAlignment = TextAlignment.Center;
                    }
                    break;

                case TLType.PageBlockPullquote:
                    var pullquoteBlock = block as TLPageBlockPullquote;
                    textBlock.FontSize = caption ? 15 : 17;
                    if (caption)
                    {
                        textBlock.Foreground = (SolidColorBrush)Resources["SystemControlDisabledChromeDisabledLowBrush"];
                    }
                    else
                    {
                        textBlock.FontFamily = new FontFamily("Times New Roman");
                        //textBlock.TextLineBounds = TextLineBounds.TrimToBaseline;
                        textBlock.TextAlignment = TextAlignment.Center;
                    }
                    break;
                }

                return(textBlock);
            }

            return(null);
        }
Esempio n. 8
0
        private FrameworkElement ProcessBlock(TLPageBase page, TLPageBlockBase block, IList <TLPhotoBase> photos, IList <TLDocumentBase> documents)
        {
            switch (block)
            {
            case TLPageBlockCover cover:
                return(ProcessCover(page, cover, photos, documents));

            case TLPageBlockAuthorDate authorDate:
                return(ProcessAuthorDate(page, authorDate, photos, documents));

            case TLPageBlockHeader header:
            case TLPageBlockSubheader subheader:
            case TLPageBlockTitle title:
            case TLPageBlockSubtitle subtitle:
            case TLPageBlockFooter footer:
            case TLPageBlockParagraph paragraph:
                return(ProcessText(page, block, photos, documents, false));

            case TLPageBlockBlockquote blockquote:
                return(ProcessBlockquote(page, blockquote, photos, documents));

            case TLPageBlockDivider divider:
                return(ProcessDivider(page, divider, photos, documents));

            case TLPageBlockPhoto photo:
                return(ProcessPhoto(page, photo, photos, documents));

            case TLPageBlockList list:
                return(ProcessList(page, list, photos, documents));

            case TLPageBlockVideo video:
                return(ProcessVideo(page, video, photos, documents));

            case TLPageBlockEmbedPost embedPost:
                return(ProcessEmbedPost(page, embedPost, photos, documents));

            case TLPageBlockSlideshow slideshow:
                return(ProcessSlideshow(page, slideshow, photos, documents));

            case TLPageBlockCollage collage:
                return(ProcessCollage(page, collage, photos, documents));

            case TLPageBlockEmbed embed:
                return(ProcessEmbed(page, embed, photos, documents));

            case TLPageBlockPullquote pullquote:
                return(ProcessPullquote(page, pullquote, photos, documents));

            case TLPageBlockAnchor anchor:
                return(ProcessAnchor(page, anchor, photos, documents));

            case TLPageBlockPreformatted preformatted:
                return(ProcessPreformatted(page, preformatted, photos, documents));

            case TLPageBlockChannel channel:
                return(ProcessChannel(page, channel, photos, documents));

            case TLPageBlockUnsupported unsupported:
                Debug.WriteLine("Unsupported block type: " + block.GetType());
                break;
            }

            return(null);
        }
Esempio n. 9
0
        private double SpacingBetweenBlocks(TLPageBlockBase upper, TLPageBlockBase lower)
        {
            if (lower is TLPageBlockCover || lower is TLPageBlockChannel)
            {
                return(0);
            }

            return(12);

            if (lower is TLPageBlockCover || lower is TLPageBlockChannel)
            {
                return(0);
            }
            else if (lower is TLPageBlockDivider || upper is TLPageBlockDivider)
            {
                return(15); // 25;
            }
            else if (lower is TLPageBlockBlockquote || upper is TLPageBlockBlockquote || lower is TLPageBlockPullquote || upper is TLPageBlockPullquote)
            {
                return(17); // 27;
            }
            else if (lower is TLPageBlockTitle)
            {
                return(12); // 20;
            }
            else if (lower is TLPageBlockAuthorDate)
            {
                if (upper is TLPageBlockTitle)
                {
                    return(16); // 26;
                }
                else
                {
                    return(12); // 20;
                }
            }
            else if (lower is TLPageBlockParagraph)
            {
                if (upper is TLPageBlockTitle || upper is TLPageBlockAuthorDate)
                {
                    return(20); // 34;
                }
                else if (upper is TLPageBlockHeader || upper is TLPageBlockSubheader)
                {
                    return(15); // 25;
                }
                else if (upper is TLPageBlockParagraph)
                {
                    return(15); // 25;
                }
                else if (upper is TLPageBlockList)
                {
                    return(19); // 31;
                }
                else if (upper is TLPageBlockPreformatted)
                {
                    return(11); // 19;
                }
                else
                {
                    return(12); // 20;
                }
            }
            else if (lower is TLPageBlockList)
            {
                if (upper is TLPageBlockTitle || upper is TLPageBlockAuthorDate)
                {
                    return(20); // 34;
                }
                else if (upper is TLPageBlockHeader || upper is TLPageBlockSubheader)
                {
                    return(19); // 31;
                }
                else if (upper is TLPageBlockParagraph || upper is TLPageBlockList)
                {
                    return(19); // 31;
                }
                else if (upper is TLPageBlockPreformatted)
                {
                    return(11); // 19;
                }
                else
                {
                    return(12); // 20;
                }
            }
            else if (lower is TLPageBlockPreformatted)
            {
                if (upper is TLPageBlockParagraph)
                {
                    return(11); // 19;
                }
                else
                {
                    return(12); // 20;
                }
            }
            else if (lower is TLPageBlockHeader)
            {
                return(20); // 32;
            }
            else if (lower is TLPageBlockSubheader)
            {
                return(20); // 32;
            }
            else if (lower == null)
            {
                if (upper is TLPageBlockFooter)
                {
                    return(14); // 24;
                }
                else
                {
                    return(14); // 24;
                }
            }

            return(12); // 20;
        }
Esempio n. 10
0
        public override TLObject FromStream(Stream input)
        {
            Cover = GetObject <TLPageBlockBase>(input);

            return(this);
        }