Fix chat history duplicate dates on incoming message.

cusax-fix
Yana Stamcheva 17 years ago
parent 5d70236c72
commit b7d015f501

@ -733,7 +733,7 @@ private void initProgressBar(Date date)
public void messageReceived(MessageReceivedEvent evt)
{
Contact sourceContact = evt.getSourceContact();
this.processMessage(sourceContact, evt.getTimestamp(),
Constants.INCOMING_MESSAGE,
evt.getSourceMessage().getContent(),
@ -789,7 +789,8 @@ private void processMessage(Contact contact,
Date lastDate = datesPanel.getDate(lastDateIndex);
if(lastDate != null
&& GuiUtils.compareDates(lastDate.getTime(), timestamp) == 0)
&& GuiUtils.compareDatesOnly(
lastDate.getTime(), timestamp) == 0)
{
HTMLDocument document = dateHistoryTable.get(lastDate);
@ -797,7 +798,8 @@ private void processMessage(Contact contact,
{
ChatMessage chatMessage = new ChatMessage(
contact.getDisplayName(),
timestamp, messageType,
timestamp,
messageType,
messageContent,
messageContentType);
@ -808,7 +810,7 @@ private void processMessage(Contact contact,
}
}
else if (lastDate == null
|| GuiUtils.compareDates(lastDate.getTime(), timestamp) < 0)
|| GuiUtils.compareDatesOnly(lastDate.getTime(), timestamp) < 0)
{
long milisecondsPerDay = 24*60*60*1000;

@ -22,6 +22,8 @@ public class GuiUtils
{
private static Calendar c1 = Calendar.getInstance();
private static Calendar c2 = Calendar.getInstance();
/**
* Number of milliseconds in a second.
*/
@ -96,6 +98,48 @@ public static int compareDates(long date1, long date2)
return (date1 < date2 ? -1 : (date1 == date2 ? 0 : 1));
}
/**
* Compares the two dates. The comparison is based only on the day, month
* and year values. Returns 0 if the two dates are equals, a value < 0 if
* the first date is before the second one and > 0 if the first date is
* after the second one.
* @param date1 the first date to compare
* @param date2 the second date to compare with
* @return Returns 0 if the two dates are equals, a value < 0 if
* the first date is before the second one and > 0 if the first date is
* after the second one
*/
public static int compareDatesOnly(long date1, long date2)
{
c1.setTimeInMillis(date1);
c2.setTimeInMillis(date2);
int day1 = c1.get(Calendar.DAY_OF_MONTH);
int month1 = c1.get(Calendar.MONTH);
int year1 = c1.get(Calendar.YEAR);
int day2 = c2.get(Calendar.DAY_OF_MONTH);
int month2 = c2.get(Calendar.MONTH);
int year2 = c2.get(Calendar.YEAR);
if((day1 == day2)
&& (month1 == month2)
&& (year1 == year2))
{
return 0;
}
else if((day1 < day2)
&& (month1 <= month2)
&& (year1 <= year2))
{
return -1;
}
else
{
return 1;
}
}
/**
* Formats the given date. The result format is the following:
* [Month] [Day], [Year]. For example: Dec 24, 2000.
@ -173,12 +217,12 @@ public static Date substractDates(Date date1, Date date2)
int sec
= (int)(( difMil - days*milPerDay - hour*milPerHour - min*milPerMin)
/ milPerSec);
c1.clear();
c1.set(Calendar.HOUR, hour);
c1.set(Calendar.MINUTE, min);
c1.set(Calendar.SECOND, sec);
return c1.getTime();
}

Loading…
Cancel
Save