예제 #1
0
        //private static Thickness textBubbleMargin = new Thickness(74, 12, 0, 10);
        //private static Thickness nudgeBubbleMargin = new Thickness(348, 12, 0, 10);
        //private static Thickness attachmentBubbleMargin = new Thickness(200, 12, 0, 10);

        private void initializeBasedOnState(ConvMessage cm, string messageString)
        {
            bool   hasAttachment = cm.HasAttachment;
            string contentType   = cm.FileAttachment == null ? "" : cm.FileAttachment.ContentType;
            //string messageString = cm.Message;
            bool isSMS   = cm.IsSms;
            bool isNudge = cm.MetaDataString != null && cm.MetaDataString.Contains("poke");

            bool isContact = hasAttachment && contentType.Contains(HikeConstants.CT_CONTACT);

            if (isContact)
            {
                messageString = cm.FileAttachment.FileName;
            }
            BubbleBg = new Rectangle();
            Grid.SetRowSpan(BubbleBg, 2);
            Grid.SetColumn(BubbleBg, 1);
            wrapperGrid.Children.Add(BubbleBg);

            if (hasAttachment || isNudge)
            {
                attachment = new Grid();
                RowDefinition r1 = new RowDefinition();
                r1.Height = GridLength.Auto;
                RowDefinition r2 = new RowDefinition();
                r2.Height = GridLength.Auto;
                attachment.RowDefinitions.Add(r1);
                attachment.RowDefinitions.Add(r2);
                Grid.SetRow(attachment, 0);
                Grid.SetColumn(attachment, 1);
                wrapperGrid.Children.Add(attachment);

                MessageImage                     = new Image();
                MessageImage.MaxWidth            = 180;
                MessageImage.MaxHeight           = 180;
                MessageImage.HorizontalAlignment = HorizontalAlignment.Right;
                MessageImage.Margin              = imgMargin;
                if (contentType.Contains(HikeConstants.AUDIO))
                {
                    this.MessageImage.Source = UI_Utils.Instance.AudioAttachmentSend;
                }
                else if (isNudge)
                {
                    this.MessageImage.Source = UI_Utils.Instance.NudgeSent;
                    this.MessageImage.Height = 35;
                    this.MessageImage.Width  = 48;
                    this.MessageImage.Margin = nudgeMargin;
                    //this.Margin = nudgeBubbleMargin;
                }
                else if (isContact)
                {
                    this.MessageImage.Source = UI_Utils.Instance.ContactIcon;
                    this.MessageImage.Height = 20;
                    this.MessageImage.Width  = 30;
                    this.MessageImage.HorizontalAlignment = HorizontalAlignment.Left;
                    TextBlock textBlck = new TextBlock();
                    textBlck.Text         = messageString;
                    textBlck.FontSize     = 22;
                    textBlck.MinWidth     = 150;
                    textBlck.MaxWidth     = 330;
                    textBlck.Foreground   = UI_Utils.Instance.White;
                    textBlck.Margin       = contactMessageTextMargin;
                    textBlck.TextWrapping = TextWrapping.Wrap;
                    Grid.SetRow(textBlck, 0);
                    Grid.SetColumn(textBlck, 1);
                    attachment.Children.Add(textBlck);
                    textBlck.FontFamily = UI_Utils.Instance.SemiLightFont;
                }
                Grid.SetRow(MessageImage, 0);

                attachment.Children.Add(MessageImage);

                if (contentType.Contains(HikeConstants.VIDEO) || contentType.Contains(HikeConstants.AUDIO))
                {
                    PlayIcon                     = new Image();
                    PlayIcon.MaxWidth            = 43;
                    PlayIcon.MaxHeight           = 42;
                    PlayIcon.Source              = UI_Utils.Instance.PlayIcon;
                    PlayIcon.HorizontalAlignment = HorizontalAlignment.Center;
                    PlayIcon.VerticalAlignment   = VerticalAlignment.Center;
                    PlayIcon.Margin              = imgMargin;
                    Grid.SetRow(PlayIcon, 0);
                    attachment.Children.Add(PlayIcon);
                }
                if (!isNudge)
                {
                    uploadProgress        = new ProgressBar();
                    uploadProgress.Height = 10;
                    if (isSMS)
                    {
                        uploadProgress.Background = UI_Utils.Instance.SmsBackground;
                    }
                    else
                    {
                        uploadProgress.Background = UI_Utils.Instance.HikeMsgBackground;
                    }
                    uploadProgress.Opacity    = 0;
                    uploadProgress.Foreground = progressColor;
                    uploadProgress.Value      = 0;
                    uploadProgress.Minimum    = 0;
                    uploadProgress.MaxHeight  = 100;
                    Grid.SetRow(uploadProgress, 1);
                    attachment.Children.Add(uploadProgress);
                    //this.Margin = attachmentBubbleMargin;
                }
            }
            else
            {
                MessageText            = new LinkifiedTextBox(UI_Utils.Instance.White, 22, messageString);
                MessageText.Width      = 330;
                MessageText.Foreground = progressColor;
                MessageText.Margin     = messageTextMargin;
                MessageText.FontFamily = UI_Utils.Instance.SemiLightFont;
                Grid.SetRow(MessageText, 0);
                Grid.SetColumn(MessageText, 1);
                wrapperGrid.Children.Add(MessageText);
                //this.Margin = textBubbleMargin;
            }

            SDRImage        = new Image();
            SDRImage.Margin = sdrImageMargin;
            SDRImage.Height = 20;
            Grid.SetRowSpan(SDRImage, 2);
            Grid.SetColumn(SDRImage, 0);
            wrapperGrid.Children.Add(SDRImage);
            if (!isNudge)
            {
                TimeStampBlock = new TextBlock();
                TimeStampBlock.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                TimeStampBlock.FontSize            = 18;
                if (isSMS)
                {
                    TimeStampBlock.Foreground = UI_Utils.Instance.SMSSentChatBubbleTimestamp;
                }
                else
                {
                    TimeStampBlock.Foreground = UI_Utils.Instance.HikeSentChatBubbleTimestamp;
                }
                TimeStampBlock.Text   = TimeStamp;
                TimeStampBlock.Margin = timeStampBlockMargin;
                Grid.SetRow(TimeStampBlock, 1);
                Grid.SetColumn(TimeStampBlock, 1);
                wrapperGrid.Children.Add(TimeStampBlock);
            }

            if (isNudge)
            {
                bubbleColor = UI_Utils.Instance.PhoneThemeColor;
            }
            else if (isSMS)
            {
                bubbleColor = UI_Utils.Instance.SmsBackground;
            }
            else
            {
                bubbleColor = UI_Utils.Instance.HikeMsgBackground;
            }
        }
        private void initializeBasedOnState(ConvMessage cm, bool isGroupChat, string userName, string messageString)
        {
            bool   hasAttachment = cm.HasAttachment;
            string contentType   = cm.FileAttachment == null ? "" : cm.FileAttachment.ContentType;
            bool   isContact     = hasAttachment && contentType.Contains(HikeConstants.CT_CONTACT);

            if (isContact)
            {
                messageString = string.IsNullOrEmpty(cm.FileAttachment.FileName) ? "contact" : cm.FileAttachment.FileName;
            }
            bool showDownload = cm.FileAttachment != null && (cm.FileAttachment.FileState == Attachment.AttachmentState.CANCELED ||
                                                              cm.FileAttachment.FileState == Attachment.AttachmentState.FAILED_OR_NOT_STARTED);
            bool isNudge = cm.MetaDataString != null && cm.MetaDataString.Contains("poke");

            Rectangle BubbleBg = new Rectangle();

            if (!isNudge)
            {
                BubbleBg.Fill      = UI_Utils.Instance.ReceivedChatBubbleColor;
                bubblePointer.Fill = UI_Utils.Instance.ReceivedChatBubbleColor;
            }
            else
            {
                BubbleBg.Fill      = UI_Utils.Instance.PhoneThemeColor;
                bubblePointer.Fill = UI_Utils.Instance.PhoneThemeColor;
            }
            Grid.SetRowSpan(BubbleBg, 2 + (isGroupChat ? 1 : 0));
            wrapperGrid.Children.Add(BubbleBg);

            int rowNumber = 0;

            if (isGroupChat)
            {
                TextBlock textBlck = new TextBlock();
                textBlck.Text       = userName + " -";
                textBlck.FontSize   = 22;
                textBlck.FontFamily = UI_Utils.Instance.SemiBoldFont;
                textBlck.Foreground = UI_Utils.Instance.GroupChatHeaderColor;
                textBlck.Margin     = userNameMargin;
                Grid.SetRow(textBlck, 0);
                wrapperGrid.Children.Add(textBlck);
                rowNumber = 1;
            }

            if (hasAttachment || isNudge)
            {
                attachment = new Grid();
                RowDefinition r1 = new RowDefinition();
                r1.Height = GridLength.Auto;
                RowDefinition r2 = new RowDefinition();
                r2.Height = GridLength.Auto;
                attachment.RowDefinitions.Add(r1);
                attachment.RowDefinitions.Add(r2);
                Grid.SetRow(attachment, rowNumber);
                Grid.SetColumn(attachment, 1);
                wrapperGrid.Children.Add(attachment);

                MessageImage                     = new Image();
                MessageImage.MaxWidth            = 180;
                MessageImage.MaxHeight           = 180;
                MessageImage.HorizontalAlignment = HorizontalAlignment.Left;
                MessageImage.Margin              = imgMargin;
                if (contentType.Contains(HikeConstants.AUDIO))
                {
                    this.MessageImage.Source = UI_Utils.Instance.AudioAttachmentReceive;
                }
                else if (isNudge)
                {
                    this.MessageImage.Source = UI_Utils.Instance.NudgeReceived;
                    this.MessageImage.Height = 35;
                    this.MessageImage.Width  = 46;
                    this.MessageImage.Margin = nudgeMargin;
                }
                else if (isContact)
                {
                    this.MessageImage.Source = UI_Utils.Instance.ContactIcon;
                    this.MessageImage.Height = 20;
                    this.MessageImage.Width  = 30;
                    TextBlock textBlck = new TextBlock();
                    textBlck.Text         = messageString;
                    textBlck.FontSize     = 22;
                    textBlck.Foreground   = UI_Utils.Instance.ReceiveMessageForeground;
                    textBlck.Margin       = contactMessageTextMargin;
                    textBlck.TextWrapping = TextWrapping.Wrap;
                    textBlck.FontFamily   = UI_Utils.Instance.SemiLightFont;
                    textBlck.MinWidth     = 150;
                    textBlck.MaxWidth     = 330;
                    Grid.SetRow(textBlck, 0);
                    Grid.SetColumn(textBlck, 1);
                    attachment.Children.Add(textBlck);
                }
                Grid.SetRow(MessageImage, 0);
                attachment.Children.Add(MessageImage);

                if ((contentType.Contains(HikeConstants.VIDEO) || contentType.Contains(HikeConstants.AUDIO) || showDownload) && !contentType.Contains(HikeConstants.LOCATION) &&
                    !contentType.Contains(HikeConstants.CT_CONTACT))
                {
                    PlayIcon           = new Image();
                    PlayIcon.MaxWidth  = 43;
                    PlayIcon.MaxHeight = 42;
                    if (contentType.Contains(HikeConstants.IMAGE))
                    {
                        PlayIcon.Source = UI_Utils.Instance.DownloadIcon;
                    }
                    else
                    {
                        PlayIcon.Source = UI_Utils.Instance.PlayIcon;
                    }
                    PlayIcon.HorizontalAlignment = HorizontalAlignment.Center;
                    PlayIcon.VerticalAlignment   = VerticalAlignment.Center;

                    PlayIcon.Margin = imgMargin;
                    Grid.SetRow(PlayIcon, 0);
                    attachment.Children.Add(PlayIcon);
                }
                if (!isNudge)
                {
                    downloadProgress            = new ProgressBar();
                    downloadProgress.Height     = 10;
                    downloadProgress.Background = new SolidColorBrush(Color.FromArgb(255, 0x99, 0x99, 0x99));
                    downloadProgress.Foreground = UI_Utils.Instance.ReceivedChatBubbleProgress;
                    downloadProgress.Minimum    = 0;
                    downloadProgress.MaxHeight  = 100;
                    downloadProgress.Opacity    = 0;
                    if (showDownload)
                    {
                        temporaryProgressBar        = new PerformanceProgressBar();
                        temporaryProgressBar.Height = 10;
                        //                    temporaryProgressBar.Background = UI_Utils.Instance.TextBoxBackground;
                        temporaryProgressBar.Foreground = UI_Utils.Instance.ReceivedChatBubbleProgress;
                        temporaryProgressBar.IsEnabled  = false;
                        temporaryProgressBar.Opacity    = 1;
                        downloadProgress.Visibility     = Visibility.Collapsed;
                        downloadProgress.Opacity        = 1;
                        Grid.SetRow(temporaryProgressBar, 1);
                        attachment.Children.Add(temporaryProgressBar);
                    }
                    Grid.SetRow(downloadProgress, 1);
                    attachment.Children.Add(downloadProgress);
                }
            }
            else
            {
                MessageText       = new LinkifiedTextBox(UI_Utils.Instance.ReceiveMessageForeground, 22, messageString);
                MessageText.Width = 330;
                if (!isGroupChat)
                {
                    MessageText.Margin = messageTextMargin;
                }
                MessageText.FontFamily = UI_Utils.Instance.SemiLightFont;
                Grid.SetRow(MessageText, rowNumber);
                wrapperGrid.Children.Add(MessageText);
            }
            if (!isNudge)
            {
                TimeStampBlock = new TextBlock();
                TimeStampBlock.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                TimeStampBlock.FontSize            = 18;
                TimeStampBlock.Foreground          = UI_Utils.Instance.ReceivedChatBubbleTimestamp;
                TimeStampBlock.Text   = TimeStamp;
                TimeStampBlock.Margin = timeStampBlockMargin;
                Grid.SetRow(TimeStampBlock, rowNumber + 1);
                wrapperGrid.Children.Add(TimeStampBlock);
            }
        }