private void generateDateHeaders(IList <MessageData> messages)
 {
     for (int i = 0; i < messages.Count; i++)
     {
         MessageData message = messages[i];
         this.items.Add(new Wrapper(this, message));
         if (messages.Count > i + 1)
         {
             MessageData nextMessage = messages[i + 1];
             if (!DateFormatter.IsSameDay(message.CreatedAt, nextMessage.CreatedAt))
             {
                 var dateMessage = new MessageData {
                     CreatedAt = message.CreatedAt, Type = MessageData.DataType.Date
                 };
                 this.items.Add(new Wrapper(this, dateMessage));
             }
         }
         else
         {
             var dateMessage = new MessageData {
                 CreatedAt = message.CreatedAt, Type = MessageData.DataType.Date
             };
             this.items.Add(new Wrapper(this, dateMessage));
         }
     }
 }
 //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
 //ORIGINAL LINE: @SuppressWarnings("unchecked") private boolean isPreviousSameDate(int position, java.util.Date dateToCompare)
 private bool isPreviousSameDate(int position, DateTime dateToCompare)
 {
     if (items.Count <= position)
     {
         return(false);
     }
     if (items[position].item is IMessage)
     {
         DateTime previousPositionDate = ((MessageData)items[position].item).CreatedAt;
         return(DateFormatter.IsSameDay(dateToCompare, previousPositionDate));
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        /// Adds messages list in chronological order. Use this method to add history.
        /// </summary>
        /// <param name="messages"> messages from history. </param>
        /// <param name="reverse">  {@code true} if need to reverse messages before adding. </param>
        public virtual void addToEnd(IList <MessageData> messages, bool reverse)
        {
            if (reverse)
            {
                messages = messages.Reverse().ToList();
            }

            if (items.Count > 0)
            {
                int      lastItemPosition = items.Count - 1;
                DateTime lastItem         = items[lastItemPosition].item.CreatedAt;
                if (DateFormatter.IsSameDay(messages[0].CreatedAt, lastItem))
                {
                    items.RemoveAt(lastItemPosition);
                    NotifyItemRemoved(lastItemPosition);
                }
            }

            int oldSize = items.Count;

            generateDateHeaders(messages);
            NotifyItemRangeInserted(oldSize, items.Count - oldSize);
        }