diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-11-07 15:38:20 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-11-07 15:38:59 +0100 |
commit | e45d7bda3886989cf43be557cbb25889477c9068 (patch) | |
tree | 499e222082a5bfbdc2629a9216e8fdb9530bacaa /src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java | |
parent | e42b6d715b8f69992ead68546aae57fb59d5c838 (diff) |
UI code refactoring
Diffstat (limited to '')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java | 135 |
1 files changed, 61 insertions, 74 deletions
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 a24f90d7b..da7a548c5 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -1,16 +1,5 @@ package eu.siacs.conversations.ui.adapter; -import java.util.List; - -import eu.siacs.conversations.Config; -import eu.siacs.conversations.R; -import eu.siacs.conversations.entities.Contact; -import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.entities.Downloadable; -import eu.siacs.conversations.entities.Message; -import eu.siacs.conversations.entities.Message.ImageParams; -import eu.siacs.conversations.ui.ConversationActivity; -import eu.siacs.conversations.utils.UIHelper; import android.content.Intent; import android.graphics.Typeface; import android.text.Spannable; @@ -19,9 +8,9 @@ import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; import android.util.DisplayMetrics; import android.view.View; -import android.view.ViewGroup; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; +import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageView; @@ -29,6 +18,18 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; +import java.util.List; + +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Contact; +import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Downloadable; +import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.entities.Message.ImageParams; +import eu.siacs.conversations.ui.ConversationActivity; +import eu.siacs.conversations.utils.UIHelper; + public class MessageAdapter extends ArrayAdapter<Message> { private static final int SENT = 0; @@ -323,10 +324,6 @@ public class MessageAdapter extends ArrayAdapter<Message> { .findViewById(R.id.message_box); viewHolder.contact_picture = (ImageView) view .findViewById(R.id.message_photo); - viewHolder.contact_picture.setImageBitmap(activity - .avatarService().get( - item.getConversation().getAccount(), - activity.getPixel(48))); viewHolder.download_button = (Button) view .findViewById(R.id.download_button); viewHolder.indicator = (ImageView) view @@ -350,11 +347,6 @@ public class MessageAdapter extends ArrayAdapter<Message> { .findViewById(R.id.message_photo); viewHolder.download_button = (Button) view .findViewById(R.id.download_button); - if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { - viewHolder.contact_picture.setImageBitmap(activity - .avatarService().get(item.getContact(), - activity.getPixel(48))); - } viewHolder.indicator = (ImageView) view .findViewById(R.id.security_indicator); viewHolder.image = (ImageView) view @@ -363,6 +355,8 @@ public class MessageAdapter extends ArrayAdapter<Message> { .findViewById(R.id.message_body); viewHolder.time = (TextView) view .findViewById(R.id.message_time); + viewHolder.indicatorReceived = (ImageView) view + .findViewById(R.id.indicator_received); view.setTag(viewHolder); break; case STATUS: @@ -370,30 +364,6 @@ public class MessageAdapter extends ArrayAdapter<Message> { R.layout.message_status, parent, false); viewHolder.contact_picture = (ImageView) view .findViewById(R.id.message_photo); - if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { - - viewHolder.contact_picture.setImageBitmap(activity - .avatarService().get( - item.getConversation().getContact(), - activity.getPixel(32))); - viewHolder.contact_picture.setAlpha(0.5f); - viewHolder.contact_picture - .setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - String name = item.getConversation() - .getName(); - String read = getContext() - .getString( - R.string.contact_has_read_up_to_this_point, - name); - Toast.makeText(getContext(), read, - Toast.LENGTH_SHORT).show(); - } - }); - - } break; default: viewHolder = null; @@ -404,9 +374,32 @@ public class MessageAdapter extends ArrayAdapter<Message> { } if (type == STATUS) { + if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { + + viewHolder.contact_picture.setImageBitmap(activity + .avatarService().get( + item.getConversation().getContact(), + activity.getPixel(32))); + viewHolder.contact_picture.setAlpha(0.5f); + viewHolder.contact_picture + .setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + String name = item.getConversation() + .getName(); + String read = getContext() + .getString( + R.string.contact_has_read_up_to_this_point, + name); + Toast.makeText(getContext(), read, + Toast.LENGTH_SHORT).show(); + } + }); + + } return view; - } - if (type == NULL) { + } else if (type == NULL) { if (position == getCount() - 1) { view.getLayoutParams().height = 1; } else { @@ -415,6 +408,19 @@ public class MessageAdapter extends ArrayAdapter<Message> { } view.setLayoutParams(view.getLayoutParams()); return view; + } else if (type == RECEIVED) { + Contact contact = item.getContact(); + if (contact != null) { + viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(contact, activity.getPixel(48))); + } else if (item.getConversation().getMode() == Conversation.MODE_MULTI) { + String name = item.getPresence(); + if (name == null) { + name = item.getCounterpart(); + } + viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(name, activity.getPixel(48))); + } + } else if (type == SENT) { + viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(item.getConversation().getAccount(), activity.getPixel(48))); } if (viewHolder.contact_picture != null) { @@ -426,7 +432,6 @@ public class MessageAdapter extends ArrayAdapter<Message> { if (MessageAdapter.this.mOnContactPictureClickedListener != null) { MessageAdapter.this.mOnContactPictureClickedListener .onContactPictureClicked(item); - ; } } @@ -447,24 +452,6 @@ public class MessageAdapter extends ArrayAdapter<Message> { }); } - if (type == RECEIVED) { - if (item.getConversation().getMode() == Conversation.MODE_MULTI) { - Contact contact = item.getContact(); - if (contact != null) { - viewHolder.contact_picture.setImageBitmap(activity - .avatarService() - .get(contact, activity.getPixel(48))); - } else { - String name = item.getPresence(); - if (name == null) { - name = item.getCounterpart(); - } - viewHolder.contact_picture.setImageBitmap(activity - .avatarService().get(name, activity.getPixel(48))); - } - } - } - if (item.getType() == Message.TYPE_IMAGE || item.getDownloadable() != null) { Downloadable d = item.getDownloadable(); @@ -532,6 +519,14 @@ public class MessageAdapter extends ArrayAdapter<Message> { } } + public interface OnContactPictureClicked { + public void onContactPictureClicked(Message message); + } + + public interface OnContactPictureLongClicked { + public void onContactPictureLongClicked(Message message); + } + private static class ViewHolder { protected LinearLayout message_box; @@ -544,12 +539,4 @@ public class MessageAdapter extends ArrayAdapter<Message> { protected ImageView contact_picture; } - - public interface OnContactPictureClicked { - public void onContactPictureClicked(Message message); - } - - public interface OnContactPictureLongClicked { - public void onContactPictureLongClicked(Message message); - } } |