From 38ae1c31d4b038d846874d100c97bd4aa81c2448 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 11 Mar 2017 17:20:21 +0100 Subject: display chat states in conferences --- .../de/pixart/messenger/entities/Conversation.java | 8 ++ .../de/pixart/messenger/entities/MucOptions.java | 15 +++- .../pixart/messenger/ui/ConversationActivity.java | 98 +++++++++++++--------- .../messenger/ui/adapter/MessageAdapter.java | 14 ++-- .../java/de/pixart/messenger/utils/UIHelper.java | 10 +++ src/main/res/values-de/strings.xml | 4 + src/main/res/values/strings.xml | 6 +- 7 files changed, 106 insertions(+), 49 deletions(-) diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 082877ef7..fac28056f 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -515,6 +515,14 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } + public int getNumberOfParticipants() { + if (getMode() == MODE_MULTI) { + return getMucOptions().NumberOfUsers(); + } else { + return 0; + } + } + public String getAccountUuid() { return this.accountUuid; } diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java index d3d0e3e9e..51345df04 100644 --- a/src/main/java/de/pixart/messenger/entities/MucOptions.java +++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java @@ -542,12 +542,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; @@ -628,6 +631,16 @@ public class MucOptions { return this.subject; } + public int NumberOfUsers() { + if (users.size() >= 1) { + return users.size(); + } else { + return 0; + } + } + + + public String createNameFromParticipants() { if (users.size() >= 1) { StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index d60fbcbe4..4630fbcba 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -67,6 +67,7 @@ import de.pixart.messenger.entities.Blockable; import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.Message; +import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.entities.Presence; import de.pixart.messenger.entities.Transferable; import de.pixart.messenger.persistance.FileBackend; @@ -423,58 +424,73 @@ public class ConversationActivity extends XmppActivity ab.setCustomView(R.layout.ab_title); TextView abtitle = (TextView) findViewById(android.R.id.text1); TextView absubtitle = (TextView) findViewById(android.R.id.text2); - if (conversation.getMode() == Conversation.MODE_SINGLE || useSubjectToIdentifyConference()) { - abtitle.setText(conversation.getName()); - abtitle.setOnClickListener(this); - abtitle.setSelected(true); - if (conversation.getMode() == Conversation.MODE_SINGLE && !this.getSelectedConversation().withSelf()) { - if (conversation.getContact().getShownStatus() == Presence.Status.OFFLINE) { - absubtitle.setText(getString(R.string.account_status_offline)); + abtitle.setText(conversation.getName()); + abtitle.setOnClickListener(this); + abtitle.setSelected(true); + if (conversation.getMode() == Conversation.MODE_SINGLE && !this.getSelectedConversation().withSelf()) { + ChatState state = conversation.getIncomingChatState(); + if (conversation.getContact().getShownStatus() == Presence.Status.OFFLINE) { + absubtitle.setText(getString(R.string.account_status_offline)); + absubtitle.setSelected(true); + absubtitle.setOnClickListener(this); + } else { + if (state == ChatState.COMPOSING) { + absubtitle.setText(getString(R.string.is_typing)); + absubtitle.setTypeface(null, Typeface.BOLD_ITALIC); absubtitle.setSelected(true); absubtitle.setOnClickListener(this); } else { - ChatState state = conversation.getIncomingChatState(); - if (state == ChatState.COMPOSING) { - absubtitle.setText(getString(R.string.is_typing)); - absubtitle.setTypeface(null, Typeface.BOLD_ITALIC); - absubtitle.setSelected(true); - absubtitle.setOnClickListener(this); - } else if (state == ChatState.PAUSED) { - if (showLastSeen && conversation.getContact().getLastseen() > 0) { - absubtitle.setText(UIHelper.lastseen(getApplicationContext(), conversation.getContact().isActive(), conversation.getContact().getLastseen())); - } else { - absubtitle.setText(getString(R.string.account_status_online)); - } - absubtitle.setSelected(true); - absubtitle.setOnClickListener(this); + if (showLastSeen && conversation.getContact().getLastseen() > 0) { + absubtitle.setText(UIHelper.lastseen(getApplicationContext(), conversation.getContact().isActive(), conversation.getContact().getLastseen())); } else { - if (showLastSeen && conversation.getContact().getLastseen() > 0) { - absubtitle.setText(UIHelper.lastseen(getApplicationContext(), conversation.getContact().isActive(), conversation.getContact().getLastseen())); - } else { - absubtitle.setText(getString(R.string.account_status_online)); - } - absubtitle.setSelected(true); - absubtitle.setOnClickListener(this); + absubtitle.setText(getString(R.string.account_status_online)); } - } - } else if (useSubjectToIdentifyConference()) { - if (conversation.getParticipants() != null) { - absubtitle.setText(conversation.getParticipants()); absubtitle.setSelected(true); absubtitle.setOnClickListener(this); - } else { - absubtitle.setText(R.string.no_participants); - abtitle.setSelected(true); - absubtitle.setOnClickListener(this); } } } else { - abtitle.setText(conversation.getJid().toBareJid().toString()); - abtitle.setOnClickListener(this); - abtitle.setSelected(true); - absubtitle.setText(""); - absubtitle.setOnClickListener(this); + if (conversation.getParticipants() != null) { + ChatState state = ChatState.COMPOSING; + List userWithChatStates = conversation.getMucOptions().getUsersWithChatState(state, 5); + if (userWithChatStates.size() == 0) { + state = ChatState.PAUSED; + userWithChatStates = conversation.getMucOptions().getUsersWithChatState(state, 5); + + } + List users = conversation.getMucOptions().getUsers(true); + if (state == ChatState.COMPOSING) { + if (userWithChatStates.size() > 0) { + if (userWithChatStates.size() == 1) { + MucOptions.User user = userWithChatStates.get(0); + absubtitle.setText(getString(R.string.contact_is_typing, UIHelper.getDisplayName(user))); + } else { + StringBuilder builder = new StringBuilder(); + for (MucOptions.User user : userWithChatStates) { + if (builder.length() != 0) { + builder.append(", "); + } + builder.append(UIHelper.getDisplayName(user)); + } + absubtitle.setText(getString(R.string.contacts_are_typing, builder.toString())); + } + } + } else { + if (users.size() == 1) { + absubtitle.setText(getString(R.string.one_participant)); + } else { + absubtitle.setText(getString(R.string.more_participants, users.size())); + } + } + absubtitle.setSelected(true); + absubtitle.setOnClickListener(this); + } else { + absubtitle.setText(R.string.no_participants); + abtitle.setSelected(true); + absubtitle.setOnClickListener(this); + } } + } else { if ((ab.getDisplayOptions() & ActionBar.DISPLAY_HOME_AS_UP) == ActionBar.DISPLAY_HOME_AS_UP) { ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE); 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 6c87196fe..17dcb9d0f 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -835,7 +835,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie } return view; } else { - loadAvatar(message, viewHolder.contact_picture); + loadAvatar(message, viewHolder.contact_picture, activity.getPixel(48)); } viewHolder.contact_picture @@ -1156,14 +1156,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 @@ -1178,9 +1180,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); @@ -1188,7 +1190,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/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java index c350268d6..02d8f5789 100644 --- a/src/main/java/de/pixart/messenger/utils/UIHelper.java +++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java @@ -21,6 +21,7 @@ import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.ListItem; import de.pixart.messenger.entities.Message; +import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.entities.Presence; import de.pixart.messenger.entities.Transferable; import de.pixart.messenger.xmpp.jid.Jid; @@ -260,6 +261,15 @@ public class UIHelper { || ((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) { if (message.getType() == Message.TYPE_IMAGE) { return context.getString(R.string.image); diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index ae3d33496..7780b68ab 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -697,5 +697,9 @@ hoch (720p) niedrig (144p) mittelmäßig (360p) + %s schreibt… + %s tippen… + %d Teilnehmer + Ein Teilnehmer diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index c16c7b921..0c665884f 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -167,7 +167,7 @@ Are you sure? If you delete your account your entire conversation history will be lost Record voice - Jabber ID + Jabber-ID Password username@pix-art.de Confirm password @@ -752,4 +752,8 @@ Notifications from strangers Notify for messages received from strangers. Received message from stranger + %s are typing… + %s is typing… + one participant + %d participants -- cgit v1.2.3