aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java134
1 files changed, 41 insertions, 93 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 22f6b662..e62aaf96 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
@@ -1,5 +1,16 @@
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;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
import java.util.List;
import de.tzur.conversations.Settings;
@@ -38,10 +49,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) {
@@ -57,20 +66,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);
if (Settings.SHOW_ONLINE_STATUS) {
TextView status = (TextView) view.findViewById(R.id.status);
@@ -100,91 +104,35 @@ 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)) {
- boolean parseEmoticons = Settings.PARSE_EMOTICONS;
- mLastMessage.setText(parseEmoticons ? UIHelper
- .transformAsciiEmoticons(getContext(), message.getBody()) : 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;
}