Commit a43c0b71 authored by Grigory Fedorov's avatar Grigory Fedorov

ChatMessageAdapter: system date and time format used.

parent d1949f1c
...@@ -199,7 +199,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -199,7 +199,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
if (timeStamp != null) { if (timeStamp != null) {
String delay = activity.getString(incoming ? R.string.chat_delay : R.string.chat_typed, String delay = activity.getString(incoming ? R.string.chat_delay : R.string.chat_typed,
StringUtils.getSmartTimeText(timeStamp)); StringUtils.getSmartTimeText(activity, timeStamp));
append(builder, delay, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay)); append(builder, delay, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay));
append(builder, divider, new TextAppearanceSpan(activity, R.style.ChatHeader)); append(builder, divider, new TextAppearanceSpan(activity, R.style.ChatHeader));
} }
...@@ -226,7 +226,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -226,7 +226,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
textView.setText(builder); textView.setText(builder);
textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setMovementMethod(LinkMovementMethod.getInstance());
String time = StringUtils.getSmartTimeText(messageItem.getTimestamp()); String time = StringUtils.getSmartTimeText(activity, messageItem.getTimestamp());
((TextView)view.findViewById(R.id.message_time)).setText(time); ((TextView)view.findViewById(R.id.message_time)).setText(time);
......
...@@ -14,13 +14,12 @@ ...@@ -14,13 +14,12 @@
*/ */
package com.xabber.android.utils; package com.xabber.android.utils;
import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
/** /**
* Helper class to get plural forms. * Helper class to get plural forms.
...@@ -123,25 +122,15 @@ public class StringUtils { ...@@ -123,25 +122,15 @@ public class StringUtils {
* @param timeStamp * @param timeStamp
* @return String with time or with date and time depend on current time. * @return String with time or with date and time depend on current time.
*/ */
public static String getSmartTimeText(Date timeStamp) { public static String getSmartTimeText(Context context, Date timeStamp) {
if (timeStamp == null) { if (timeStamp == null) {
return ""; return "";
} }
// today DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
Calendar midnight = new GregorianCalendar(); DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
// reset hour, minutes, seconds and millis
midnight.set(Calendar.HOUR_OF_DAY, 0);
midnight.set(Calendar.MINUTE, 0);
midnight.set(Calendar.SECOND, 0);
midnight.set(Calendar.MILLISECOND, 0);
if (timeStamp.getTime() > midnight.getTimeInMillis()) return dateFormat.format(timeStamp) + " " + timeFormat.format(timeStamp);
synchronized (TIME) {
return TIME.format(timeStamp);
}
else
return getDateTimeText(timeStamp);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment