예제 #1
0
            public override View GetView(int position, View convertView, ViewGroup parent)
            {
                ViewHolder viewHolder = null;
                Object     item       = this [position];

                if (convertView == null || (convertView.Tag as ViewHolder).GetViewType() != GetItemViewType(position))
                {
                    viewHolder = new ViewHolder();
                    viewHolder.SetViewType(GetItemViewType(position));

                    switch (GetItemViewType(position))
                    {
                    case TYPE_UNSUPPORTED:
                    {
                        convertView     = new View(mInflater.Context);
                        convertView.Tag = viewHolder;
                        break;
                    }

                    case TYPE_MESSAGE:
                    {
                        TextView  tv;
                        ImageView iv;
                        View      v;

                        convertView = mInflater.Inflate(Resource.Layout.SendBirdViewMessagingMessage, parent, false);

                        v = convertView.FindViewById(Resource.Id.left_container);
                        viewHolder.SetView("left_container", v);
                        iv = convertView.FindViewById(Resource.Id.img_left_thumbnail) as ImageView;
                        viewHolder.SetView("left_thumbnail", iv);
                        tv = convertView.FindViewById(Resource.Id.txt_left) as TextView;
                        viewHolder.SetView("left_message", tv);
                        tv = convertView.FindViewById(Resource.Id.txt_left_name) as TextView;
                        viewHolder.SetView("left_name", tv);
                        tv = convertView.FindViewById(Resource.Id.txt_left_time) as TextView;
                        viewHolder.SetView("left_time", tv);

                        v = convertView.FindViewById(Resource.Id.right_container);
                        viewHolder.SetView("right_container", v);
                        iv = convertView.FindViewById(Resource.Id.img_right_thumbnail) as ImageView;
                        viewHolder.SetView("right_thumbnail", iv);
                        tv = convertView.FindViewById(Resource.Id.txt_right) as TextView;
                        viewHolder.SetView("right_message", tv);
                        tv = convertView.FindViewById(Resource.Id.txt_right_name) as TextView;
                        viewHolder.SetView("right_name", tv);
                        tv = convertView.FindViewById(Resource.Id.txt_right_time) as TextView;
                        viewHolder.SetView("right_time", tv);
                        tv = convertView.FindViewById(Resource.Id.txt_right_status) as TextView;
                        viewHolder.SetView("right_status", tv);

                        convertView.Tag = viewHolder;
                        break;
                    }

                    case TYPE_SYSTEM_MESSAGE:
                    {
                        convertView = mInflater.Inflate(Resource.Layout.SendBirdViewSystemMessage, parent, false);
                        viewHolder.SetView("message", convertView.FindViewById(Resource.Id.txt_message) as TextView);
                        convertView.Tag = viewHolder;
                        break;
                    }

                    case TYPE_BROADCAST_MESSAGE:
                    {
                        convertView = mInflater.Inflate(Resource.Layout.SendBirdViewSystemMessage, parent, false);
                        viewHolder.SetView("message", convertView.FindViewById(Resource.Id.txt_message) as TextView);
                        convertView.Tag = viewHolder;
                        break;
                    }

                    case TYPE_TYPING_INDICATOR:
                    {
                        convertView = mInflater.Inflate(Resource.Layout.SendBirdViewTypingIndicator, parent, false);
                        viewHolder.SetView("message", convertView.FindViewById(Resource.Id.txt_message));
                        convertView.Tag = viewHolder;
                        break;
                    }
                    }
                }
                viewHolder = convertView.Tag as ViewHolder;
                switch (GetItemViewType(position))
                {
                case TYPE_UNSUPPORTED:
                    break;

                case TYPE_MESSAGE:
                {
                    SendBird.Model.Message message = item as SendBird.Model.Message;
                    if (message.GetSenderId().Equals(SendBirdSDK.GetUserId()))
                    {
                        viewHolder.GetView("left_container").Visibility  = ViewStates.Gone;
                        viewHolder.GetView("right_container").Visibility = ViewStates.Visible;

                        // DisplayUrlImage()
                        viewHolder.GetView <TextView> ("right_name").Text    = message.GetSenderName();
                        viewHolder.GetView <TextView> ("right_message").Text = message.message;
                        viewHolder.GetView <TextView> ("right_time").Text    = GetDisplayDateTime(mContext, message.messageTimestamp);

                        int readCount = 0;
                        foreach (string key in mReadStatus.Keys)
                        {
                            if (key.Equals(message.GetSenderId()))
                            {
                                readCount += 1;
                                continue;
                            }

                            if (mReadStatus [key] >= message.messageTimestamp)
                            {
                                readCount += 1;
                            }
                        }

                        if (readCount < mReadStatus.Count)
                        {
                            if (mReadStatus.Count - readCount > 1)
                            {
                                viewHolder.GetView <TextView> ("right_status").Text = "Unread " + (mReadStatus.Count - readCount);
                            }
                            else
                            {
                                viewHolder.GetView <TextView> ("right_status").Text = "Unread";
                            }
                        }
                        else
                        {
                            viewHolder.GetView <TextView> ("right_status").Text = string.Empty;
                        }
                    }
                    else
                    {
                        viewHolder.GetView("left_container").Visibility  = ViewStates.Visible;
                        viewHolder.GetView("right_container").Visibility = ViewStates.Gone;

                        // DisplayUrlImage()
                        viewHolder.GetView <TextView> ("left_name").Text    = message.GetSenderName();
                        viewHolder.GetView <TextView> ("left_message").Text = message.message;
                        viewHolder.GetView <TextView> ("left_time").Text    = GetDisplayDateTime(mContext, message.messageTimestamp);
                    }
                    break;
                }

                case TYPE_SYSTEM_MESSAGE:
                {
                    SendBird.Model.SystemMessage systemMessage = item as SendBird.Model.SystemMessage;
                    viewHolder.GetView <TextView> ("message").TextFormatted = Html.FromHtml(systemMessage.message);
                    break;
                }

                case TYPE_BROADCAST_MESSAGE:
                {
                    SendBird.Model.BroadcastMessage broadcastMessage = item as SendBird.Model.BroadcastMessage;
                    viewHolder.GetView <TextView> ("message").TextFormatted = Html.FromHtml(broadcastMessage.message);
                    break;
                }

                case TYPE_TYPING_INDICATOR:
                {
                    System.Collections.ICollection itemList = (System.Collections.ICollection)item;
                    int    itemCount = itemList.Count;
                    string typeMsg   = (item as List <string>)[0] + ((itemCount > 1) ? " +" + (itemCount - 1) : "")
                                       + ((itemCount > 1) ? " are " : " is ")
                                       + "typing...";
                    viewHolder.GetView <TextView> ("message").Text = typeMsg;
                    break;
                }
                }

                return(convertView);
            }
