Ejemplo n.º 1
0
        private void ParseText(string value)
        {
            if (value == null)
            {
                value = "";
            }

            if (_stackPanel == null)
            {
                return;
            }
            // Clear previous TextBlocks
            _stackPanel.Children.Clear();

            var suppressParsing = BrowserNavigationService.GetSuppressParsing(this);
            var message         = DataContext as TLMessageBase;
            var fitIn2000Pixels = CheckFitInMaxRenderHeight(value);

            if (fitIn2000Pixels)
            {
                var textBlock = GetTextBlock();
                BrowserNavigationService.SetSuppressParsing(textBlock, suppressParsing);
                BrowserNavigationService.SetMessage(textBlock, message);
                BrowserNavigationService.SetText(textBlock, value);
                _stackPanel.Children.Add(textBlock);
            }
            else
            {
                ParseLineExtended(value);
            }
        }
Ejemplo n.º 2
0
        private FrameworkElement CreateButton(TLKeyboardButton keyboardButton, double height, double margin)
        {
            var isLightTheme = (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible;
            var background   = isLightTheme ? (Brush)Resources["ButtonLightBackground"] : (Brush)Resources["ButtonBackground"];

            var text    = keyboardButton.Text.ToString();
            var textBox = new TelegramRichTextBox {
                Text = text, MaxHeight = height, Margin = new Thickness(0.0, -4.0, 0.0, 0.0), FontSize = 22, FontFamily = new FontFamily("Segoe WP Semibold")
            };

            BrowserNavigationService.SetSuppressParsing(textBox, true);

            var button = new Button();

            button.Style      = (Style)Resources["CommandButtonStyle"];
            button.Height     = height;
            button.Margin     = new Thickness(margin);
            button.Background = background;

            button.Content     = textBox;
            button.DataContext = keyboardButton;
            button.Click      += OnButtonClick;

            return(button);
        }
Ejemplo n.º 3
0
        private void ParseText(string value)
        {
            if (value == null)
            {
                value = "";
            }

            if (_stackPanel == null)
            {
                return;
            }

            //System.Diagnostics.Debug.WriteLine("{0} ParseText", GetHashCode());
            // Clear previous TextBlocks
            _stackPanel.Children.Clear();

            var suppressParsing  = BrowserNavigationService.GetSuppressParsing(this);
            var message          = DataContext as TLMessageBase ?? BrowserNavigationService.GetMessage(this);
            var decryptedMessage = DataContext as TLDecryptedMessageBase;
            var fitIn2000Pixels  = CheckFitInMaxRenderHeight(value);

            if (fitIn2000Pixels)
            {
                var textBlock = GetTextBlock();
                BrowserNavigationService.SetSuppressParsing(textBlock, suppressParsing);
                BrowserNavigationService.SetMessage(textBlock, message);
                BrowserNavigationService.SetDecryptedMessage(textBlock, decryptedMessage);
                BrowserNavigationService.SetAddFooter(textBlock, true);
                BrowserNavigationService.SetText(textBlock, value);
                _stackPanel.Children.Add(textBlock);

                _footerRun = GetFooter(textBlock);
            }
            else
            {
                ParseLineExtended(value);
            }
        }
Ejemplo n.º 4
0
        private FrameworkElement CreateButton(TLKeyboardButtonBase keyboardButton, double height, Thickness margin, double padding, int maxTextLength)
        {
            var isLightTheme = (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible;
            var background   = isLightTheme ? (Brush)Resources["ButtonLightBackground"] : (Brush)Resources["ButtonBackground"];

            var text      = keyboardButton.Text.ToString();
            var buttonBuy = keyboardButton as TLKeyboardButtonBuy;

            if (buttonBuy != null)
            {
                var message = DataContext as TLMessage;
                if (message != null)
                {
                    var mediaInvoice = message.Media as TLMessageMediaInvoice;
                    if (mediaInvoice != null)
                    {
                        var receiptMsgId = mediaInvoice.ReceiptMsgId;
                        if (receiptMsgId != null)
                        {
                            text = AppResources.Receipt;
                        }
                    }
                }
            }

            if (text.Length > maxTextLength)
            {
                text = text.Substring(0, maxTextLength) + "...";
            }
            else
            {
                text = string.Format(" {0} ", text);
            }
            var textBox = new TelegramRichTextBox {
                MaxHeight = height, Margin = new Thickness(0.0, 0.0, 0.0, 0.0), Padding = new Thickness(0.0, 0.0, 0.0, 0.0), FontSize = 22, TextWrapping = TextWrapping.NoWrap
            };

            BrowserNavigationService.SetSuppressParsing(textBox, true);
            textBox.Text       = text;
            textBox.Margin     = new Thickness(-12.0 + padding, 0.0, -12.0, 0 + padding);
            textBox.FontSize   = Inline ? 17.776 : textBox.FontSize;
            textBox.Foreground = Inline ? new SolidColorBrush(Colors.White) : textBox.Foreground;

            var button = new Button();

            button.Style      = (Style)Resources["CommandButtonStyle"];
            button.MaxHeight  = height;
            button.Margin     = margin;
            button.Background = Inline ? (Brush)Resources["ButtonInlineBackground"] : background;

            button.Content     = textBox;
            button.DataContext = keyboardButton;
            button.Click      += OnButtonClick;

            if (keyboardButton is TLKeyboardButtonUrl)
            {
                var imageSource = isLightTheme && !Inline ? "/Images/Messages/inline.openweb.light.png" : "/Images/Messages/inline.openweb.png";

                var grid = new Grid();
                grid.Children.Add(button);
                grid.Children.Add(new Image
                {
                    Width  = 11.0,
                    Height = 11.0,
                    Margin = new Thickness(8.0),
                    HorizontalAlignment = HorizontalAlignment.Right,
                    VerticalAlignment   = VerticalAlignment.Top,
                    Source = new BitmapImage(new Uri(imageSource, UriKind.Relative))
                });

                return(grid);
            }

            if (keyboardButton is TLKeyboardButtonSwitchInline)
            {
                var imageSource = isLightTheme && !Inline ? "/Images/Messages/inline.share.light.png" : "/Images/Messages/inline.share.png";

                var grid = new Grid();
                grid.Children.Add(button);
                grid.Children.Add(new Image
                {
                    Width  = 13.0,
                    Height = 12.0,
                    Margin = new Thickness(8.0),
                    HorizontalAlignment = HorizontalAlignment.Right,
                    VerticalAlignment   = VerticalAlignment.Top,
                    Source = new BitmapImage(new Uri(imageSource, UriKind.Relative))
                });

                return(grid);
            }

            return(button);
        }
Ejemplo n.º 5
0
        private void ParseLineExtended(string allText)
        {
            if (string.IsNullOrEmpty(allText))
            {
                return;
            }


            int cutIndex = MAX_STR_LENGTH;

            if (cutIndex >= allText.Length)
            {
                cutIndex = allText.Length - 1;
            }

            var endOfSentenceIndAfterCut = allText.IndexOf(".", cutIndex);

            if (endOfSentenceIndAfterCut >= 0 && endOfSentenceIndAfterCut - cutIndex < 200)
            {
                cutIndex = endOfSentenceIndAfterCut;
            }
            else
            {
                var whiteSpaceIndAfterCut = allText.IndexOf(' ', cutIndex);

                if (whiteSpaceIndAfterCut >= 0 && whiteSpaceIndAfterCut - cutIndex < 100)
                {
                    cutIndex = whiteSpaceIndAfterCut;
                }
            }

            // add all whitespaces before cut
            while (cutIndex + 1 < allText.Length &&
                   allText[cutIndex + 1] == ' ')
            {
                cutIndex++;
            }

            var suppressParsing  = BrowserNavigationService.GetSuppressParsing(this);
            var message          = DataContext as TLMessageBase;
            var decryptedMessage = DataContext as TLDecryptedMessageBase;

            var leftSide = allText.Substring(0, cutIndex + 1);

            allText = allText.Substring(cutIndex + 1);
            var isLastTextBlock = allText.Length <= 0;
            var textBlock       = GetTextBlock();

            BrowserNavigationService.SetSuppressParsing(textBlock, suppressParsing);
            BrowserNavigationService.SetMessage(textBlock, message);
            BrowserNavigationService.SetDecryptedMessage(textBlock, decryptedMessage);
            if (isLastTextBlock)
            {
                BrowserNavigationService.SetAddFooter(textBlock, true);
            }
            BrowserNavigationService.SetText(textBlock, leftSide);
            _stackPanel.Children.Add(textBlock);

            _footerRun = GetFooter(textBlock);

            if (!isLastTextBlock)
            {
                ParseLineExtended(allText);
            }
        }