Пример #1
0
        private void MediaPreview_Clicked(Uri uri)
        {
            if (PreviewFrame.Visibility == Visibility.Collapsed)
            {
                PreviewFrame.Visibility = Visibility.Visible;

                if (uri != lastUri)
                {
                    if (uri.Host.Contains("twitter.com"))
                    {
                        PreviewFrame.Navigate(typeof(TwitterView), uri, new SuppressNavigationTransitionInfo());
                    }
                    else if (uri.Host.Contains("youtube.com") || uri.Host.Contains("youtu.be"))
                    {
                        PreviewFrame.Navigate(typeof(YoutubeView), uri, new SuppressNavigationTransitionInfo());
                    }
                    else if (HyperlinkManager.isImage(uri.ToString()))
                    {
                        PreviewFrame.Navigate(typeof(ImageView), uri, new SuppressNavigationTransitionInfo());
                    }
                }

                lastUri = uri;
            }
            else
            {
                PreviewFrame.Visibility = Visibility.Collapsed;
            }
        }
Пример #2
0
        public void UpdateUi()
        {
            this.hyperlinkManager = new HyperlinkManager();

            if (MessageItem != null)
            {
                PreviewFrame.Visibility = Visibility.Collapsed;

                if (hyperlinkManager.LinkClicked != null)
                {
                    hyperlinkManager.LinkClicked -= MediaPreview_Clicked;
                }

                if (MessageItem.Type == MessageType.Info || MessageItem.Type == MessageType.JoinPart)
                {
                    MessageBox.Style = (Style)Application.Current.Resources["InfoTextRichStyle"];
                }
                else if (MessageItem.Type == MessageType.Action)
                {
                    MessageBox.FontStyle = Windows.UI.Text.FontStyle.Italic;
                }

                if (MessageItem.Type == MessageType.MOTD)
                {
                    this.FontFamily = new FontFamily("Consolas");
                }
                else
                {
                    this.FontFamily = new FontFamily(Config.GetString(Config.FontFamily, "Segoe UI"));
                    this.FontSize   = Config.GetInt(Config.FontSize, 14);
                }

                hyperlinkManager.SetText(MessageParagraph, MessageItem.Text);
                hyperlinkManager.LinkClicked += MediaPreview_Clicked;
            }

            try
            {
                if (!hyperlinkManager.InlineLink && hyperlinkManager.FirstLink != null && Config.GetBoolean(Config.ShowMetadata, true))
                {
                    Task.Run(async() =>
                    {
                        var graph = await OpenGraph.ParseUrlAsync(hyperlinkManager.FirstLink);

                        if (graph.Values.Count > 0 && graph.Title != "" && graph["description"] != "")
                        {
                            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                PreviewFrame.Visibility = Visibility.Visible;
                                PreviewFrame.Navigate(typeof(LinkView), graph, new SuppressNavigationTransitionInfo());
                            });
                        }
                    });
                }
            }
            catch { } // swallow exceptions

            this.HasLoaded = true;
            UpdateLayout();
        }
Пример #3
0
        public MessageLine()
        {
            this.InitializeComponent();
            this.hyperlinkManager = new HyperlinkManager();

            Loaded   += MessageLine_Loaded;
            Unloaded += MessageLine_Unloaded;
        }
Пример #4
0
        private void MessageLine_Unloaded(object sender, RoutedEventArgs e)
        {
            PreviewFrame.Navigate(typeof(Page));

            hyperlinkManager.SetText(MessageParagraph, "");
            hyperlinkManager.LinkClicked -= MediaPreview_Clicked;
            hyperlinkManager              = null;
            MainPage.instance.UiUpdated  -= Instance_UiUpdated;
            UpdateLayout();
        }
Пример #5
0
        public void UpdateUi()
        {
            this.hyperlinkManager = new HyperlinkManager();

            if (double.IsNaN(UsernameBox.ActualWidth) || double.IsNaN(TimestampBox.ActualWidth))
            {
                return;
            }
            if (MessageItem != null)
            {
                PreviewFrame.Visibility = Visibility.Collapsed;

                if (hyperlinkManager.LinkClicked != null)
                {
                    hyperlinkManager.LinkClicked -= MediaPreview_Clicked;
                }
                if (MessageBox.ActualHeight > UsernameBox.ActualHeight)
                {
                    Thickness margin = new Thickness(0, -1, 0, 0);
                    MessageBox.Margin = margin;
                }

                if (MessageItem.Type == MessageType.Info || MessageItem.Type == MessageType.JoinPart)
                {
                    UsernameBox.Style = (Style)Application.Current.Resources["InfoTextBlockStyle"];
                    MessageBox.Style  = (Style)Application.Current.Resources["InfoTextRichStyle"];
                }
                else if (MessageItem.Type == MessageType.Action)
                {
                    UsernameBox.FontStyle = Windows.UI.Text.FontStyle.Italic;
                    MessageBox.FontStyle  = Windows.UI.Text.FontStyle.Italic;
                }

                if (MessageItem.Mention)
                {
                    UsernameBox.Foreground = new SolidColorBrush(Colors.Red);
                }

                if (MessageItem.Type == MessageType.MOTD)
                {
                    this.FontFamily = new FontFamily("Consolas");
                }

                hyperlinkManager.SetText(MessageParagraph, MessageItem.Text);
                hyperlinkManager.LinkClicked += MediaPreview_Clicked;
            }

            try
            {
                if (!hyperlinkManager.InlineLink && hyperlinkManager.FirstLink != null && Config.GetBoolean(Config.ShowMetadata, true))
                {
                    Task.Run(async() =>
                    {
                        var graph = await OpenGraph.ParseUrlAsync(hyperlinkManager.FirstLink);

                        if (graph.Values.Count > 0 && graph.Title != "" && graph["description"] != "")
                        {
                            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                PreviewFrame.Visibility = Visibility.Visible;
                                PreviewFrame.Navigate(typeof(LinkView), graph, new SuppressNavigationTransitionInfo());
                            });
                        }
                    });
                }
            }
            catch { } // swallow exceptions

            this.HasLoaded = true;
            UpdateLayout();
        }