Пример #1
0
        //private async void HyperlinkButton_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        //{
        //    var hb = (HyperlinkButton)sender;
        //    hb.nav
        //    await Windows.System.Launcher.LaunchUriAsync(new Uri("http://gank.io"));
        //}

        public async void ShowMessage(string msg, double seconds)
        {
            MessageBlock.Text        = msg;
            MessageBorder.Visibility = Visibility.Visible;
            await MessageBorder.Fade(1).StartAsync();

            await MessageBorder.Fade(delay : seconds * 1e3).StartAsync();

            MessageBorder.Visibility = Visibility.Collapsed;
        }
Пример #2
0
        public void ShowMessage(string message)
        {
            MessageTimer.Stop();
            HideMessageTimer.Stop();
            MessageBorder.Visibility = Visibility.Visible;
            message.Trim();
            MessageLB.Content = message;
            new Thread(() =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    DoubleAnimation errorAnimation = new DoubleAnimation();
                    errorAnimation.From            = 0;
                    errorAnimation.To = 1;
                    errorAnimation.AccelerationRatio = 0.5;
                    errorAnimation.Duration          = TimeSpan.FromMilliseconds(300);
                    MessageBorder.BeginAnimation(OpacityProperty, errorAnimation);
                });
            }).Start();

            MessageBorder.Background  = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageInformationBackground));
            MessageBorder.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageInformationForeground));
            MessageIconLB.Content     = MessageInformationIcon;
            MessageTimer.Interval     = TimeSpan.FromMilliseconds((500 * App.NumberOfWordsIn(message)) + 2000);
            MessageTimer.Tick        += ((sender, e) =>
            {
                new Thread(() =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        DoubleAnimation errorAnimation = new DoubleAnimation();
                        errorAnimation.To = 0;
                        errorAnimation.AccelerationRatio = 0.5;
                        errorAnimation.Duration = TimeSpan.FromMilliseconds(300);
                        MessageBorder.BeginAnimation(OpacityProperty, errorAnimation);
                        HideMessageTimer.Interval = TimeSpan.FromMilliseconds(300);
                        HideMessageTimer.Tick += ((sender1, e1) =>
                        {
                            MessageBorder.Visibility = Visibility.Collapsed;
                        });
                        HideMessageTimer.Start();
                    });
                }).Start();
            });
            MessageTimer.Start();
        }
Пример #3
0
        public void ShowMessage(MessageType type)
        {
            MessageTimer.Stop();
            HideMessageTimer.Stop();

            MessageBorder.Visibility = Visibility.Visible;
            t1 = new Task(() =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    DoubleAnimation errorAnimation = new DoubleAnimation();
                    errorAnimation.From            = 0;
                    errorAnimation.To = 1;
                    errorAnimation.AccelerationRatio = 0.5;
                    errorAnimation.Duration          = TimeSpan.FromMilliseconds(300);
                    MessageBorder.BeginAnimation(OpacityProperty, errorAnimation);
                });
            });
            t1.Start();
            if (type == MessageType.Error)
            {
                MessageBorder.Background  = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageErrorBackground));
                MessageBorder.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageErrorForeground));
                MessageIconLB.Content     = MessageErrorIcon;
                MessageLB.Content         = "Something went wrong";
            }
            else if (type == MessageType.Warning)
            {
                MessageBorder.Background  = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageWarningBackground));
                MessageBorder.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageWarningForeground));
                MessageIconLB.Content     = MessageWarningIcon;
                MessageLB.Content         = "Something may went wrong";
            }
            else if (type == MessageType.Information)
            {
                MessageBorder.Background  = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageInformationBackground));
                MessageBorder.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageInformationForeground));
                MessageIconLB.Content     = MessageInformationIcon;
                MessageLB.Content         = "Contact support if you need some help";
            }
            else if (type == MessageType.Success)
            {
                MessageBorder.Background  = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageSuccessBackground));
                MessageBorder.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(MessageSuccessForeground));
                MessageIconLB.Content     = MessageSuccessIcon;
                MessageLB.Content         = "Process completed successfully";
            }
            MessageTimer.Interval = TimeSpan.FromMilliseconds((500 * App.NumberOfWordsIn(MessageLB.Content.ToString())) + 2000);
            MessageTimer.Tick    += (async(sender, e) =>
            {
                t2 = new Task(() =>
                {
                    this.Dispatcher.Invoke(() =>
                    {
                        DoubleAnimation errorAnimation = new DoubleAnimation();
                        errorAnimation.To = 0;
                        errorAnimation.AccelerationRatio = 0.5;
                        errorAnimation.Duration = TimeSpan.FromMilliseconds(300);
                        MessageBorder.BeginAnimation(OpacityProperty, errorAnimation);
                        HideMessageTimer.Interval = TimeSpan.FromMilliseconds(300);
                        HideMessageTimer.Tick += ((sender1, e1) =>
                        {
                            MessageBorder.Visibility = Visibility.Collapsed;
                        });
                        HideMessageTimer.Start();
                    });
                });
                t2.Start();
                await Task.WhenAll(t1, t2);
            });
            MessageTimer.Start();
        }
