aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/adapter
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/adapter')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java123
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java52
2 files changed, 46 insertions, 129 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
index 9c606c3e4..37cdf223e 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
@@ -3,6 +3,7 @@ package eu.siacs.conversations.ui.adapter;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
+import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -34,10 +35,8 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
- LayoutInflater inflater = (LayoutInflater) activity
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflater.inflate(R.layout.conversation_list_row,
- parent, false);
+ LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ view = inflater.inflate(R.layout.conversation_list_row,parent, false);
}
Conversation conversation = getItem(position);
if (this.activity instanceof ConversationActivity) {
@@ -53,20 +52,15 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
view.setBackgroundColor(Color.TRANSPARENT);
}
}
- TextView convName = (TextView) view
- .findViewById(R.id.conversation_name);
- if (conversation.getMode() == Conversation.MODE_SINGLE
- || activity.useSubjectToIdentifyConference()) {
+ TextView convName = (TextView) view.findViewById(R.id.conversation_name);
+ if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
convName.setText(conversation.getName());
} else {
convName.setText(conversation.getJid().toBareJid().toString());
}
- TextView mLastMessage = (TextView) view
- .findViewById(R.id.conversation_lastmsg);
- TextView mTimestamp = (TextView) view
- .findViewById(R.id.conversation_lastupdate);
- ImageView imagePreview = (ImageView) view
- .findViewById(R.id.conversation_lastimage);
+ TextView mLastMessage = (TextView) view.findViewById(R.id.conversation_lastmsg);
+ TextView mTimestamp = (TextView) view.findViewById(R.id.conversation_lastupdate);
+ ImageView imagePreview = (ImageView) view.findViewById(R.id.conversation_lastimage);
Message message = conversation.getLatestMessage();
@@ -76,89 +70,36 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
convName.setTypeface(null, Typeface.NORMAL);
}
- if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE
- || message.getDownloadable() != null) {
- Downloadable d = message.getDownloadable();
- if (conversation.isRead()) {
- mLastMessage.setTypeface(null, Typeface.ITALIC);
- } else {
- mLastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
- }
- if (d != null) {
- mLastMessage.setVisibility(View.VISIBLE);
- imagePreview.setVisibility(View.GONE);
- if (d.getStatus() == Downloadable.STATUS_CHECKING) {
- mLastMessage.setText(R.string.checking_image);
- } else if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
- if (message.getType() == Message.TYPE_FILE) {
- mLastMessage.setText(getContext().getString(R.string.receiving_file,d.getMimeType(), d.getProgress()));
- } else {
- mLastMessage.setText(getContext().getString(R.string.receiving_image, d.getProgress()));
- }
- } else if (d.getStatus() == Downloadable.STATUS_OFFER) {
- if (message.getType() == Message.TYPE_FILE) {
- mLastMessage.setText(R.string.file_offered_for_download);
- } else {
- mLastMessage.setText(R.string.image_offered_for_download);
- }
- } else if (d.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) {
- mLastMessage.setText(R.string.image_offered_for_download);
- } else if (d.getStatus() == Downloadable.STATUS_DELETED) {
- if (message.getType() == Message.TYPE_FILE) {
- mLastMessage.setText(R.string.file_deleted);
- } else {
- mLastMessage.setText(R.string.image_file_deleted);
- }
- } else if (d.getStatus() == Downloadable.STATUS_FAILED) {
- if (message.getType() == Message.TYPE_FILE) {
- mLastMessage.setText(R.string.file_transmission_failed);
- } else {
- mLastMessage.setText(R.string.image_transmission_failed);
- }
- } else if (message.getImageParams().width > 0) {
- mLastMessage.setVisibility(View.GONE);
- imagePreview.setVisibility(View.VISIBLE);
- activity.loadBitmap(message, imagePreview);
+ if (message.getImageParams().width > 0
+ && (message.getDownloadable() == null
+ || message.getDownloadable().getStatus() == Downloadable.STATUS_DELETED)) {
+ mLastMessage.setVisibility(View.GONE);
+ imagePreview.setVisibility(View.VISIBLE);
+ activity.loadBitmap(message, imagePreview);
+ } else {
+ Pair<String,Boolean> preview = UIHelper.getMessagePreview(activity,message);
+ mLastMessage.setVisibility(View.VISIBLE);
+ imagePreview.setVisibility(View.GONE);
+ mLastMessage.setText(preview.first);
+ if (preview.second) {
+ if (conversation.isRead()) {
+ mLastMessage.setTypeface(null, Typeface.ITALIC);
} else {
- mLastMessage.setText("");
+ mLastMessage.setTypeface(null,Typeface.BOLD_ITALIC);
}
- } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
- imagePreview.setVisibility(View.GONE);
- mLastMessage.setVisibility(View.VISIBLE);
- mLastMessage.setText(R.string.encrypted_message_received);
- } else if (message.getType() == Message.TYPE_FILE && message.getImageParams().width <= 0) {
- DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
- mLastMessage.setVisibility(View.VISIBLE);
- imagePreview.setVisibility(View.GONE);
- mLastMessage.setText(getContext().getString(R.string.file,file.getMimeType()));
- } else {
- mLastMessage.setVisibility(View.GONE);
- imagePreview.setVisibility(View.VISIBLE);
- activity.loadBitmap(message, imagePreview);
- }
- } else {
- if ((message.getEncryption() != Message.ENCRYPTION_PGP)
- && (message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
- mLastMessage.setText(message.getBody());
- } else {
- mLastMessage.setText(R.string.encrypted_message_received);
- }
- if (!conversation.isRead()) {
- mLastMessage.setTypeface(null, Typeface.BOLD);
} else {
- mLastMessage.setTypeface(null, Typeface.NORMAL);
+ if (conversation.isRead()) {
+ mLastMessage.setTypeface(null,Typeface.NORMAL);
+ } else {
+ mLastMessage.setTypeface(null,Typeface.BOLD);
+ }
}
- mLastMessage.setVisibility(View.VISIBLE);
- imagePreview.setVisibility(View.GONE);
}
- mTimestamp.setText(UIHelper.readableTimeDifference(getContext(),
- conversation.getLatestMessage().getTimeSent()));
- ImageView profilePicture = (ImageView) view
- .findViewById(R.id.conversation_image);
- profilePicture.setImageBitmap(activity.avatarService().get(
- conversation, activity.getPixel(56)));
+ mTimestamp.setText(UIHelper.readableTimeDifference(activity,conversation.getLatestMessage().getTimeSent()));
+ ImageView profilePicture = (ImageView) view.findViewById(R.id.conversation_image);
+ profilePicture.setImageBitmap(activity.avatarService().get(conversation, activity.getPixel(56)));
return view;
}
-}
+} \ No newline at end of file
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 9a69db119..a1361fa1b 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -144,7 +144,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
break;
default:
if (multiReceived) {
- info = getMessageDisplayName(message);
+ info = UIHelper.getMessageDisplayName(message);
}
break;
}
@@ -213,24 +213,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setTextIsSelectable(false);
}
- private String getMessageDisplayName(final Message message) {
- if (message.getStatus() == Message.STATUS_RECEIVED) {
- if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
- return getDisplayedMucCounterpart(message.getCounterpart());
- } else {
- final Contact contact = message.getContact();
- return contact != null ? contact.getDisplayName() : "";
- }
- } else {
- if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
- return getDisplayedMucCounterpart(message.getConversation().getJid());
- } else {
- final Jid jid = message.getConversation().getAccount().getJid();
- return jid.hasLocalpart() ? jid.getLocalpart() : jid.toDomainJid().toString();
- }
- }
- }
-
private void displayTextMessage(final ViewHolder viewHolder, final Message message) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
@@ -238,7 +220,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
if (message.getBody() != null) {
- final String nick = getMessageDisplayName(message);
+ final String nick = UIHelper.getMessageDisplayName(message);
final String formattedBody = message.getMergedBody().replaceAll("^/me ", nick + " ");
if (message.getType() != Message.TYPE_PRIVATE) {
if (message.hasMeCommand()) {
@@ -303,16 +285,15 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
private void displayOpenableMessage(ViewHolder viewHolder,final Message message) {
- final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE);
- viewHolder.download_button.setText(activity.getString(R.string.open_file, file.getMimeType()));
+ viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity,message)));
viewHolder.download_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- openDownloadable(file);
+ openDownloadable(message);
}
});
viewHolder.download_button.setOnLongClickListener(openContextMenu);
@@ -352,16 +333,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.image.setOnLongClickListener(openContextMenu);
}
- private String getDisplayedMucCounterpart(final Jid counterpart) {
- if (counterpart==null) {
- return "";
- } else if (!counterpart.isBareJid()) {
- return counterpart.getResourcepart();
- } else {
- return counterpart.toString();
- }
- }
-
@Override
public View getView(int position, View view, ViewGroup parent) {
final Message message = getItem(position);
@@ -481,8 +452,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (contact != null) {
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(contact, activity.getPixel(48)));
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
- viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(getDisplayedMucCounterpart(message.getCounterpart()),
- activity.getPixel(48)));
+ viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(
+ UIHelper.getMessageDisplayName(message),
+ activity.getPixel(48)));
}
} else if (type == SENT) {
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48)));
@@ -519,7 +491,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
Downloadable d = message.getDownloadable();
if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
if (message.getType() == Message.TYPE_FILE) {
- displayInfoMessage(viewHolder,activity.getString(R.string.receiving_file,d.getMimeType(),d.getProgress()));
+ displayInfoMessage(viewHolder,activity.getString(R.string.receiving_x_file,
+ UIHelper.getFileDescriptionString(activity,message),
+ d.getProgress()));
} else {
displayInfoMessage(viewHolder,activity.getString(R.string.receiving_image,d.getProgress()));
}
@@ -533,7 +507,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
} else if (d.getStatus() == Downloadable.STATUS_OFFER) {
if (message.getType() == Message.TYPE_FILE) {
- displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_file,d.getMimeType()));
+ displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_x_file,
+ UIHelper.getFileDescriptionString(activity,message)));
} else {
displayDownloadableMessage(viewHolder, message,activity.getString(R.string.download_image));
}
@@ -592,7 +567,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
}
- public void openDownloadable(DownloadableFile file) {
+ public void openDownloadable(Message message) {
+ DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
if (!file.exists()) {
Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show();
return;