more speed optimizations
This commit is contained in:
parent
746f959155
commit
94ab61d5c0
|
@ -157,18 +157,14 @@ public class ConversationFragment extends Fragment {
|
||||||
int type = getItemViewType(position);
|
int type = getItemViewType(position);
|
||||||
ViewHolder viewHolder;
|
ViewHolder viewHolder;
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
|
viewHolder = new ViewHolder();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SENT:
|
case SENT:
|
||||||
viewHolder = new ViewHolder();
|
|
||||||
view = (View) inflater.inflate(R.layout.message_sent,
|
view = (View) inflater.inflate(R.layout.message_sent,
|
||||||
null);
|
null);
|
||||||
viewHolder.imageView = (ImageView) view
|
viewHolder.imageView = (ImageView) view
|
||||||
.findViewById(R.id.message_photo);
|
.findViewById(R.id.message_photo);
|
||||||
viewHolder.messageBody = (TextView) view
|
viewHolder.imageView.setImageBitmap(selfBitmap);
|
||||||
.findViewById(R.id.message_body);
|
|
||||||
viewHolder.time = (TextView) view
|
|
||||||
.findViewById(R.id.message_time);
|
|
||||||
view.setTag(viewHolder);
|
|
||||||
break;
|
break;
|
||||||
case RECIEVED:
|
case RECIEVED:
|
||||||
viewHolder = new ViewHolder();
|
viewHolder = new ViewHolder();
|
||||||
|
@ -176,36 +172,43 @@ public class ConversationFragment extends Fragment {
|
||||||
R.layout.message_recieved, null);
|
R.layout.message_recieved, null);
|
||||||
viewHolder.imageView = (ImageView) view
|
viewHolder.imageView = (ImageView) view
|
||||||
.findViewById(R.id.message_photo);
|
.findViewById(R.id.message_photo);
|
||||||
viewHolder.messageBody = (TextView) view
|
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
||||||
.findViewById(R.id.message_body);
|
Uri uri = item.getConversation().getProfilePhotoUri();
|
||||||
viewHolder.time = (TextView) view
|
if (uri != null) {
|
||||||
.findViewById(R.id.message_time);
|
viewHolder.imageView
|
||||||
view.setTag(viewHolder);
|
.setImageBitmap(mBitmapCache.get(item
|
||||||
|
.getConversation().getName(), uri));
|
||||||
|
} else {
|
||||||
|
viewHolder.imageView
|
||||||
|
.setImageBitmap(mBitmapCache.get(item
|
||||||
|
.getConversation().getName(), null));
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
viewHolder = null;
|
viewHolder = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
viewHolder.messageBody = (TextView) view
|
||||||
|
.findViewById(R.id.message_body);
|
||||||
|
viewHolder.time = (TextView) view
|
||||||
|
.findViewById(R.id.message_time);
|
||||||
|
|
||||||
|
view.setTag(viewHolder);
|
||||||
} else {
|
} else {
|
||||||
viewHolder = (ViewHolder) view.getTag();
|
viewHolder = (ViewHolder) view.getTag();
|
||||||
}
|
}
|
||||||
if (type == RECIEVED) {
|
if (type == RECIEVED) {
|
||||||
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||||
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.getCounterpart() != null) {
|
if (item.getCounterpart() != null) {
|
||||||
viewHolder.imageView.setImageBitmap(mBitmapCache.get(item.getCounterpart(),null));
|
viewHolder.imageView.setImageBitmap(mBitmapCache
|
||||||
|
.get(item.getCounterpart(), null));
|
||||||
} else {
|
} 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();
|
String body = item.getBody();
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
|
@ -409,12 +412,13 @@ public class ConversationFragment extends Fragment {
|
||||||
|
|
||||||
private class BitmapCache {
|
private class BitmapCache {
|
||||||
private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>();
|
private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>();
|
||||||
|
|
||||||
public Bitmap get(String name, Uri uri) {
|
public Bitmap get(String name, Uri uri) {
|
||||||
if (bitmaps.containsKey(name)) {
|
if (bitmaps.containsKey(name)) {
|
||||||
return bitmaps.get(name);
|
return bitmaps.get(name);
|
||||||
} else {
|
} else {
|
||||||
Bitmap bm;
|
Bitmap bm;
|
||||||
if (uri!=null) {
|
if (uri != null) {
|
||||||
try {
|
try {
|
||||||
bm = BitmapFactory.decodeStream(getActivity()
|
bm = BitmapFactory.decodeStream(getActivity()
|
||||||
.getContentResolver().openInputStream(uri));
|
.getContentResolver().openInputStream(uri));
|
||||||
|
|
Loading…
Reference in a new issue