public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath) { ListItem msg = messages[indexPath.Row]; if (msg.getType() == 1) { List <ChatAttachment> AttachList = new List <ChatAttachment>(); GeneralItem GeneralItem = (GeneralItem)msg; var item = GeneralItem.getChatMessagearray(); AttachList = (item.ChatMessageId != 0) ? Repositories.ChatAttachmentRepository.GetChatAttachList(item.ChatMessageId) : new List <ChatAttachment>(); if (AttachList.Count > 0) { return(ChatBubbleWithAttachmentCell.GetHeight(tableView, item.MessageText, "10:11 PM").Height); } else { return(ChatBubbleCell.GetHeight(tableView, item.MessageText, "10:11 PM").Height); } } else { return(32); }// return ChatBubbleCell.GetSizeForText(tableView, messages[indexPath.Row].Text).Height + ChatBubbleCell.BubblePadding.Height; //Message msg = messages[indexPath.Row]; //return CalculateHeightFor(msg, tableView); }
public void LoadLocalLatestMessages() { try { loadList = false; if (chatConversation != null) { ListChatsCon = ChatMessageRepository.GetChatMessagesForPageIndex(paginationModel, chatConversation.ChatId); messages = new List <Message>(); if (ListChatsCon != null && ListChatsCon.Count > 0) { consolidatedList = new List <ListItem>(); foreach (var itemm in ListChatsCon) { DateItem dateItem = new DateItem(); dateItem.setDate(itemm.Key.ToShortDateString()); consolidatedList.Add(dateItem); foreach (var general in itemm.Value) { GeneralItem generalItem = new GeneralItem(); generalItem.setChatMessagearray(general); consolidatedList.Add(generalItem); } } foreach (var ChatConverstions in consolidatedList) { message = new Message(); switch (ChatConverstions.getType()) { case 1: { GeneralItem GeneralItem = (GeneralItem)ChatConverstions; 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) { message.Text = item.MessageText; message.Type = MessageType.Outgoing; } else { message.Text = item.MessageText; message.Type = MessageType.Incoming; } break; } case 0: { break; } } messages.Add(message); } chatSource = new ChatSource(messages); tableView.Source = chatSource; tableView.ReloadData(); ScrollToBottom(true); } } } catch (Exception e) { //Crashes.TrackError(e); } }
public void UpdateCell(ListItem ChatConverstions, int position) { switch (ChatConverstions.getType()) { case 1: { // txt_Date_message.Hidden = true; GeneralItem GeneralItem = (GeneralItem)ChatConverstions; 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) { //RightUserMsg.Text = item.MessageText; //RightMsgTime.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; //LeftView.Hidden = true; //RightView.Hidden = false; // txt_Date_message.Hidden = true; // LeftUserMsg.Hidden = true; // LeftMsgTime.Hidden = true; } else { LeftUserMsg.Text = item.MessageText; LeftMsgTime.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)); //ll_LinearLayoutForImageAttachLeft.Visibility = ViewStates.Visible; } else { //vh.ll_LinearLayoutForImageAttachLeft.Visibility = ViewStates.Gone; } //vh.ll_LinearLayoutLeft.Visibility = ViewStates.Visible; //vh.ll_LinearLayoutRight.Visibility = ViewStates.Gone; LeftUserMsg.Hidden = false; LeftMsgTime.Hidden = false; //LeftView.Hidden = false; //RightView.Hidden = true; } break; } case 0: { // txt_Date_message.Hidden = false; LeftUserMsg.Hidden = false; LeftMsgTime.Hidden = false; //LeftView.Hidden = true; //RightView.Hidden = true; DateItem DateItem = (DateItem)ChatConverstions; var datetimedata = Convert.ToDateTime(DateItem.getDate()).ToLocalTime().Date; //if (datetimedata.Date == DateTime.Now.Date) //{ // txt_Date_message.Text = "Today"; //} //else if (datetimedata.Date == DateTime.Now.Date.AddDays(-1)) //{ // txt_Date_message.Text = "Yesterday"; //} //else //{ // txt_Date_message.Text = datetimedata.ToString("MMM dd, yyyy"); //} break; } } }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { //BubbleCell cell = null; //Message msg = messages[indexPath.Row]; //cell = (BubbleCell)tableView.DequeueReusableCell(GetReuseId(msg.Type)); //cell.Message = msg; //return cell; bool isLeft = false; ListItem msg = messages[indexPath.Row]; List <ChatAttachment> AttachList = new List <ChatAttachment>(); ChatMessage item = new ChatMessage(); switch (msg.getType()) { case 0: { //DateViewHolder dh = holder as DateViewHolder; DateItem DateItem = (DateItem)msg; var cell = tableView.DequeueReusableCell("DateLabelCell") as DateLabelCell; cell.UpdateCell(DateItem); return(cell); } default: GeneralItem GeneralItem = (GeneralItem)msg; item = GeneralItem.getChatMessagearray(); Boolean isMe = item.ContactId != Common.CommonHelper.GetUserId(); AttachList = (item.ChatMessageId != 0) ? Repositories.ChatAttachmentRepository.GetChatAttachList(item.ChatMessageId) : new List <ChatAttachment>(); if (isMe) { isLeft = false; } else { isLeft = true; } if (AttachList.Count > 0) { var cell = tableView.DequeueReusableCell("PrivateChatAttachmentCell") as PrivateChatAttachmentCell; cell.Update(item, this.uiNewView, isLeft); cell.OpenImageViewEvent += Cell_OpenImageViewEvent; // var cell = tableView.DequeueReusableCell(isLeft ? PrivateChatAttachmentCell.KeyLeft : PrivateChatAttachmentCell.KeyRight) as PrivateChatAttachmentCell; //if (cell == null) //cell = new PrivateChatAttachmentCell(isLeft); //cell.Update(item); return(cell); } else { var cell = tableView.DequeueReusableCell(isLeft ? ChatBubbleCell.KeyLeft : ChatBubbleCell.KeyRight) as ChatBubbleCell; if (cell == null) { cell = new ChatBubbleCell(isLeft); } cell.Update(item); return(cell); } } }