From 1fd3bbfe2529d5488914babde0cf76b0de621840 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 8 Mar 2017 10:32:42 +0100 Subject: [PATCH] display chat states in conferences --- .../conversations/entities/MucOptions.java | 5 ++- .../ui/ConversationFragment.java | 30 +++++++++++++++ .../ui/adapter/MessageAdapter.java | 37 ++++++++++++------- .../siacs/conversations/utils/UIHelper.java | 12 +++++- src/main/res/layout/message_status.xml | 2 + src/main/res/values/strings.xml | 2 + 6 files changed, 73 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index 9f9ba0a6b..852959736 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -544,12 +544,15 @@ public class MucOptions { } } - public ArrayList getUsersWithChatState(ChatState state) { + public ArrayList getUsersWithChatState(ChatState state, int max) { synchronized (users) { ArrayList list = new ArrayList<>(); for(User user : users) { if (user.chatState == state) { list.add(user); + if (list.size() >= max) { + break; + } } } return list; diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 0b91e26c1..124a2c4b7 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1284,6 +1284,36 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } } } + } else { + ChatState state = ChatState.COMPOSING; + List users = conversation.getMucOptions().getUsersWithChatState(state,5); + if (users.size() == 0) { + state = ChatState.PAUSED; + users = conversation.getMucOptions().getUsersWithChatState(state, 5); + + } + if (users.size() > 0) { + Message statusMessage; + if (users.size() == 1) { + MucOptions.User user = users.get(0); + int id = state == ChatState.COMPOSING ? R.string.contact_is_typing : R.string.contact_has_stopped_typing; + statusMessage = Message.createStatusMessage(conversation, getString(id, UIHelper.getDisplayName(user))); + statusMessage.setTrueCounterpart(user.getRealJid()); + statusMessage.setCounterpart(user.getFullJid()); + } else { + StringBuilder builder = new StringBuilder(); + for(MucOptions.User user : users) { + if (builder.length() != 0) { + builder.append(", "); + } + builder.append(UIHelper.getDisplayName(user)); + } + int id = state == ChatState.COMPOSING ? R.string.contacts_are_typing : R.string.contacts_have_stopped_typing; + statusMessage = Message.createStatusMessage(conversation, getString(id, builder.toString())); + } + this.messageList.add(statusMessage); + } + } } } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 0a405b958..3e917d945 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -667,19 +667,28 @@ public class MessageAdapter extends ArrayAdapter 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()); + boolean showAvatar; + if (conversation.getMode() == Conversation.MODE_SINGLE) { + showAvatar = true; + loadAvatar(message,viewHolder.contact_picture,activity.getPixel(32)); + } else if (message.getCounterpart() != null ){ + showAvatar = true; + loadAvatar(message,viewHolder.contact_picture,activity.getPixel(32)); + } else { + showAvatar = false; + } + if (showAvatar) { + viewHolder.contact_picture.setAlpha(0.5f); + viewHolder.contact_picture.setVisibility(View.VISIBLE); + } else { + viewHolder.contact_picture.setVisibility(View.GONE); + } } return view; } else { - loadAvatar(message, viewHolder.contact_picture); + loadAvatar(message, viewHolder.contact_picture,activity.getPixel(48)); } viewHolder.contact_picture @@ -968,14 +977,16 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie class BitmapWorkerTask extends AsyncTask { private final WeakReference imageViewReference; private Message message = null; + private final int size; - public BitmapWorkerTask(ImageView imageView) { + public BitmapWorkerTask(ImageView imageView, int size) { imageViewReference = new WeakReference<>(imageView); + this.size = size; } @Override protected Bitmap doInBackground(Message... params) { - return activity.avatarService().get(params[0], activity.getPixel(48), isCancelled()); + return activity.avatarService().get(params[0], size, isCancelled()); } @Override @@ -990,9 +1001,9 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie } } - public void loadAvatar(Message message, ImageView imageView) { + public void loadAvatar(Message message, ImageView imageView, int size) { if (cancelPotentialWork(message, imageView)) { - final Bitmap bm = activity.avatarService().get(message, activity.getPixel(48), true); + final Bitmap bm = activity.avatarService().get(message, size, true); if (bm != null) { cancelPotentialWork(message, imageView); imageView.setImageBitmap(bm); @@ -1000,7 +1011,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie } else { imageView.setBackgroundColor(UIHelper.getColorForName(UIHelper.getMessageDisplayName(message))); imageView.setImageDrawable(null); - final BitmapWorkerTask task = new BitmapWorkerTask(imageView); + final BitmapWorkerTask task = new BitmapWorkerTask(imageView, size); final AsyncDrawable asyncDrawable = new AsyncDrawable(activity.getResources(), null, task); imageView.setImageDrawable(asyncDrawable); try { diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 401303eb9..eb398641f 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -22,6 +22,7 @@ import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.entities.Transferable; import eu.siacs.conversations.ui.XmppActivity; @@ -251,7 +252,16 @@ public class UIHelper { private static boolean isPositionFollowedByBigGrin(CharSequence body, int pos) { return body.length() <= pos + 1 - || ((body.charAt(pos+1) == '<') && (body.length() == pos+2 || Character.isWhitespace(body.charAt(pos+2)))); + || ((body.charAt(pos + 1) == '<') && (body.length() == pos + 2 || Character.isWhitespace(body.charAt(pos + 2)))); + } + + public static String getDisplayName(MucOptions.User user) { + Contact contact = user.getContact(); + if (contact != null) { + return contact.getDisplayName(); + } else { + return user.getName(); + } } public static String getFileDescriptionString(final Context context, final Message message) { diff --git a/src/main/res/layout/message_status.xml b/src/main/res/layout/message_status.xml index 71f278ecf..c4ca3597a 100644 --- a/src/main/res/layout/message_status.xml +++ b/src/main/res/layout/message_status.xml @@ -34,7 +34,9 @@ android:id="@+id/status_message" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:minHeight="32dp" android:layout_centerVertical="true" + android:gravity="center_vertical" android:layout_marginLeft="8dp" android:layout_toEndOf="@+id/message_photo" android:layout_toRightOf="@+id/message_photo" diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index cbf9a3658..b4544328f 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -503,6 +503,8 @@ Disable Account %s is typing… %s has stopped typing + %s are typing… + %s have stopped typing Typing notifications Let your contacts know when you are writing messages to them Send location