示例#1
0
        static void SetHeader(this MessageCell cell, int row, BotMessage message)
        {
            cell.SetHeader(message.LocalTimeStamp, message.Activity?.From?.Name);

            //cell.ImageView.SetCacheFormat (getCacheFormat (MessageCell.AvatarImageSize));

            //if (message.Activity.From.Id == "DigitalAgencies")
            //{
            //	cell.SetAvatar (row, UIImage.FromBundle ("avatar_microsoft"));
            //}
            //else
            //{
            var avatarUrl = string.IsNullOrEmpty(message.Activity?.From?.Id) ? string.Empty : BotClient.Shared.GetAvatarUrl(message.Activity.From.Id);

            if (string.IsNullOrEmpty(avatarUrl))
            {
                cell.SetAvatar(row, null);
            }
            else
            {
                var placeholder = getPlaceholderImage(MessageCell.AvatarImageSize);

                Glide.With(cell.Context).Load(avatarUrl).Placeholder(placeholder).Into(cell.AvatarView);

                //using (NSUrl url = new NSUrl (avatarUrl))
                //{
                //	cell?.ImageView.SetImage (url, placeholder, (img) => cell.SetAvatar (indexPath.Row, img), (err) =>
                //	{
                //		cell.SetAvatar (indexPath.Row, null);

                //		Log.Debug (err.LocalizedDescription);
                //	});
                //}
            }
            //}
        }
示例#2
0
        public static void SetMessageCell(this List <BotMessage> messages, MessageCell cell, int row)
        {
            if (messages?.Count > 0 && messages.Count > row)
            {
                var message = messages [row];

                //var cell = holder.ItemView as MessageCell;

                cell.Key = row;

                if (message.Head)
                {
                    cell.SetHeader(row, message);
                }

                if (message.HasText)
                {
                    cell.SetMessage(message.AttributedText);
                }

                if (message.HasAtachments)
                {
                    foreach (var attachment in message.Attachments)
                    {
                        // images
                        if (attachment.Content.HasImages)
                        {
                            foreach (var image in attachment.Content.Images)
                            {
                                cell.AddHeroImage(row, image.Url);
                            }
                        }

                        // title
                        if (attachment.Content.HasTitle)
                        {
                            cell.AddAttachmentTitle(attachment.Content.AttributedTitle);
                        }

                        // subtitle
                        if (attachment.Content.HasSubtitle)
                        {
                            cell.AddAttachmentSubtitle(attachment.Content.AttributedSubtitle);
                        }

                        // text
                        if (attachment.Content.HasText)
                        {
                            cell.AddAttachmentText(attachment.Content.AttributedText);
                        }

                        // buttons
                        if (attachment.Content.HasButtons)
                        {
                            cell.SetButtons(attachment.Content.Buttons.Select(b => (b.Title, b.Value.ToString())).ToArray());
                        }
                    }
                }

                // Cells must inherit the table view's transform
                // This is very important, since the main table view may be inverted
                //cell.Transform = tableView.Transform;

                //return cell;
            }

            //return null;
        }