예제 #2
0
            public override View GetView(int position, View convertView, ViewGroup parent)
            {
                ViewHolder viewHolder = null;
                Object     item       = this [position];

                if (convertView == null || (convertView.Tag as ViewHolder).GetViewType() != GetItemViewType(position))
                {
                    viewHolder = new ViewHolder();
                    viewHolder.SetViewType(GetItemViewType(position));

                    switch (GetItemViewType(position))
                    {
                    case TYPE_UNSUPPORTED:
                    {
                        convertView     = new View(mInflater.Context);
                        convertView.Tag = viewHolder;
                        break;
                    }

                    case TYPE_MESSAGE:
                    {
                        convertView = mInflater.Inflate(Resource.Layout.SendBirdViewMessage, parent, false);
                        viewHolder.SetView("message", convertView.FindViewById(Resource.Id.txt_message) as TextView);
                        viewHolder.SetView("img_op_icon", (ImageView)convertView.FindViewById(Resource.Id.img_op_icon));
                        convertView.Tag = viewHolder;
                        break;
                    }

                    case TYPE_SYSTEM_MESSAGE:
                    {
                        convertView = mInflater.Inflate(Resource.Layout.SendBirdViewSystemMessage, parent, false);
                        viewHolder.SetView("message", convertView.FindViewById(Resource.Id.txt_message) as TextView);
                        convertView.Tag = viewHolder;
                        break;
                    }

                    case TYPE_BROADCAST_MESSAGE:
                    {
                        convertView = mInflater.Inflate(Resource.Layout.SendBirdViewSystemMessage, parent, false);
                        viewHolder.SetView("message", convertView.FindViewById(Resource.Id.txt_message) as TextView);
                        convertView.Tag = viewHolder;
                        break;
                    }

                    case TYPE_FILELINK:
                    {
                        TextView tv;
                        convertView = mInflater.Inflate(Resource.Layout.SendBirdViewFileLink, parent, false);
                        tv          = convertView.FindViewById(Resource.Id.txt_sender_name) as TextView;

                        viewHolder.SetView("txt_sender_name", tv);
                        viewHolder.SetView("img_op_icon", convertView.FindViewById(Resource.Id.img_op_icon) as ImageView);
                        viewHolder.SetView("img_file_container", convertView.FindViewById(Resource.Id.img_file_container));
                        viewHolder.SetView("image_container", convertView.FindViewById(Resource.Id.image_container));
                        viewHolder.SetView("img_thumbnail", convertView.FindViewById(Resource.Id.img_thumbnail));
                        viewHolder.SetView("txt_image_name", convertView.FindViewById(Resource.Id.txt_image_name));
                        viewHolder.SetView("txt_image_size", convertView.FindViewById(Resource.Id.txt_image_size));

                        viewHolder.SetView("file_container", convertView.FindViewById(Resource.Id.file_container));
                        viewHolder.SetView("txt_file_name", convertView.FindViewById(Resource.Id.txt_file_name));
                        viewHolder.SetView("txt_file_size", convertView.FindViewById(Resource.Id.txt_file_size));

                        convertView.Tag = viewHolder;
                        break;
                    }
                    }
                }
                viewHolder = convertView.Tag as ViewHolder;
                switch (GetItemViewType(position))
                {
                case TYPE_UNSUPPORTED:
                    break;

                case TYPE_MESSAGE:
                {
                    SendBird.Model.Message message = item as SendBird.Model.Message;
                    viewHolder.GetView <ImageView> ("img_op_icon").Visibility = ViewStates.Gone;
                    var messageView = viewHolder.GetView <TextView> ("message");
                    messageView.TextFormatted = Html.FromHtml("<font color='#824096'><b>" + message.GetSenderName() + "</b></font>: " + message.message);
                    if (!messageView.HasOnClickListeners)
                    {
                        // To prevent mutiple click listners
                        messageView.Click += (sender, e) => {
                            var builder = new Android.App.AlertDialog.Builder(mContext);
                            builder.SetTitle("SENDBIRD");
                            builder.SetMessage("Do you want to start 1:1 messaging with " + message.GetSenderName() + "?");
                            builder.SetPositiveButton("OK", (s, ev) => {
                                    Intent data = new Intent();
                                    data.PutExtra("userIds", new string[] { message.GetSenderId() });
                                    ((SendBirdChatActivity)mContext).SetResult(Android.App.Result.Ok, data);
                                    ((SendBirdChatActivity)mContext).mDoNotDisconnect = true;
                                    ((SendBirdChatActivity)mContext).Finish();
                                });
                            builder.SetNegativeButton("Cancel", (EventHandler <DialogClickEventArgs>)null);

                            var dialog = builder.Create();
                            dialog.Show();
                        };
                    }
                    break;
                }

                case TYPE_SYSTEM_MESSAGE:
                {
                    SendBird.Model.SystemMessage systemMessage = item as SendBird.Model.SystemMessage;
                    viewHolder.GetView <TextView> ("message").TextFormatted = Html.FromHtml(systemMessage.message);
                    break;
                }

                case TYPE_BROADCAST_MESSAGE:
                {
                    SendBird.Model.BroadcastMessage broadcastMessage = item as SendBird.Model.BroadcastMessage;
                    viewHolder.GetView <TextView> ("message").TextFormatted = Html.FromHtml(broadcastMessage.message);
                    break;
                }

                case TYPE_FILELINK:
                {
                    FileLink fileLink = item as FileLink;
                    if (fileLink.isOpMessage)
                    {
                        viewHolder.GetView <ImageView> ("img_op_icon").Visibility       = ViewStates.Visible;
                        viewHolder.GetView <TextView> ("txt_sender_name").TextFormatted = Html.FromHtml("&nbsp;&nbsp;&nbsp;<font color='#824096'><b>" + fileLink.GetSenderName() + "</b></font>: ");
                    }
                    else
                    {
                        viewHolder.GetView <ImageView> ("img_op_icon").Visibility      = ViewStates.Gone;
                        viewHolder.GetView <TextView>("txt_sender_name").TextFormatted = Html.FromHtml("<font color='#824096'><b>" + fileLink.GetSenderName() + "</b></font>: ");
                    }
                    if (fileLink.fileInfo.type.ToLower().StartsWith("image"))
                    {
                        viewHolder.GetView("file_container").Visibility = ViewStates.Gone;

                        viewHolder.GetView("image_container").Visibility     = ViewStates.Visible;
                        viewHolder.GetView <TextView>("txt_image_name").Text = fileLink.fileInfo.name;
                        viewHolder.GetView <TextView>("txt_image_size").Text = fileLink.fileInfo.size.ToString();
                        if (fileLink.fileInfo.url != null && fileLink.fileInfo.url != "null")
                        {
                            DisplayUrlImage(viewHolder.GetView <ImageView> ("img_thumbnail"), fileLink.fileInfo.url);
                        }
                    }
                    else
                    {
                        viewHolder.GetView("image_container").Visibility = ViewStates.Gone;

                        viewHolder.GetView("file_container").Visibility     = ViewStates.Visible;
                        viewHolder.GetView <TextView>("txt_file_name").Text = fileLink.fileInfo.name;
                        viewHolder.GetView <TextView>("txt_file_size").Text = "" + fileLink.fileInfo.size.ToString();
                    }
                    viewHolder.GetView("txt_sender_name").Click += (sender, e) => {
                        var builder = new Android.App.AlertDialog.Builder(mContext);
                        builder.SetTitle("SENDBIRD");
                        builder.SetMessage("Do you want to start 1:1 messaging with " + fileLink.GetSenderName() + "?");
                        builder.SetPositiveButton("OK", (s, ev) => {
                                Intent data = new Intent();
                                data.PutExtra("userIds", new string[] { fileLink.GetSenderId() });
                                ((SendBirdChatActivity)mContext).SetResult(Android.App.Result.Ok, data);
                                ((SendBirdChatActivity)mContext).mDoNotDisconnect = true;
                                ((SendBirdChatActivity)mContext).Finish();
                            });
                        builder.SetNegativeButton("Cancel", (EventHandler <DialogClickEventArgs>)null);

                        var dialog = builder.Create();
                        dialog.Show();
                    };
                    break;
                }
                }

                return(convertView);
            }