OnCreateViewHolder(ViewGroup parent, int viewType) { // Inflate the CardView for the photo: //////View itemView = LayoutInflater.From(parent.Context). ////// Inflate(Resource.Layout.List_item_private_chat_message_send_recv, parent, false); //////PrivateMessgeHolder vh = new PrivateMessgeHolder(itemView, OnClick,); //////return vh; RecyclerView.ViewHolder viewHolder = null; LayoutInflater inflater = LayoutInflater.From(parent.Context); switch (viewType) { case ListItem.TYPE_GENERAL: View v1 = inflater.Inflate(Resource.Layout.List_item_private_chat_message_send_recv, parent, false); viewHolder = new PrivateMessgeHolder(v1, OnClick, consolidatedList); break; case ListItem.TYPE_DATE: View v2 = inflater.Inflate(Resource.Layout.List_Item_Date_privateMsg, parent, false); viewHolder = new DateViewHolder(v2, consolidatedList); break; } return(viewHolder); }
OnBindViewHolder(RecyclerView.ViewHolder holder, int position) { PrivateMessgeHolder vh = holder as PrivateMessgeHolder; switch (consolidatedList[position].getType()) { case 1: { GeneralItem GeneralItem = (GeneralItem)consolidatedList[position]; var item = GeneralItem.getChatMessagearray(); Boolean isMe = item.ContactId != Common.CommonHelper.GetUserId(); var AttachList = (item.ChatMessageId != 0) ? Repositories.ChatAttachmentRepository.GetChatAttachList(item.ChatMessageId) : new List <ChatAttachment>(); if (isMe) { vh.tv_messageRight.Text = item.MessageText; vh.message_timeRight.Text = item.MessageTime.ToLocalTime().ToString("hh:mm tt"); if (AttachList.Count > 0) { CommonHelper.SetImageOnUIImageView(vh.iv_AttachImage, AttachList.FirstOrDefault().url, context, 600, 600); vh.iv_AttachImage.SetOnClickListener(new iv_AttachImageClikLitener(item, context)); vh.ll_LinearLayoutForImageAttachRight.Visibility = ViewStates.Visible; } else { vh.ll_LinearLayoutForImageAttachRight.Visibility = ViewStates.Gone; } if (item.IsRead) { vh.iv_StatusRight.SetImageResource(Resource.Drawable.message_got_read_receipt_from_target); } else if (item.IsRecieved) { vh.iv_StatusRight.SetImageResource(Resource.Drawable.message_got_receipt_from_target); } else if (item.IsSend) { vh.iv_StatusRight.SetImageResource(Resource.Drawable.message_got_receipt_from_server); } else { vh.iv_StatusRight.SetImageResource(Resource.Drawable.pending); } vh.ll_LinearLayoutRight.Visibility = ViewStates.Visible; vh.ll_LinearLayoutLeft.Visibility = ViewStates.Gone; } else { vh.tv_messageLeft.Text = item.MessageText; vh.message_timeLeft.Text = item.MessageTime.ToLocalTime().ToString("hh:mm tt"); if (AttachList.Count > 0) { CommonHelper.SetImageOnUIImageView(vh.iv_AttachImageLeft, AttachList.FirstOrDefault().url, context, 600, 600); vh.iv_AttachImageLeft.SetOnClickListener(new iv_AttachImageLeftClikLitener(item, context)); vh.ll_LinearLayoutForImageAttachLeft.Visibility = ViewStates.Visible; } else { vh.ll_LinearLayoutForImageAttachLeft.Visibility = ViewStates.Gone; } vh.ll_LinearLayoutLeft.Visibility = ViewStates.Visible; vh.ll_LinearLayoutRight.Visibility = ViewStates.Gone; } break; } case 0: { DateViewHolder dh = holder as DateViewHolder; DateItem DateItem = (DateItem)consolidatedList[position]; var datetimedata = Convert.ToDateTime(DateItem.getDate()).ToLocalTime().Date; if (datetimedata.Date == DateTime.Now.Date) { dh.txt_Date_message.Text = "Today"; } else if (datetimedata.Date == DateTime.Now.Date.AddDays(-1)) { dh.txt_Date_message.Text = "Yesterday"; } else { dh.txt_Date_message.Text = datetimedata.ToString("MMM dd, yyyy"); } break; } } }