Commit 9d3afd55 authored by Grigory Fedorov's avatar Grigory Fedorov

Last outgoing message and time are displayed in active chats.

parent 1787ea35
...@@ -451,8 +451,9 @@ public abstract class AbstractChat extends BaseEntity { ...@@ -451,8 +451,9 @@ public abstract class AbstractChat extends BaseEntity {
for (int index = messages.size() - 1; index >= 0; index--) { for (int index = messages.size() - 1; index >= 0; index--) {
MessageItem messageItem = messages.get(index); MessageItem messageItem = messages.get(index);
if (messageItem.getAction() == null) { if (messageItem.getAction() == null) {
lastText = messageItem.isIncoming() ? messageItem.getText() String lastMessage = messageItem.getText();
: "";
lastText = messageItem.isIncoming() ? "< " + lastMessage : "> " + lastMessage;
lastTime = messageItem.getTimestamp(); lastTime = messageItem.getTimestamp();
return; return;
} }
...@@ -467,8 +468,7 @@ public abstract class AbstractChat extends BaseEntity { ...@@ -467,8 +468,7 @@ public abstract class AbstractChat extends BaseEntity {
Application.getInstance().runInBackground(new Runnable() { Application.getInstance().runInBackground(new Runnable() {
@Override @Override
public void run() { public void run() {
MessageTable.getInstance().removeMessages( MessageTable.getInstance().removeMessages(MessageManager.getMessageIds(messageItems, true));
MessageManager.getMessageIds(messageItems, true));
} }
}); });
} }
...@@ -482,8 +482,7 @@ public abstract class AbstractChat extends BaseEntity { ...@@ -482,8 +482,7 @@ public abstract class AbstractChat extends BaseEntity {
Application.getInstance().runInBackground(new Runnable() { Application.getInstance().runInBackground(new Runnable() {
@Override @Override
public void run() { public void run() {
MessageTable.getInstance().removeMessages( MessageTable.getInstance().removeMessages(MessageManager.getMessageIds(messageItems, true));
MessageManager.getMessageIds(messageItems, true));
MessageTable.getInstance().removeMessages(historyIds); MessageTable.getInstance().removeMessages(historyIds);
historyIds.clear(); historyIds.clear();
} }
......
...@@ -15,8 +15,11 @@ import com.xabber.android.data.message.MessageManager; ...@@ -15,8 +15,11 @@ import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.ui.ContactEditor; import com.xabber.android.ui.ContactEditor;
import com.xabber.android.ui.ContactViewer; import com.xabber.android.ui.ContactViewer;
import com.xabber.android.utils.StringUtils;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import java.util.Date;
public class ContactItemInflater { public class ContactItemInflater {
static class ContactViewHolder { static class ContactViewHolder {
...@@ -78,13 +81,7 @@ public class ContactItemInflater { ...@@ -78,13 +81,7 @@ public class ContactItemInflater {
viewHolder.avatar.setOnClickListener(new View.OnClickListener() { viewHolder.avatar.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (MUCManager.getInstance().hasRoom(abstractContact.getAccount(), abstractContact.getUser())) { onAvatarClick(abstractContact);
context.startActivity(ContactViewer.createIntent(context,
abstractContact.getAccount(), abstractContact.getUser()));
} else {
context.startActivity(ContactEditor.createIntent(context,
abstractContact.getAccount(), abstractContact.getUser()));
}
} }
}); });
...@@ -93,8 +90,12 @@ public class ContactItemInflater { ...@@ -93,8 +90,12 @@ public class ContactItemInflater {
if (MessageManager.getInstance() if (MessageManager.getInstance()
.hasActiveChat(abstractContact.getAccount(), abstractContact.getUser())) { .hasActiveChat(abstractContact.getAccount(), abstractContact.getUser())) {
statusText = MessageManager.getInstance() String lastMessage = MessageManager.getInstance()
.getLastText(abstractContact.getAccount(), abstractContact.getUser()); .getLastText(abstractContact.getAccount(), abstractContact.getUser());
Date lastTime = MessageManager.getInstance()
.getLastTime(abstractContact.getAccount(), abstractContact.getUser());
statusText = StringUtils.getSmartTimeText(context, lastTime) + " " + lastMessage;
} else { } else {
statusText = abstractContact.getStatusText(); statusText = abstractContact.getStatusText();
} }
...@@ -126,4 +127,14 @@ public class ContactItemInflater { ...@@ -126,4 +127,14 @@ public class ContactItemInflater {
return view; return view;
} }
private void onAvatarClick(AbstractContact contact) {
if (MUCManager.getInstance().hasRoom(contact.getAccount(), contact.getUser())) {
context.startActivity(ContactViewer.createIntent(context,
contact.getAccount(), contact.getUser()));
} else {
context.startActivity(ContactEditor.createIntent(context,
contact.getAccount(), contact.getUser()));
}
}
} }
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