public override void OnBindViewHolder(RecyclerView.ViewHolder vh, int position) { try { int type = GetItemViewType(position); var item = MessageList[type]; if (item == null) { return; } switch (item.ApiType) { case ApiType.Text: { TextViewHolder holder = vh as TextViewHolder; LoadTextOfChatItem(holder, position, item); break; } case ApiType.Image: { ImageViewHolder holder = vh as ImageViewHolder; LoadImageOfChatItem(holder, position, item); break; } } } catch (Exception exception) { Console.WriteLine(exception); } }
private void LoadTextOfChatItem(TextViewHolder holder, int position, ChatMessagesDataObject item) { try { Console.WriteLine(position); holder.Time.Text = Methods.Time.TimeAgo(Convert.ToInt32(item.Time)); holder.TextSanitizerAutoLink.Load(Methods.FunString.DecodeString(item.Text), item.ApiPosition); } catch (Exception e) { Console.WriteLine(e); } }
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { try { //Setup your layout here >> var itemView = MessageList[viewType]; if (itemView != null) { if (itemView.ApiPosition == ApiPosition.Right && itemView.ApiType == ApiType.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.ApiPosition == ApiPosition.Left && itemView.ApiType == ApiType.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.ApiPosition == ApiPosition.Right && itemView.ApiType == ApiType.Image) { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Right_MS_image, parent, false); ImageViewHolder imageViewHolder = new ImageViewHolder(row); return(imageViewHolder); } if (itemView.ApiPosition == ApiPosition.Left && itemView.ApiType == ApiType.Image) { View row = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Left_MS_image, parent, false); ImageViewHolder imageViewHolder = new ImageViewHolder(row); return(imageViewHolder); } return(null); } return(null); } catch (Exception exception) { Console.WriteLine(exception); return(null); } }