修复聊天框名牌混乱问题

This commit is contained in:
zlzw 2022-10-21 14:40:31 +08:00
parent c9743f28a3
commit dedb30d297
2 changed files with 31 additions and 24 deletions

View File

@ -77,6 +77,7 @@ import com.yunbao.live.socket.SocketClient;
import com.yunbao.live.socket.SocketMessageListener; import com.yunbao.live.socket.SocketMessageListener;
import com.yunbao.live.socket.SocketRyChatUtil; import com.yunbao.live.socket.SocketRyChatUtil;
import com.yunbao.live.socket.SocketRyClient; import com.yunbao.live.socket.SocketRyClient;
import com.yunbao.live.utils.LiveTextRender;
import com.yunbao.live.utils.LoadDian9TuUtil; import com.yunbao.live.utils.LoadDian9TuUtil;
import com.yunbao.live.utils.UnzipFromAssets; import com.yunbao.live.utils.UnzipFromAssets;
import com.yunbao.live.views.AbsLiveViewHolder; import com.yunbao.live.views.AbsLiveViewHolder;
@ -1522,6 +1523,7 @@ public abstract class LiveActivity extends AbsActivity implements SocketMessageL
// mMobShareUtil = null; // mMobShareUtil = null;
mImageUtil = null; mImageUtil = null;
SVGAViewUtils.clearSVGA(); SVGAViewUtils.clearSVGA();
LiveTextRender.clear();
L.e("LiveActivity--------release------>"); L.e("LiveActivity--------release------>");
Constants.isSend = "0"; Constants.isSend = "0";

View File

