调整.9图缓存策略

This commit is contained in:
zlzw 2022-10-11 17:56:15 +08:00
parent 447f8537f1
commit 1a8e7ecae9
2 changed files with 23 additions and 3 deletions

View File

@ -77,6 +77,7 @@ import com.yunbao.live.socket.SocketClient;
import com.yunbao.live.socket.SocketMessageListener;
import com.yunbao.live.socket.SocketRyChatUtil;
import com.yunbao.live.socket.SocketRyClient;
import com.yunbao.live.utils.LoadDian9TuUtil;
import com.yunbao.live.utils.UnzipFromAssets;
import com.yunbao.live.views.AbsLiveViewHolder;
import com.yunbao.live.views.LiveAddImpressViewHolder;
@ -1474,6 +1475,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
protected void release() {
EventBus.getDefault().unregister(this);
LiveHttpUtil.cancel(LiveHttpConsts.SEND_DANMU);
LoadDian9TuUtil.clearBitmap();
if (mKeyBoardHeightUtil != null) {
mKeyBoardHeightUtil.release();
}

View File

@ -15,11 +15,15 @@ import android.view.View;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.yunbao.live.activity.LiveActivity;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;
public class LoadDian9TuUtil {
private static final List<Bitmap> BITMAP_CACHE=new ArrayList<>();//.9图Bitmap缓存
public static void loadDian9Tu(Context context, View imageView, String imgUrl, int position) {
if (context == null) {
@ -39,9 +43,11 @@ public class LoadDian9TuUtil {
@Override
public void onResourceReady(@NonNull File resource, @Nullable Transition<? super File> transition) {
try {
FileInputStream is = new FileInputStream(resource);
setNinePathImage(context, imageView, BitmapFactory.decodeStream(is), position);
FileInputStream is=new FileInputStream(resource);
Bitmap bitmap=BitmapFactory.decodeStream(is);
BITMAP_CACHE.add(bitmap);
setNinePathImage(context, imageView, bitmap, position);
is.close();
} catch (Exception e) {
e.printStackTrace();
}
@ -63,4 +69,16 @@ public class LoadDian9TuUtil {
imageView.setBackground(patchy);
}
}
/**
* @see LiveActivity#onDestroy() 结束时释放掉.9图缓存
*/
public static void clearBitmap(){
for (Bitmap bitmap : BITMAP_CACHE) {
if(bitmap!=null) {
bitmap.recycle();
}
}
BITMAP_CACHE.clear();
}
}