Skip to content

Commit 21e99df

Browse files
author
manshan
committed
use universal-image-downloader to download chat images to solve picasso out of memory issue
1 parent d65cbc9 commit 21e99df

File tree

3 files changed

+65
-17
lines changed

3 files changed

+65
-17
lines changed

mgandroid-teamtalk/src/com/mogujie/tt/adapter/ChatAdapter.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import com.mogujie.tt.imlib.IMSession;
1919
import com.mogujie.tt.imlib.utils.IMUIHelper;
2020
import com.mogujie.tt.log.Logger;
21-
import com.mogujie.tt.ui.utils.IMServiceHelper;
22-
import com.mogujie.widget.imageview.MGWebImageView;
2321

2422
/**
2523
*
@@ -28,7 +26,6 @@
2826
@SuppressLint("ResourceAsColor")
2927
public class ChatAdapter extends BaseAdapter {
3028
private LayoutInflater mInflater = null;
31-
private IMServiceHelper imServiceHelper;
3229
private List<RecentInfo> recentSessionList = new LinkedList<RecentInfo>();
3330
private static Logger logger = Logger.getLogger(ChatAdapter.class);
3431

@@ -135,7 +132,6 @@ public View getView(int position, View convertView, ViewGroup parent) {
135132
avatarUrl = "";
136133
}
137134

138-
139135
IMUIHelper.setEntityImageViewAvatar(holder.avatar, avatarUrl, sessionType);
140136

141137
// 设置其它信息
@@ -152,11 +148,6 @@ public View getView(int position, View convertView, ViewGroup parent) {
152148
}
153149
}
154150

155-
public void setIMService(IMServiceHelper imServiceHelper) {
156-
logger.d("recent#setIMService");
157-
this.imServiceHelper = imServiceHelper;
158-
}
159-
160151
public void setData(List<RecentInfo> recentSessionList) {
161152
logger.d("recent#set New recent session list");
162153

mgandroid-teamtalk/src/com/mogujie/tt/adapter/MessageAdapter.java

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
import com.mogujie.tt.widget.MessageOperatePopup;
6363
import com.mogujie.tt.widget.SpeekerToast;
6464
import com.mogujie.widget.imageview.MGWebImageView;
65+
import com.nostra13.universalimageloader.core.ImageLoader;
66+
import com.nostra13.universalimageloader.core.assist.FailReason;
67+
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
6568
import com.squareup.picasso.Picasso.LoadedFrom;
6669

6770
/**
@@ -510,7 +513,7 @@ public void onClick(View arg0) {
510513
logger.d("debug#pic#found failed receiving image message");
511514
updateItemState(info.msgId, SysConstant.MESSAGE_STATE_UNLOAD);
512515
}
513-
516+
514517
int menuType = getMenuType(info);
515518
if (menuType > 0) {
516519
// logger.d("debug#showMenu MessageInfo:%s", info);
@@ -1191,13 +1194,15 @@ private void downLoadImage(MessageInfo messageInfo) {
11911194

11921195
final MessageInfo messageInfoFinal = messageInfo;
11931196

1194-
MGWebImageView.fetchBitmap(context, smallImageUrl, new MGWebImageView.TargetCallback() {
1195-
@Override
1196-
public void onPrepareLoad(Drawable placeHolderDrawable) {
1197-
}
1197+
ImageLoader.getInstance().loadImage(smallImageUrl, null, null, new SimpleImageLoadingListener() {
1198+
//message_image
11981199

11991200
@Override
1200-
public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
1201+
public void onLoadingComplete(String imageUri, View view,
1202+
Bitmap bitmap) {
1203+
logger.d("chat#pic#icon onLoadingComplete");
1204+
//holder.image.setImageBitmap(loadedImage);
1205+
12011206
logger.d("chat#pic#onBitmapLoaded");
12021207
String smallImagePath = CommonUtil.getMd5Path(smallImageUrl, SysConstant.FILE_SAVE_TYPE_IMAGE);
12031208
File myFile = new File(smallImagePath);
@@ -1233,13 +1238,66 @@ public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
12331238
}
12341239

12351240
@Override
1236-
public void onBitmapFailed(Drawable errorDrawable) {
1241+
public void onLoadingFailed(String imageUri, View view,
1242+
FailReason failReason) {
1243+
logger.d("chat#pic#icon onLoadingFailed");
1244+
12371245
logger.d("chat#pic#onBitmapFailed");
12381246
updateMessageState(messageInfoFinal, SysConstant.MESSAGE_STATE_FINISH_FAILED);
12391247
logger.d("download failed");
12401248
}
1249+
12411250
});
12421251

1252+
// MGWebImageView.fetchBitmap(context, smallImageUrl, new MGWebImageView.TargetCallback() {
1253+
// @Override
1254+
// public void onPrepareLoad(Drawable placeHolderDrawable) {
1255+
// }
1256+
//
1257+
// @Override
1258+
// public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
1259+
// logger.d("chat#pic#onBitmapLoaded");
1260+
// String smallImagePath = CommonUtil.getMd5Path(smallImageUrl, SysConstant.FILE_SAVE_TYPE_IMAGE);
1261+
// File myFile = new File(smallImagePath);
1262+
// if (myFile.exists()) {
1263+
// logger.d("chat#pic#image already exists, no need to save");
1264+
// return;
1265+
// }
1266+
// BufferedOutputStream bos = null;
1267+
// try {
1268+
// if (null != bitmap) {
1269+
// FileOutputStream fout = new FileOutputStream(myFile);
1270+
// bos = new BufferedOutputStream(fout);
1271+
// bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
1272+
// bos.flush();
1273+
// bos.close();
1274+
// bos = null;
1275+
// logger.d("chat#pic#save image ok");
1276+
// updateMessageState(messageInfoFinal, SysConstant.MESSAGE_STATE_FINISH_SUCCESSED);
1277+
// }
1278+
// } catch (Exception e) {
1279+
// logger.e("chat#pic#downloading image got exception:%s", e.getMessage());
1280+
// } finally {
1281+
// try {
1282+
// if (null != bos) {
1283+
// bos.flush();
1284+
// bos.close();
1285+
// }
1286+
// } catch (IOException e) {
1287+
// e.printStackTrace();
1288+
//
1289+
// }
1290+
// }
1291+
// }
1292+
//
1293+
// @Override
1294+
// public void onBitmapFailed(Drawable errorDrawable) {
1295+
// logger.d("chat#pic#onBitmapFailed");
1296+
// updateMessageState(messageInfoFinal, SysConstant.MESSAGE_STATE_FINISH_FAILED);
1297+
// logger.d("download failed");
1298+
// }
1299+
// });
1300+
12431301
} catch (Exception e) {
12441302
logger.e(e.getMessage());
12451303
}

mgandroid-teamtalk/src/com/mogujie/tt/ui/fragment/ChatFragment.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ private void initContactListView() {
441441
// 绑定数据源
442442
try {
443443
contactAdapter = new ChatAdapter(getActivity());
444-
contactAdapter.setIMService(imServiceHelper);
445444
contactListView.setAdapter(contactAdapter);
446445
} catch (ParseException e) {
447446
logger.e(e.toString());

0 commit comments

Comments
 (0)