From 94ab61d5c0b060e2aea5caf58ac06864f980956b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 19 Feb 2014 08:21:33 +0100 Subject: more speed optimizations --- src/de/gultsch/chat/ui/ConversationFragment.java | 54 +++++++++++++----------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index 8be44f49..0d2116e6 100644 --- a/src/de/gultsch/chat/ui/ConversationFragment.java +++ b/src/de/gultsch/chat/ui/ConversationFragment.java @@ -157,18 +157,14 @@ public class ConversationFragment extends Fragment { int type = getItemViewType(position); ViewHolder viewHolder; if (view == null) { + viewHolder = new ViewHolder(); switch (type) { case SENT: - viewHolder = new ViewHolder(); view = (View) inflater.inflate(R.layout.message_sent, null); viewHolder.imageView = (ImageView) view .findViewById(R.id.message_photo); - viewHolder.messageBody = (TextView) view - .findViewById(R.id.message_body); - viewHolder.time = (TextView) view - .findViewById(R.id.message_time); - view.setTag(viewHolder); + viewHolder.imageView.setImageBitmap(selfBitmap); break; case RECIEVED: viewHolder = new ViewHolder(); @@ -176,36 +172,43 @@ public class ConversationFragment extends Fragment { R.layout.message_recieved, null); viewHolder.imageView = (ImageView) view .findViewById(R.id.message_photo); - viewHolder.messageBody = (TextView) view - .findViewById(R.id.message_body); - viewHolder.time = (TextView) view - .findViewById(R.id.message_time); - view.setTag(viewHolder); + if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { + Uri uri = item.getConversation().getProfilePhotoUri(); + if (uri != null) { + viewHolder.imageView + .setImageBitmap(mBitmapCache.get(item + .getConversation().getName(), uri)); + } else { + viewHolder.imageView + .setImageBitmap(mBitmapCache.get(item + .getConversation().getName(), null)); + } + } break; default: viewHolder = null; break; } + viewHolder.messageBody = (TextView) view + .findViewById(R.id.message_body); + viewHolder.time = (TextView) view + .findViewById(R.id.message_time); + + view.setTag(viewHolder); } else { viewHolder = (ViewHolder) view.getTag(); } if (type == RECIEVED) { - if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { - Uri uri = item.getConversation().getProfilePhotoUri(); - if (uri != null) { - viewHolder.imageView.setImageBitmap(mBitmapCache.get(item.getConversation().getName(), uri)); - } else { - viewHolder.imageView.setImageBitmap(mBitmapCache.get(item.getConversation().getName(),null)); - } - } else if (item.getConversation().getMode() == Conversation.MODE_MULTI) { + if (item.getConversation().getMode() == Conversation.MODE_MULTI) { if (item.getCounterpart() != null) { - viewHolder.imageView.setImageBitmap(mBitmapCache.get(item.getCounterpart(),null)); + viewHolder.imageView.setImageBitmap(mBitmapCache + .get(item.getCounterpart(), null)); } else { - viewHolder.imageView.setImageBitmap(mBitmapCache.get(item.getConversation().getName(),null)); + viewHolder.imageView + .setImageBitmap(mBitmapCache.get(item + .getConversation().getName(), null)); } } - } else { - viewHolder.imageView.setImageBitmap(selfBitmap); } String body = item.getBody(); if (body != null) { @@ -406,15 +409,16 @@ public class ConversationFragment extends Fragment { protected ImageView imageView; } - + private class BitmapCache { private HashMap bitmaps = new HashMap(); + public Bitmap get(String name, Uri uri) { if (bitmaps.containsKey(name)) { return bitmaps.get(name); } else { Bitmap bm; - if (uri!=null) { + if (uri != null) { try { bm = BitmapFactory.decodeStream(getActivity() .getContentResolver().openInputStream(uri)); -- cgit v1.2.3