コード例 #1
0
        public override void OnBindViewHolder(RecyclerView.ViewHolder vh, int position)
        {
            try
            {
                int type = GetItemViewType(position);
                var item = MessageList[type];
                if (item == null)
                {
                    return;
                }
                switch (item.MessageType)
                {
                case "text":
                {
                    TextViewHolder holder = vh as TextViewHolder;
                    LoadTextOfChatItem(holder, position, item);
                    break;
                }

                case "media":
                {
                    ImageViewHolder holder = vh as ImageViewHolder;
                    LoadImageOfChatItem(holder, position, item);
                    break;
                }

                case "sticker" when item.Sticker.Contains(".gif"):
                {
                    GifViewHolder holder = vh as GifViewHolder;
                    LoadGifOfChatItem(holder, position, item);
                    break;
                }

                case "sticker":
                {
                    StickerViewHolder holder = vh as StickerViewHolder;
                    LoadStickerOfChatItem(holder, position, item);
                    break;
                }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
コード例 #2
0
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            try
            {
                //Setup your layout here >>
                var itemView = MessageList[viewType];
                if (itemView != null)
                {
                    if (itemView.From == UserDetails.UserId && itemView.MessageType == "text")
                    {
                        View           row            = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Right_MS_view, parent, false);
                        TextViewHolder textViewHolder = new TextViewHolder(row, ActivityContext);
                        return(textViewHolder);
                    }

                    if (itemView.To == UserDetails.UserId && itemView.MessageType == "text")
                    {
                        View           row            = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Left_MS_view, parent, false);
                        TextViewHolder textViewHolder = new TextViewHolder(row, ActivityContext);
                        return(textViewHolder);
                    }
                    if (itemView.From == UserDetails.UserId && itemView.MessageType == "media")
                    {
                        View            row             = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Right_MS_image, parent, false);
                        ImageViewHolder imageViewHolder = new ImageViewHolder(row);
                        return(imageViewHolder);
                    }
                    if (itemView.To == UserDetails.UserId && itemView.MessageType == "media")
                    {
                        View            row             = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Left_MS_image, parent, false);
                        ImageViewHolder imageViewHolder = new ImageViewHolder(row);
                        return(imageViewHolder);
                    }
                    if (itemView.From == UserDetails.UserId && itemView.MessageType == "sticker")
                    {
                        if (itemView.Sticker.Contains(".gif"))
                        {
                            View          row        = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Right_MS_gif, parent, false);
                            GifViewHolder viewHolder = new GifViewHolder(row);
                            return(viewHolder);
                        }
                        else
                        {
                            View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Right_MS_sticker, parent, false);
                            StickerViewHolder stickerViewHolder = new StickerViewHolder(row);
                            return(stickerViewHolder);
                        }
                    }
                    if (itemView.To == UserDetails.UserId && itemView.MessageType == "sticker")
                    {
                        if (itemView.Sticker.Contains(".gif"))
                        {
                            View          row        = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Left_MS_gif, parent, false);
                            GifViewHolder viewHolder = new GifViewHolder(row);
                            return(viewHolder);
                        }
                        else
                        {
                            View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Left_MS_sticker, parent, false);
                            StickerViewHolder stickerViewHolder = new StickerViewHolder(row);
                            return(stickerViewHolder);
                        }
                    }

                    return(null);
                }

                return(null);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return(null);
            }
        }
コード例 #3
0
        private void LoadTextOfChatItem(TextViewHolder holder, int position, GetChatConversationsObject.Messages item)
        {
            try
            {
                try
                {
                    if (holder.Time.Text != item.CreatedAt)
                    {
                        DateTime time = Methods.Time.UnixTimeStampToDateTime(int.Parse(item.CreatedAt));
                        holder.Time.Text = time.ToShortTimeString();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                holder.TextSanitizerAutoLink.Load(Methods.FunString.DecodeString(item.Text), item.Type);

                holder.LytParent.Activated = SelectedItems.Get(position, false);

                if (!holder.LytParent.HasOnClickListeners)
                {
                    holder.LytParent.Click += delegate
                    {
                        try
                        {
                            if (ClickListener == null)
                            {
                                return;
                            }

                            ClickListener.ItemClick(holder.LytParent, item, position);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    };

                    holder.LytParent.LongClick += delegate
                    {
                        try
                        {
                            if (ClickListener == null)
                            {
                                return;
                            }

                            ClickListener.ItemLongClick(holder.LytParent, item, position);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    };
                }


                ToggleCheckedBackground(holder, position);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }