Commit 0bcca238 authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix coding style

parent 41cd2147
...@@ -7,15 +7,17 @@ import java.util.GregorianCalendar; ...@@ -7,15 +7,17 @@ import java.util.GregorianCalendar;
import java.util.TimeZone; import java.util.TimeZone;
import timber.log.Timber; import timber.log.Timber;
/**
* Utility class for converting epoch ms and date-time string.
*/
public class DateTime { public class DateTime {
private static final String TAG = DateTime.class.getName(); private static final String TAG = DateTime.class.getName();
private static final SimpleDateFormat sSimpleTimeFormat = new SimpleDateFormat("HH:mm"); private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
private static final SimpleDateFormat sSimpleDateFormat = new SimpleDateFormat("yyyy/MM/dd"); private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd");
private static final SimpleDateFormat sSimpleDayFormat = new SimpleDateFormat("MM/dd"); private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("MM/dd");
private static final SimpleDateFormat sSimpleDayTimeFormat = new SimpleDateFormat("MM/dd HH:mm"); private static final SimpleDateFormat DAY_TIME_FORMAT = new SimpleDateFormat("MM/dd HH:mm");
private static final SimpleDateFormat sSimpleDateTimeFormat = private static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm");
new SimpleDateFormat("yyyy/MM/dd HH:mm");
/** /**
* convert datetime ms to String. * convert datetime ms to String.
...@@ -26,26 +28,26 @@ public class DateTime { ...@@ -26,26 +28,26 @@ public class DateTime {
switch (format) { switch (format) {
case DAY: case DAY:
return sSimpleDayFormat.format(cal.getTime()); return DAY_FORMAT.format(cal.getTime());
case DATE: case DATE:
return sSimpleDateFormat.format(cal.getTime()); return DATE_FORMAT.format(cal.getTime());
case TIME: case TIME:
return sSimpleTimeFormat.format(cal.getTime()); return TIME_FORMAT.format(cal.getTime());
case DATE_TIME: case DATE_TIME:
return sSimpleDateTimeFormat.format(cal.getTime()); return DATE_TIME_FORMAT.format(cal.getTime());
case DAY_TIME: case DAY_TIME:
return sSimpleDayTimeFormat.format(cal.getTime()); return DAY_TIME_FORMAT.format(cal.getTime());
case AUTO_DAY_TIME: { case AUTO_DAY_TIME: {
final long curTimeMs = System.currentTimeMillis(); final long curTimeMs = System.currentTimeMillis();
Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("JST")); Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("JST"));
cal2.setTimeInMillis(curTimeMs); cal2.setTimeInMillis(curTimeMs);
if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal.get(Calendar.DAY_OF_YEAR) == cal2 if (cal.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
.get(Calendar.DAY_OF_YEAR)) { && cal.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)) {
//same day. //same day.
return sSimpleDayTimeFormat.format(cal.getTime()); return DAY_TIME_FORMAT.format(cal.getTime());
} else { } else {
return sSimpleDayFormat.format(cal.getTime()); return DAY_FORMAT.format(cal.getTime());
} }
} }
default: default:
...@@ -59,7 +61,7 @@ public class DateTime { ...@@ -59,7 +61,7 @@ public class DateTime {
public static long fromDateToEpocMs(String dateString) { public static long fromDateToEpocMs(String dateString) {
try { try {
Calendar cal = new GregorianCalendar(); Calendar cal = new GregorianCalendar();
cal.setTime(sSimpleDateFormat.parse(dateString)); cal.setTime(DATE_FORMAT.parse(dateString));
return cal.getTimeInMillis(); return cal.getTimeInMillis();
} catch (ParseException exception) { } catch (ParseException exception) {
Timber.w(exception, "failed to parse date: %s", dateString); Timber.w(exception, "failed to parse date: %s", dateString);
...@@ -67,8 +69,10 @@ public class DateTime { ...@@ -67,8 +69,10 @@ public class DateTime {
return 0; return 0;
} }
/**
* format.
*/
public enum Format { public enum Format {
DATE, DAY, TIME, DATE_TIME, DAY_TIME, AUTO_DAY_TIME DATE, DAY, TIME, DATE_TIME, DAY_TIME, AUTO_DAY_TIME
} }
} }
\ No newline at end of file
...@@ -12,6 +12,7 @@ import chat.rocket.android.renderer.MessageRenderer; ...@@ -12,6 +12,7 @@ import chat.rocket.android.renderer.MessageRenderer;
import chat.rocket.android.widget.message.RocketChatMessageLayout; import chat.rocket.android.widget.message.RocketChatMessageLayout;
/** /**
* View holder of NORMAL chat message.
*/ */
public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> { public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
private final ImageView avatar; private final ImageView avatar;
...@@ -23,6 +24,9 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> { ...@@ -23,6 +24,9 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
private final View newDayContainer; private final View newDayContainer;
private final TextView newDayText; private final TextView newDayText;
/**
* constructor WITH hostname.
*/
public MessageViewHolder(View itemView, String hostname) { public MessageViewHolder(View itemView, String hostname) {
super(itemView); super(itemView);
avatar = (ImageView) itemView.findViewById(R.id.user_avatar); avatar = (ImageView) itemView.findViewById(R.id.user_avatar);
...@@ -35,6 +39,9 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> { ...@@ -35,6 +39,9 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
this.hostname = hostname; this.hostname = hostname;
} }
/**
* bind the view model.
*/
public void bind(PairedMessage pairedMessage) { public void bind(PairedMessage pairedMessage) {
new MessageRenderer(itemView.getContext(), pairedMessage.target) new MessageRenderer(itemView.getContext(), pairedMessage.target)
.avatarInto(avatar, hostname) .avatarInto(avatar, hostname)
......
...@@ -15,12 +15,18 @@ public class PairedMessage { ...@@ -15,12 +15,18 @@ public class PairedMessage {
this.nextSibling = nextSibling; this.nextSibling = nextSibling;
} }
/**
* Returns true if target and nextSibling has the same date of timestamp.
*/
public boolean hasSameDate() { public boolean hasSameDate() {
return nextSibling != null return nextSibling != null
&& DateTime.fromEpocMs(nextSibling.getTs(), DateTime.Format.DATE) && DateTime.fromEpocMs(nextSibling.getTs(), DateTime.Format.DATE)
.equals(DateTime.fromEpocMs(target.getTs(), DateTime.Format.DATE)); .equals(DateTime.fromEpocMs(target.getTs(), DateTime.Format.DATE));
} }
/**
* Returns true if target and nextSibling are sent by the same user.
*/
public boolean hasSameUser() { public boolean hasSameUser() {
return nextSibling != null return nextSibling != null
&& nextSibling.getU() != null && target.getU() != null && nextSibling.getU() != null && target.getU() != null
......
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