aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java8
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java36
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java8
3 files changed, 29 insertions, 23 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index 59073cb77..f6c578e6c 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -189,6 +189,14 @@ public class Message extends AbstractEntity {
cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)));
}
+ public static Message createDateMessage(Conversation conversation, String body) {
+ final Message message = new Message();
+ message.setType(Message.TYPE_STATUS);
+ message.setConversation(conversation);
+ message.setBody(body);
+ return message;
+ }
+
public static Message createStatusMessage(Conversation conversation, String body) {
final Message message = new Message();
message.setType(Message.TYPE_STATUS);
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index e0b5b7e11..f2127b48e 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -41,9 +41,11 @@ import android.widget.Toast;
import net.java.otr4j.session.SessionStatus;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
import java.util.UUID;
import de.pixart.messenger.Config;
@@ -119,6 +121,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private TextView snackbarMessage;
private TextView snackbarAction;
private Toast messageLoaderToast;
+ SimpleDateFormat sdf = new SimpleDateFormat("EEEE, dd. MMM yyyy", Locale.getDefault());
+ String first = sdf.format(System.currentTimeMillis());
+ String today = sdf.format(System.currentTimeMillis());
private OnScrollListener mOnScrollListener = new OnScrollListener() {
@@ -1264,25 +1269,26 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (showLoadMoreMessages(conversation)) {
this.messageList.add(0, Message.createLoadMoreMessage(conversation));
}
- if (conversation.getMode() == Conversation.MODE_SINGLE) {
- ChatState state = conversation.getIncomingChatState();
- if (state == ChatState.COMPOSING) {
- //this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_is_typing, conversation.getName())));
- } else if (state == ChatState.PAUSED) {
- //this.messageList.add(Message.createStatusMessage(conversation, getString(R.string.contact_has_stopped_typing, conversation.getName())));
- } else {
- for (int i = this.messageList.size() - 1; i >= 0; --i) {
- if (this.messageList.get(i).getStatus() == Message.STATUS_RECEIVED) {
- return;
- } else {
- if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) {
-// this.messageList.add(i + 1,
-// Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, conversation.getName())));
-// return;
+
+ // show date in chat view
+ int max = this.messageList.size();
+ if (max == 0 || (max <= 1 && showLoadMoreMessages(conversation))){
+ this.messageList.add(0, Message.createDateMessage(conversation, getString(R.string.start_chatting)));
+ } else if ((max > 0 && !showLoadMoreMessages(conversation)) || (max > 1 && showLoadMoreMessages(conversation))) {
+ for (int i = (max - 1); i > 0; --i) {
+ String last = sdf.format(this.messageList.get(i).getTimeSent());
+ String date = first;
+ if (!last.equals(first)) {
+ if (i < (max - 1)) {
+ if (today.equals(first)) {
+ date = getString(R.string.today);
}
+ this.messageList.add(i + 1, Message.createDateMessage(conversation, date));
}
}
+ first = last;
}
+ this.messageList.add(0, Message.createDateMessage(conversation, first));
}
}
}
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 fa65b3af6..b71e98032 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -808,7 +808,6 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
if (type == STATUS) {
if ("LOAD_MORE".equals(message.getBody())) {
viewHolder.status_message.setVisibility(View.GONE);
- viewHolder.contact_picture.setVisibility(View.GONE);
viewHolder.load_more_messages.setVisibility(View.VISIBLE);
viewHolder.load_more_messages.setOnClickListener(new OnClickListener() {
@Override
@@ -818,14 +817,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
});
} else {
viewHolder.status_message.setVisibility(View.VISIBLE);
- viewHolder.contact_picture.setVisibility(View.VISIBLE);
viewHolder.load_more_messages.setVisibility(View.GONE);
- if (conversation.getMode() == Conversation.MODE_SINGLE) {
- viewHolder.contact_picture.setImageBitmap(activity
- .avatarService().get(conversation.getContact(),
- activity.getPixel(32)));
- viewHolder.contact_picture.setAlpha(0.5f);
- }
viewHolder.status_message.setText(message.getBody());
}
return view;