Ejemplo n.º 1
0
        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);

            //////GroupMessageHolder vh = new GroupMessageHolder(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_group_chat_message_send_recv, parent, false);
                viewHolder = new GroupMessageViewHolder(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);
        }
Ejemplo n.º 2
0
        OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            GroupMessageViewHolder vh = holder as GroupMessageViewHolder;

            switch (consolidatedList[position].getType())
            {
            case 1:
            {
                GeneralGroupItem GeneralItem = (GeneralGroupItem)consolidatedList[position];

                var item = GeneralItem.getChatMessagearray();
                //Boolean isMe = item.ContactId != Common.CommonHelper.GetUserId();
                var AttachList = (item.MessageId != 0) ? Repositories.GroupRepository.GetGroupMessageAttachList(item.MessageId) : new List <GroupAttachment>();
                //    var item = rvmGroupMessage[position];
                Boolean ishide = false;
                if (position > 0)
                {
                    if (consolidatedList[position - 1].getType() == 1)
                    {
                        GeneralGroupItem GeneralItemPrevious = (GeneralGroupItem)consolidatedList[position - 1];
                        string           oldName             = GeneralItemPrevious.getChatMessagearray().senderName;
                        string           newName             = item.senderName;
                        ishide = oldName == newName;
                    }
                }


                Boolean isMe = item.SenderUserId == Common.CommonHelper.GetUserId();

                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_AttachImageClikLitenerGroupImage(item, context));
                        vh.ll_LinearLayoutForImageAttachRight.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        vh.ll_LinearLayoutForImageAttachRight.Visibility = ViewStates.Gone;
                    }

                    var Status = (item.MessageId != 0) ? Repositories.GroupRepository.GetGroupMessageOverallStatusbyid(item.MessageId) : new GroupMessageStatus();
                    if (Status.IsRead)
                    {
                        vh.iv_StatusRight.SetImageResource(Resource.Drawable.message_got_read_receipt_from_target);
                    }

                    else if (Status.IsRecieved)
                    {
                        vh.iv_StatusRight.SetImageResource(Resource.Drawable.message_got_receipt_from_target);
                    }

                    else if (Status.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 (ishide)
                    {
                        vh.tv_SenderNameLeft.Visibility = ViewStates.Gone;
                    }
                    else
                    {
                        vh.tv_SenderNameLeft.Visibility = ViewStates.Visible;
                        vh.tv_SenderNameLeft.Text       = item.senderName;
                    }
                    if (AttachList.Count > 0)
                    {
                        CommonHelper.SetImageOnUIImageView(vh.iv_AttachImageLeft, AttachList.FirstOrDefault().url, context, 600, 600);
                        vh.iv_AttachImageLeft.SetOnClickListener(new iv_AttachImageLeftClikLitenerGroupImage(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;
            }
            }
        }