Ejemplo n.º 1
0
        private void OnPropertyChanged(DependencyObject d, DependencyProperty prop)
        {
            // Accent color
            if (EmbedContent.Color != 0)
            {
                SideBorder.Background = Common.IntToColor(EmbedContent.Color);
            }
            else
            {
                SideBorder.Background = (SolidColorBrush)App.Current.Resources["LightBG"];
            }

            // Author
            if (EmbedContent.Author != null)
            {
                AuthorSP.Visibility = Visibility.Visible;
                AuthorText.Content  = EmbedContent.Author.Name;
                if (EmbedContent.Author.Url != null)
                {
                    AuthorText.NavigateUri = new Uri(EmbedContent.Author.Url);
                }
                if (EmbedContent.Author.IconUrl == null)
                {
                    AuthorImage.Visibility = Visibility.Collapsed;
                }
                else
                {
                    AuthorImage.Visibility       = Visibility.Visible;
                    AuthorImageBrush.ImageSource = new BitmapImage(new Uri(EmbedContent.Author.IconUrl));
                }
            }
            else
            {
                AuthorSP.Visibility = Visibility.Collapsed;
            }

            // Title
            if (EmbedContent.Title != null)
            {
                if (EmbedContent.Url == null)
                {
                    UrlTitleBlock.Visibility   = Visibility.Collapsed;
                    PlainTitleBlock.Visibility = Visibility.Visible;
                    PlainTitleBlock.Text       = EmbedContent.Title;
                }
                else
                {
                    PlainTitleBlock.Visibility = Visibility.Collapsed;
                    UrlTitleBlock.Visibility   = Visibility.Visible;
                    UrlTitleBlock.Content      = EmbedContent.Title;
                    UrlTitleBlock.NavigateUri  = new Uri(EmbedContent.Url);

                    // Share Icon (CU is weird here)
                    if (App.FCU)
                    {
                        ShareButton.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        CUShareButton.Visibility = Visibility.Visible;
                    }
                }
            }
            else
            {
                PlainTitleBlock.Visibility = Visibility.Collapsed;
                UrlTitleBlock.Visibility   = Visibility.Collapsed;
            }

            // Description
            if (EmbedContent.Description != null)
            {
                DescriptionBlock.Visibility = Visibility.Visible;
                DescriptionBlock.Text       = EmbedContent.Description;
            }
            else
            {
                DescriptionBlock.Visibility = Visibility.Collapsed;
            }

            // Fields
            UniversalWrapPanel previousWrapPanel = null;

            FieldsStacker.Children.Clear();
            if (EmbedContent.Fields != null)
            {
                FieldsStacker.Visibility = Visibility.Visible;
                foreach (var field in EmbedContent.Fields)
                {
                    if (field.Inline)
                    {
                        if (previousWrapPanel == null)
                        {
                            previousWrapPanel = new UniversalWrapPanel()
                            {
                                Orientation = Orientation.Horizontal
                            }
                        }
                        ;
                        previousWrapPanel.Children.Add(GenerateField(field));
                    }
                    else
                    {
                        if (previousWrapPanel != null)
                        {
                            FieldsStacker.Children.Add(previousWrapPanel);
                            previousWrapPanel = null;
                        }
                        FieldsStacker.Children.Add(GenerateField(field));
                    }
                }
                if (previousWrapPanel != null)
                {
                    FieldsStacker.Children.Add(previousWrapPanel);
                }
            }
            else
            {
                FieldsStacker.Visibility = Visibility.Collapsed;
            }

            // Content
            if (EmbedContent.Image != null)
            {
                type = Type.Image;
                ImageViewbox.Visibility = Visibility.Collapsed;
                player.Visibility       = Visibility.Collapsed;
                PreviewIcon.Glyph       = "";
                if (!NetworkSettings.GetTTL())
                {
                    ShowPreview();
                }
                else
                {
                    PreviewButton.Visibility = Visibility.Visible;
                }
                if ((EmbedContent.Author == null || (EmbedContent.Author.Name == null && EmbedContent.Author.IconUrl == null)) &&
                    EmbedContent.Description == null && EmbedContent.Fields != null &&
                    EmbedContent.Fields.Count() == 0 && EmbedContent.Footer.Text == null &&
                    EmbedContent.Footer.IconUrl == null && EmbedContent.Title == null)
                {
                    stacker.Margin   = new Thickness(0);
                    SideBorder.Width = 0;
                }
            }
            else if (EmbedContent.Video != null)
            {
                type = Type.Video;
                ImageViewbox.Visibility = Visibility.Collapsed;
                player.Visibility       = Visibility.Collapsed;
                PreviewIcon.Glyph       = "";
                if (!NetworkSettings.GetTTL())
                {
                    ShowPreview();
                }
                else
                {
                    PreviewButton.Visibility = Visibility.Visible;
                }
                player.Height = Math.Min(EmbedContent.Video.Height, this.Height);
                player.Width  = Math.Min(EmbedContent.Video.Width, this.Width);
                if ((EmbedContent.Author == null || (EmbedContent.Author.Name == null && EmbedContent.Author.IconUrl == null)) &&
                    EmbedContent.Description == null && EmbedContent.Fields != null &&
                    EmbedContent.Fields.Count() == 0 && EmbedContent.Footer.Text == null &&
                    EmbedContent.Footer.IconUrl == null && EmbedContent.Title == null)
                {
                    stacker.Margin   = new Thickness(0);
                    SideBorder.Width = 0;
                }
            }
            else
            {
                ImageViewbox.Visibility = Visibility.Collapsed;
                player.Visibility       = Visibility.Collapsed;
            }

            // Footer
            if (EmbedContent.Footer == null && EmbedContent.Timestamp == null)
            {
                FooterSP.Visibility = Visibility.Collapsed;
            }
            else
            {
                FooterSP.Visibility = Visibility.Visible;
                string footertext = "";
                if (EmbedContent.Footer?.Text != null)
                {
                    footertext = EmbedContent.Footer.Text;
                }
                if (EmbedContent.Timestamp != null)
                {
                    if (footertext != "")
                    {
                        footertext += " | ";
                    }
                    footertext     += Common.HumanizeDate(DateTime.Parse(EmbedContent.Timestamp), null);
                    FooterText.Text = footertext;
                }
                else
                {
                    FooterText.Text = footertext;
                }
                if (EmbedContent.Footer != null && EmbedContent.Footer.IconUrl != null)
                {
                    FooterImage.Visibility = Visibility.Visible;
                    FooterImage.Source     = new BitmapImage(new Uri(EmbedContent.Footer.IconUrl));
                }
                else
                {
                    FooterImage.Visibility = Visibility.Collapsed;
                }
            }

            // Provider
            if (EmbedContent.Provider != null)
            {
                ProviderHyperlink.Visibility = Visibility.Visible;
                ProviderHyperlink.Content    = EmbedContent.Provider.Name;
                if (EmbedContent.Provider.Url != null)
                {
                    ProviderHyperlink.NavigateUri = new Uri(EmbedContent.Provider.Url);
                }
            }
            else
            {
                ProviderHyperlink.Visibility = Visibility.Collapsed;
            }

            // Thumbnail
            if (EmbedContent.Thumbnail != null)
            {
                if (EmbedContent.Type == "article")
                {
                    ThumbnailColumn.Width     = new GridLength(0, GridUnitType.Pixel);
                    ThumbnailImage.Visibility = Visibility.Collapsed;
                    ImageViewbox.Visibility   = Visibility.Visible;
                    ImageViewer.Source        = new BitmapImage(new Uri(EmbedContent.Thumbnail.Url));
                }
                else
                {
                    ThumbnailColumn.Width     = new GridLength(1, GridUnitType.Star);
                    ThumbnailImage.Visibility = Visibility.Visible;
                    ThumbnailImage.Source     = new BitmapImage(new Uri(EmbedContent.Thumbnail.Url));
                }
            }
            else
            {
                ThumbnailColumn.Width     = new GridLength(0, GridUnitType.Pixel);
                ThumbnailImage.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load the attachement
        /// </summary>
        /// <param name="images">True if the preview should be shown</param>
        private void LoadAttachement(bool images)
        {
            // Clear Attachment
            AttachedImageViewer.Source      = null;
            AttachedImageViewbox.Visibility = Visibility.Collapsed;
            LoadingImage.IsActive           = false;
            LoadingImage.Visibility         = Visibility.Collapsed;
            AttachedFileViewer.Visibility   = Visibility.Collapsed;
            ClearButton.Visibility          = Visibility.Collapsed;
            if (IsFake)
            {
                ClearButton.Visibility = Visibility.Visible;
            }

            if (DisplayedAttachement == null)
            {
                return;
            }

            if (images)
            {
                // Set the FileType icon and show preview if applicable
                string extension = "." + DisplayedAttachement.Filename.Split('.').Last().ToLower();
                if (ImageFiletypes.Contains(extension))
                {
                    type = Type.Image;
                    PreviewIcon.Glyph = "";
                    if (!NetworkSettings.GetTTL())
                    {
                        ShowPreview();
                    }
                }
                else if (AudioFiletypes.Contains(extension))
                {
                    type = Type.Audio;
                    PreviewIcon.Glyph    = "";
                    player.AudioCategory = AudioCategory.Media;

                    if (!NetworkSettings.GetTTL())
                    {
                        ShowPreview();
                    }
                }
                else if (VideoFiletypes.Contains(extension))
                {
                    type = Type.Video;
                    PreviewIcon.Glyph    = "";
                    player.AudioCategory = AudioCategory.Media;
                    if (!NetworkSettings.GetTTL())
                    {
                        ShowPreview();
                    }
                }
                else if (".pdf" == extension)
                {
                    type = Type.PDF;
                    PreviewIcon.Glyph = "";
                }
            }

            // Enable navigation if applicable
            if (!IsFake)
            {
                FileName.NavigateUri = new Uri(DisplayedAttachement.Url);
            }

            // Set FileName and byte size info
            FileName.Content = DisplayedAttachement.Filename;
            FileSize.Text    = Common.HumanizeFileSize(DisplayedAttachement.Size);

            if (type == Type.Unknown || type == Type.PDF || NetworkSettings.GetTTL())
            {
                // Show FileType Icon
                if (type != Type.Unknown)
                {
                    PreviewButton.Visibility = Visibility.Visible; FileIcon.Visibility = Visibility.Collapsed;
                }
                AttachedFileViewer.Visibility = Visibility.Visible;
                player.Visibility             = Visibility.Collapsed;
            }
            else if (type == Type.Audio || type == Type.Video)
            {
                // Show MediaPlayer
                player.Visibility = Visibility.Visible;
                if (type == Type.Audio)
                {
                    player.Height = 48;
                }
            }
        }