@ -36,6 +36,9 @@ import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.R; import com.yunbao.live.R;
import com.yunbao.live.bean.LiveChatBean; import com.yunbao.live.bean.LiveChatBean;
import java.util.HashMap;
import java.util.Map;
/** /**
* Created by cxf on 2018/10/11. * Created by cxf on 2018/10/11.
*/ */
@ -49,7 +52,10 @@ public class LiveTextRender {
private static AbsoluteSizeSpan sFontSizeSpan; private static AbsoluteSizeSpan sFontSizeSpan;
private static AbsoluteSizeSpan sFontSizeSpan2; private static AbsoluteSizeSpan sFontSizeSpan2;
private static AbsoluteSizeSpan sFontSizeSpan3; private static AbsoluteSizeSpan sFontSizeSpan3;
private static Drawable mDrawableMedal, gzDrawables, ryxzDrawables, nhDrawables; private static final Map<LiveChatBean,Drawable> mDrawableMedalMap=new HashMap<>();
private static final Map<LiveChatBean,Drawable> gzDrawablesMap=new HashMap<>();
private static final Map<LiveChatBean,Drawable> ryxzDrawablesMap=new HashMap<>();
private static final Map<LiveChatBean,Drawable> nhDrawablesMap=new HashMap<>();
static { static {
sBoldSpan = new StyleSpan(Typeface.BOLD); sBoldSpan = new StyleSpan(Typeface.BOLD);
@ -195,24 +201,24 @@ public class LiveTextRender {
index += 2; index += 2;
} }
if (gzDrawables != null) {//贵族 if (gzDrawablesMap.containsKey(bean)) {//贵族
builder.append(" "); builder.append(" ");
gzDrawables.setBounds(0, 0, DpUtil.dp2px(32), DpUtil.dp2px(18)); gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(32), DpUtil.dp2px(18));
builder.setSpan(new VerticalImageSpan(gzDrawables), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index += 2; index += 2;
} }
if (ryxzDrawables != null) {//荣誉勋章 if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章
builder.append(" "); builder.append(" ");
ryxzDrawables.setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18));
builder.setSpan(new VerticalImageSpan(ryxzDrawables), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index += 2; index += 2;
} }
if (nhDrawables != null) {//靓号 if (nhDrawablesMap.containsKey(bean)) {//靓号
builder.append(" "); builder.append(" ");
nhDrawables.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(nhDrawables), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index += 2; index += 2;
} }
@ -276,9 +282,8 @@ public class LiveTextRender {
private static Drawable getMedalImage(final LiveChatBean bean) { private static Drawable getMedalImage(final LiveChatBean bean) {
View view = LayoutInflater.from(CommonAppContext.sInstance).inflate(R.layout.live_medal_icon, null, false); View view = LayoutInflater.from(CommonAppContext.sInstance).inflate(R.layout.live_medal_icon, null, false);
final ImageView iv = view.findViewById(R.id.ivIcon); final ImageView iv = view.findViewById(R.id.ivIcon);
if (mDrawableMedalMap.containsKey(bean))
if (mDrawableMedal != null) iv.setImageDrawable(mDrawableMedalMap.get(bean));
iv.setImageDrawable(mDrawableMedal);
TextView tv = view.findViewById(R.id.tvName); TextView tv = view.findViewById(R.id.tvName);
tv.setText(bean.getMedalNmae()); tv.setText(bean.getMedalNmae());
//字体加粗 //字体加粗
@ -303,7 +308,7 @@ public class LiveTextRender {
ImgLoader.displayDrawable(context, bean.getMedalLevelImageUrl(), new ImgLoader.DrawableCallback() { ImgLoader.displayDrawable(context, bean.getMedalLevelImageUrl(), new ImgLoader.DrawableCallback() {
@Override @Override
public void onLoadSuccess(Drawable drawable) { public void onLoadSuccess(Drawable drawable) {
mDrawableMedal = drawable; mDrawableMedalMap.put(bean, drawable);
gz(context, textView, bean); gz(context, textView, bean);
} }
@ -319,14 +324,12 @@ public class LiveTextRender {
ImgLoader.displayDrawable(context, bean.getMedal_honor(), new ImgLoader.DrawableCallback() { ImgLoader.displayDrawable(context, bean.getMedal_honor(), new ImgLoader.DrawableCallback() {
@Override @Override
public void onLoadSuccess(Drawable drawable) { public void onLoadSuccess(Drawable drawable) {
ryxzDrawables = null; ryxzDrawablesMap.put(bean,drawable);
ryxzDrawables = drawable;
nh(context, textView, bean); nh(context, textView, bean);
} }
@Override @Override
public void onLoadFailed() { public void onLoadFailed() {
ryxzDrawables = null;
nh(context, textView, bean); nh(context, textView, bean);
} }
}); });
@ -334,10 +337,9 @@ public class LiveTextRender {
public static void nh(final Context context, final TextView textView, final LiveChatBean bean) { public static void nh(final Context context, final TextView textView, final LiveChatBean bean) {
if (bean.getGood_nub() != null && !bean.getGood_nub().equals("")) { if (bean.getGood_nub() != null && !bean.getGood_nub().equals("")) {
nhDrawables = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.good_nub); nhDrawablesMap.put(bean,ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.good_nub));
renderTMP(context, textView, bean); renderTMP(context, textView, bean);
} else { } else {
nhDrawables = null;
renderTMP(context, textView, bean); renderTMP(context, textView, bean);
} }
} }
@ -346,14 +348,12 @@ public class LiveTextRender {
ImgLoader.displayDrawable(context, TextUtils.isEmpty(bean.getMedal_new()) ? bean.getMedal() : bean.getMedal_new(), new ImgLoader.DrawableCallback() { ImgLoader.displayDrawable(context, TextUtils.isEmpty(bean.getMedal_new()) ? bean.getMedal() : bean.getMedal_new(), new ImgLoader.DrawableCallback() {
@Override @Override
public void onLoadSuccess(Drawable drawable) { public void onLoadSuccess(Drawable drawable) {
gzDrawables = null; gzDrawablesMap.put(bean, drawable);
gzDrawables = drawable;
ryxz(context, textView, bean); ryxz(context, textView, bean);
} }
@Override @Override
public void onLoadFailed() { public void onLoadFailed() {
gzDrawables = null;
ryxz(context, textView, bean); ryxz(context, textView, bean);
} }
}); });
@ -490,7 +490,7 @@ public class LiveTextRender {
ImgLoader.displayDrawable(context, bean.getMedalLevelImageUrl(), new ImgLoader.DrawableCallback() { ImgLoader.displayDrawable(context, bean.getMedalLevelImageUrl(), new ImgLoader.DrawableCallback() {
@Override @Override
public void onLoadSuccess(Drawable drawable) { public void onLoadSuccess(Drawable drawable) {
mDrawableMedal = drawable; mDrawableMedalMap.put(bean, drawable);
renderEnterRoomTMP(context, textView, bean); renderEnterRoomTMP(context, textView, bean);
} }
@ -604,6 +604,11 @@ public class LiveTextRender {
builder.setSpan(sFontSizeSpan2, index1, index2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); builder.setSpan(sFontSizeSpan2, index1, index2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return builder; return builder;
} }
public static void clear(){
mDrawableMedalMap.clear();
gzDrawablesMap.clear();
ryxzDrawablesMap.clear();
nhDrawablesMap.clear();
}
} }