Пример #4
0
        public MessageView(Telegram.Bot.Types.Message message, bool isYour)
        {
            Message = message;
            InitializeComponent();

            #region Styling&CM

            var cm       = new ContextMenu();
            var copyitem = new MenuItem {
                Header = "Копировать"
            };
            copyitem.Click += CopyMessage;
            cm.Items.Add(copyitem);
            if (isYour)
            {
                Pane.FlowDirection = FlowDirection.LeftToRight;
                MessageLabel.SetResourceReference(ForegroundProperty, "TextOnLightColor");
                MessageBorder.SetResourceReference(BackgroundProperty, "AlternativeBackgroundColor");
                MessageBorder.BorderThickness = new Thickness(1);
                var delitem = new MenuItem {
                    Header = "Удалить"
                };
                delitem.Click += DeleteMessage;
                cm.Items.Add(delitem);
            }
            else
            {
                Pane.FlowDirection = FlowDirection.RightToLeft;
                MessageLabel.SetResourceReference(ForegroundProperty, "TextOnDarkColor");
                MessageBorder.SetResourceReference(BackgroundProperty, "PrimaryLightColor");
            }
            MessageLabel.ContextMenu = cm;

            #endregion

            var photoid = message.Photo?.FirstOrDefault(x => x.Width < 300);
            if (photoid?.FileId != null)
            {
                try
                {
                    var photo = App.Bot.GetFileAsync(photoid.FileId).Result;

                    var img = new BitmapImage();
                    img.BeginInit();
                    img.StreamSource = photo.FileStream;
                    img.EndInit();
                    MessageLabel.Content = new Image {
                        Source = img, Stretch = Stretch.Uniform, MaxWidth = 400
                    };
                }
                catch
                {
                    MessageLabel.Content = "{Ссылка на файл уже не действительна}";
                }
            }
            if (message.Sticker != null)
            {
                MessageLabel.Content = "{Стикер}";
            }
            if (message.Audio != null)
            {
                MessageLabel.Content = "{Audio}";
            }
            if (message.Video != null)
            {
                MessageLabel.Content = "{Video}";
            }
            if (message.Contact != null)
            {
                MessageLabel.Content =
                    $"Контакт:\n+{message.Contact.PhoneNumber}\n{message.Contact.LastName} {message.Contact.FirstName}";
            }
            if (message.Document != null)
            {
                var p = new Path
                {
                    Stretch = Stretch.Uniform
                };
                p.SetResourceReference(Path.DataProperty, "Download");
                p.SetResourceReference(Shape.FillProperty, "SecondaryColor");
                var b = new Button();
                b.SetResourceReference(StyleProperty, "TranspButton");
                b.Content = new Border {
                    Width = 40, Child = p
                };
                b.Click += async(s, e) =>
                {
                    var d = new SaveFileDialog {
                        FileName = Message.Document.FileName
                    };
                    if (d.ShowDialog() != true)
                    {
                        return;
                    }

                    var file = await App.Bot.GetFileAsync(message.Document.FileId);

                    file.FileStream.CopyTo(d.OpenFile());
                };
                var dp = new DockPanel();
                DockPanel.SetDock(b, Dock.Right);
                dp.Children.Add(b);
                var l1 = new Label {
                    VerticalContentAlignment = VerticalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, Content = Message.Document?.FileName
                };
                l1.SetResourceReference(ForegroundProperty, "TextOnDarkColor");
                DockPanel.SetDock(l1, Dock.Top);
                dp.Children.Add(l1);
                var l2 = new Label {
                    VerticalContentAlignment = VerticalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, Content = $"{Message.Document?.MimeType}\n{Hrs(Message.Document?.FileSize??0)}"
                };
                l2.SetResourceReference(FontSizeProperty, "FontSizeSmall");
                l2.SetResourceReference(ForegroundProperty, "TextOnDarkColor");
                DockPanel.SetDock(l2, Dock.Bottom);
                dp.Children.Add(l2);
                MessageLabel.Content = dp;
            }
            if (message.Venue != null)
            {
                var p = new Path
                {
                    Stretch = Stretch.Uniform
                };
                p.SetResourceReference(Path.DataProperty, "Map");
                p.SetResourceReference(Shape.FillProperty, "SecondaryColor");
                var b = new Button();
                b.SetResourceReference(StyleProperty, "TranspButton");
                b.Content = new Border {
                    Width = 40, Child = p
                };
                b.Click += (s, e) =>
                {
                    App.Map.AddPoint(message.Venue);
                    App.Map.Show();
                };
                var dp = new DockPanel();
                DockPanel.SetDock(b, Dock.Right);
                dp.Children.Add(b);
                var l1 = new Label {
                    VerticalContentAlignment = VerticalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, Content = Message.Venue?.Title
                };
                l1.SetResourceReference(ForegroundProperty, "TextOnDarkColor");
                DockPanel.SetDock(l1, Dock.Top);
                dp.Children.Add(l1);
                var l2 = new Label {
                    VerticalContentAlignment = VerticalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, Content = Message.Venue?.Address
                };
                l2.SetResourceReference(FontSizeProperty, "FontSizeSmall");
                l2.SetResourceReference(ForegroundProperty, "TextOnDarkColor");
                DockPanel.SetDock(l2, Dock.Bottom);
                dp.Children.Add(l2);
                MessageLabel.Content = dp;
            }
            if (message.Location != null)
            {
                var p = new Path
                {
                    Stretch = Stretch.Uniform
                };
                p.SetResourceReference(Path.DataProperty, "Map");
                p.SetResourceReference(Shape.FillProperty, "SecondaryColor");
                var b = new Button();
                b.SetResourceReference(StyleProperty, "TranspButton");
                b.Content = new Border {
                    Width = 40, Child = p
                };
                b.Click += (s, e) =>
                {
                    App.Map.AddPoint(message.Location);
                    App.Map.Show();
                };
                var dp = new DockPanel();
                DockPanel.SetDock(b, Dock.Right);
                dp.Children.Add(b);
                var l1 = new Label {
                    VerticalContentAlignment = VerticalAlignment.Center, HorizontalContentAlignment = HorizontalAlignment.Center, Content = $"lat: {Message.Location?.Latitude} lng: {Message.Location?.Longitude}"
                };
                l1.SetResourceReference(ForegroundProperty, "TextOnDarkColor");
                DockPanel.SetDock(l1, Dock.Top);
                dp.Children.Add(l1);
                MessageLabel.Content = dp;
            }
            if (message.Text != null)
            {
                MessageLabel.Content = message.Text;
            }
        }