diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-08-01 11:33:39 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-08-01 11:34:59 +0200 |
commit | 23752c581f79640a38d87aa2a6914deac475447d (patch) | |
tree | cf55b54ad2ea305812beb919fa90ab2c9f82fd27 /src/main/java/de/pixart/messenger/ui/adapter | |
parent | dbb0cf8ead030a624954d7e07161f71038d008bc (diff) |
update datebubbles
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/adapter')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index d0bacc245..8320ac8ad 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -18,6 +18,7 @@ import android.text.Spannable; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.Spanned; +import android.text.format.DateUtils; import android.text.style.ForegroundColorSpan; import android.text.style.RelativeSizeSpan; import android.text.style.StyleSpan; @@ -87,6 +88,10 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie private static final int SENT = 0; private static final int RECEIVED = 1; private static final int STATUS = 2; + private static final int DATE_SEPARATOR = 3; + + public static final String DATE_SEPARATOR_BODY = "DATE_SEPARATOR"; + private static final Pattern XMPP_PATTERN = Pattern .compile("xmpp\\:(?:(?:[" + Patterns.GOOD_IRI_CHAR @@ -151,12 +156,16 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie @Override public int getViewTypeCount() { - return 3; + return 4; } public int getItemViewType(Message message) { if (message.getType() == Message.TYPE_STATUS) { - return STATUS; + if (DATE_SEPARATOR_BODY.equals(message.getBody())) { + return DATE_SEPARATOR; + } else { + return STATUS; + } } else if (message.getStatus() <= Message.STATUS_RECEIVED) { return RECEIVED; } @@ -778,6 +787,10 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie View view; viewHolder = new ViewHolder(); switch (type) { + case DATE_SEPARATOR: + view = activity.getLayoutInflater().inflate(R.layout.message_date_bubble, parent, false); + viewHolder.status_message = (TextView) view.findViewById(R.id.status_message); + break; case SENT: view = activity.getLayoutInflater().inflate( R.layout.message_sent, parent, false); @@ -829,8 +842,6 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie break; case STATUS: view = activity.getLayoutInflater().inflate(R.layout.message_status, parent, false); - viewHolder.contact_picture = (ImageView) view.findViewById(R.id.message_photo); - viewHolder.status_message = (TextView) view.findViewById(R.id.status_message); viewHolder.load_more_messages = (Button) view.findViewById(R.id.load_more_messages); break; default: @@ -850,9 +861,18 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie boolean darkBackground = (type == SENT && (!isInValidSession || !mUseWhiteBackground)); - if (type == STATUS) { + if (type == DATE_SEPARATOR) { + if (UIHelper.today(message.getTimeSent())) { + viewHolder.status_message.setText(R.string.today); + } else if (UIHelper.yesterday(message.getTimeSent())) { + viewHolder.status_message.setText(R.string.yesterday); + } else { + viewHolder.status_message.setText(DateUtils.formatDateTime(activity, message.getTimeSent(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR)); + } + viewHolder.status_message.setTextColor(activity.getSecondaryTextColor()); + return view; + } else if (type == STATUS) { if ("LOAD_MORE".equals(message.getBody())) { - viewHolder.status_message.setVisibility(View.GONE); viewHolder.load_more_messages.setVisibility(View.VISIBLE); viewHolder.load_more_messages.setOnClickListener(new OnClickListener() { @Override @@ -861,9 +881,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } }); } else { - viewHolder.status_message.setVisibility(View.VISIBLE); viewHolder.load_more_messages.setVisibility(View.GONE); - viewHolder.status_message.setText(message.getBody()); } return view; } else { |