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

fix coding style

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