修复一堆图标+10字名字聊天框没有图标问题

This commit is contained in:
zlzw 2024-06-03 15:02:03 +08:00
parent 5f3ebb4235
commit edc738d80b
2 changed files with 67 additions and 9 deletions

View File

@ -36,6 +36,9 @@ import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.enums.PopupPosition;
import com.lxj.xpopup.interfaces.XPopupCallback;
import com.lzf.easyfloat.EasyFloat;
import com.lzf.easyfloat.enums.ShowPattern;
import com.yunbao.common.dialog.DebugDialog;
import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.utils.MobclickAgent;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants;
@ -126,6 +129,7 @@ import com.yunbao.live.dialog.SignDialogFragment;
import com.yunbao.live.event.LinkMicTxAccEvent;
import com.yunbao.live.event.LiveAudienceEvent;
import com.yunbao.live.http.ImHttpUtil;
import com.yunbao.live.utils.LiveTextRender;
import com.yunbao.live.views.LiveRoomPlayViewHolder;
import com.yunbao.live.views.LiveRoomViewHolder;
import com.yunbao.live.views.PortraitLiveManager;
@ -225,6 +229,27 @@ public class LiveAudienceActivity extends LiveActivity {
fragment.show(((FragmentActivity) mContext).getSupportFragmentManager(), "YoursystemisolderDialog");
IMLoginManager.get(mContext).setXiaJBG(true);
}
/*new Handler(Looper.getMainLooper())
.postDelayed(new Runnable() {
@Override
public void run() {
System.out.println("------------------------初始化弹窗------------------------");
DebugDialog.getInstance(new DebugDialog.DebugDialogRunnable() {
@Override
public void run(DebugDialog dialog) {
System.out.println("------------------------显示弹窗------------------------");
dialog.setShowPattern(ShowPattern.ALL_TIME);
dialog.show();
LiveTextRender.onItemClickListener = new OnItemClickListener<String>() {
@Override
public void onItemClick(String bean, int position) {
dialog.setParams(bean.split("\\|")[0], bean.split("\\|")[1]);
}
};
}
});
}
},1000);*/
}
private final MicStatusManager.OnMicStatusListener onMicStatusListener = new MicStatusManager.OnMicStatusListener() {

View File

@ -32,13 +32,16 @@ import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.lzf.easyfloat.enums.ShowPattern;
import com.yunbao.common.CommonAppContext;
import com.yunbao.common.bean.AiAutomaticSpeechModel;
import com.yunbao.common.bean.MsgModel;
import com.yunbao.common.bean.NewGuardLevelModel;
import com.yunbao.common.bean.NewLevelModel;
import com.yunbao.common.custom.VerticalImageSpan;
import com.yunbao.common.dialog.DebugDialog;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.manager.NewLevelManager;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.StringUtil;
@ -84,6 +87,10 @@ public class LiveTextRender {
sFontSizeSpan = new AbsoluteSizeSpan(17, true);
sFontSizeSpan2 = new AbsoluteSizeSpan(12, true);
sFontSizeSpan3 = new AbsoluteSizeSpan(14, true);
if (!isInit) {
isInit = true;
}
}
public void blindBox(Context context, TextView textView, LiveChatBean bean) {
@ -285,7 +292,7 @@ public class LiveTextRender {
getGuardImage(CommonAppContext.sInstance, bean.getGuardType(), new ImgLoader.DrawableCallback() {
@Override
public void onLoadSuccess(Drawable drawable) {
SpannableStringBuilder builder = new SpannableStringBuilder();
/*SpannableStringBuilder builder = new SpannableStringBuilder();
int index = 0;
if (levelDrawable != null) {
@ -354,11 +361,16 @@ public class LiveTextRender {
index = builder.length();
}
}
createPrefixCallback.onPrefixCallback(builder, 0);
createPrefixCallback.onPrefixCallback(builder, 0);*/
show(drawable);
}
@Override
public void onLoadFailed() {
show(null);
}
void show(Drawable drawable) {
SpannableStringBuilder builder = new SpannableStringBuilder();
int index = 0;
int prefixWidth = 0;
@ -393,10 +405,17 @@ public class LiveTextRender {
index = builder.length();
prefixWidth += nhDrawablesMap.get(bean).getBounds().width();
}
if (drawable != null) {
builder.append(" ");
drawable.setBounds(0, 0, DpUtil.dp2px(34), DpUtil.dp2px(17));
builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length();
prefixWidth += drawable.getBounds().width();
}
//在这里添加粉丝徽章的图片
if (!TextUtils.isEmpty(bean.getMedalNmae()) && !TextUtils.isEmpty(bean.getMedalLevelImageUrl())
&& !bean.getMedalNmae().equals("null") && !bean.getMedalNmae().equals("(null)") && !bean.getMedalNmae().equals("<null>")) {//粉丝徽章图标
Drawable drawable = getMedalImage(bean);
drawable = getMedalImage(bean);
if (drawable != null) {
builder.append(" ");
drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17));
@ -408,23 +427,25 @@ public class LiveTextRender {
if (bean.isManager()) {//直播间管理员图标
Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m);
drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_m);
if (drawable != null) {
builder.append(" ");
drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14));
builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index = builder.length();
prefixWidth += drawable.getBounds().width();
}
}
if (!TextUtils.isEmpty(bean.getLiangName())) {//靓号图标
Drawable drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang);
drawable = ContextCompat.getDrawable(CommonAppContext.sInstance, R.mipmap.icon_live_chat_liang);
if (drawable != null) {
builder.append(" ");
drawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(14));
builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// new add
index = builder.length();
prefixWidth += drawable.getBounds().width();
}
}
createPrefixCallback.onPrefixCallback(builder, prefixWidth);
@ -811,6 +832,14 @@ public class LiveTextRender {
return mNewBitmap;
}
public static OnItemClickListener<String> onItemClickListener=new OnItemClickListener<String>() {
@Override
public void onItemClick(String bean, int position) {
}
};
private static boolean isInit = false;
/**
* 渲染普通聊天消息
*/
@ -824,21 +853,25 @@ public class LiveTextRender {
sb.append(builder).append(name).append(" ");
float measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth;
int width = ((ViewGroup) textView.getParent()).getWidth();
onItemClickListener.onItemClick("测算|" + measuredText, 0);
onItemClickListener.onItemClick("控件宽度|" + width, 0);
onItemClickListener.onItemClick("前缀预留宽度|" + prefixWidth, 0);
//检测渲染后图标+名字是否超过父布局宽度超过了就做换行处理
if (measuredText > width) {
sb.clear();
sb.append(builder);
for (int i = 0; i < name.length(); i++) {
sb.append(name.charAt(i)).append(" ");
sb.append(name.charAt(i));
measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth;
if (measuredText + 1 > width) {
name = name.substring(0, i+1) + "\n" + name.substring(i+1);
onItemClickListener.onItemClick(i + "逐测算|" + measuredText, 0);
if (measuredText > width) {
name = name.substring(0, i - 1) + "\n" + name.substring(i -1);
break;
}
}
sb.clear();
}
// name=name.substring(0,7)+"\n"+name.substring(7);
// name=name.substring(0,7)+"\n"+name.substring(7);
builder.append(name);
//超皇设置渐变色展示昵称
if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) {