From 1b57d8bc8f7c265999f5bd55f38d0249355f2e2a Mon Sep 17 00:00:00 2001 From: Martin <13046765170@163.com> Date: Mon, 3 Jun 2024 15:41:29 +0800 Subject: [PATCH] =?UTF-8?q?fix[=E4=BF=AE=E5=A4=8DBUG]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/CommonAppConfig.java | 4 +- .../live/activity/LiveAudienceActivity.java | 25 ++++ .../com/yunbao/live/utils/LiveTextRender.java | 128 ++++++++++++++---- live/src/main/res/layout/item_live_chat.xml | 2 +- .../main/res/layout/view_live_pk_details.xml | 11 +- settings.gradle | 4 +- 6 files changed, 136 insertions(+), 38 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/CommonAppConfig.java b/common/src/main/java/com/yunbao/common/CommonAppConfig.java index 2536baf6c..fb294a2ef 100644 --- a/common/src/main/java/com/yunbao/common/CommonAppConfig.java +++ b/common/src/main/java/com/yunbao/common/CommonAppConfig.java @@ -80,9 +80,9 @@ public class CommonAppConfig { public static String SWToken = ""; //声网Token public static final String SWChannelPrefix = "g"; //测试服 - public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; + //public static final String SWAPPId = "4cf0376582d742ac8a96778b25b1079e"; //正式服 - //public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; + public static final String SWAPPId = "d4a5879524d74c20a7bdd667b0f2ca21"; diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 432b2ec9a..d0bfb97df 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -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; @@ -127,6 +130,7 @@ import com.yunbao.live.event.LinkMicTxAccEvent; import com.yunbao.live.event.LiveAudienceEvent; import com.yunbao.live.event.LiveOpenSuccessEvent; 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; @@ -227,6 +231,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() { + @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() { diff --git a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java index b220d8f07..c99006b84 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -21,6 +21,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.MeasureSpec; +import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; @@ -31,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; @@ -83,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) { @@ -263,7 +271,7 @@ public class LiveTextRender { } public interface CreatePrefixCallback { - void onPrefixCallback(SpannableStringBuilder builder); + void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth); } /** @@ -284,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) { @@ -353,19 +361,25 @@ public class LiveTextRender { index = builder.length(); } } - createPrefixCallback.onPrefixCallback(builder); + 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; if (levelDrawable != null) { builder.append(" "); levelDrawable.setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(levelDrawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += levelDrawable.getBounds().width(); } if (gzDrawablesMap.containsKey(bean)) {//贵族 @@ -373,6 +387,7 @@ public class LiveTextRender { gzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(35), DpUtil.dp2px(20)); builder.setSpan(new VerticalImageSpan(gzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += gzDrawablesMap.get(bean).getBounds().width(); } if (ryxzDrawablesMap.containsKey(bean)) {//荣誉勋章 @@ -380,6 +395,7 @@ public class LiveTextRender { ryxzDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(18), DpUtil.dp2px(18)); builder.setSpan(new VerticalImageSpan(ryxzDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += ryxzDrawablesMap.get(bean).getBounds().width(); } if (nhDrawablesMap.containsKey(bean)) {//靓号 @@ -387,41 +403,52 @@ public class LiveTextRender { nhDrawablesMap.get(bean).setBounds(0, 0, DpUtil.dp2px(17), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(nhDrawablesMap.get(bean)), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 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("")) {//粉丝徽章图标 - Drawable drawable = getMedalImage(bean); + drawable = getMedalImage(bean); if (drawable != null) { builder.append(" "); drawable.setBounds(0, 0, DpUtil.dp2px(44), DpUtil.dp2px(17)); builder.setSpan(new VerticalImageSpan(drawable), index, index + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); index = builder.length(); + prefixWidth += drawable.getBounds().width(); } } 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); + createPrefixCallback.onPrefixCallback(builder, prefixWidth); } }); @@ -515,9 +542,9 @@ public class LiveTextRender { } public void getGuardImage(Context mContext, int guardType, ImgLoader.DrawableCallback callback) { - if (guardType==0){ + if (guardType == 0) { callback.onLoadFailed(); - }else { + } else { if (mContext instanceof Activity) { if (((Activity) mContext).isDestroyed()) { mContext = CommonAppContext.getTopActivity(); @@ -684,7 +711,7 @@ public class LiveTextRender { createPrefix(drawable, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int color = Color.parseColor("#68F1F4"); if (bean.isAnchor()) { color = Color.parseColor("#FBEABF"); @@ -696,20 +723,20 @@ public class LiveTextRender { builder = renderGift(color, builder, bean); break; default: - builder = renderChat(color, builder, bean); + builder = renderChat(textView, color, builder, bean, prefixWidth); break; } textView.setText(builder); } }); - } + }// 123123123123123123123123 @Override public void onLoadFailed() { createPrefix(null, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int color = 0; if (bean.isAnchor()) { color = 0xffffdd00; @@ -721,7 +748,7 @@ public class LiveTextRender { builder = renderGift(color, builder, bean); break; default: - builder = renderChat(color, builder, bean); + builder = renderChat(textView, color, builder, bean, prefixWidth); break; } textView.setText(builder); @@ -805,15 +832,46 @@ public class LiveTextRender { return mNewBitmap; } + public static OnItemClickListener onItemClickListener=new OnItemClickListener() { + @Override + public void onItemClick(String bean, int position) { + + } + }; + private static boolean isInit = false; + /** * 渲染普通聊天消息 */ - private SpannableStringBuilder renderChat(int color, SpannableStringBuilder builder, LiveChatBean bean) { + private SpannableStringBuilder renderChat(TextView textView, int color, SpannableStringBuilder builder, LiveChatBean bean, int prefixWidth) { int length = builder.length(); String name = bean.getUserNiceName(); if (bean.getType() != LiveChatBean.ENTER_ROOM) {//产品规定,进场消息不允许加冒号 name += ":"; } + SpannableStringBuilder sb = new SpannableStringBuilder(); + 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)); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + 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); builder.append(name); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getStartColor())) { @@ -823,6 +881,24 @@ public class LiveTextRender { builder.setSpan(new ForegroundColorSpan(color), length, length + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } int lengthContent = builder.length(); + //这一段先别删,万一后面要改内容换行呢 + /* sb.clear(); + sb.append(builder).append(bean.getContent()); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText > width) { + sb.clear(); + sb.append(builder); + for (int i = 0; i < bean.getContent().length(); i++) { + sb.append(bean.getContent().charAt(i)); + measuredText = textView.getPaint().measureText(sb, 0, sb.length()) + prefixWidth; + if (measuredText + 3 > width) { + bean.setContent(bean.getContent().substring(0, i) + "\n"+ bean.getContent().substring(i)); + bean.setContent(""); + break; + } + } + } +*/ builder.append(bean.getContent()); //超皇设置渐变色展示昵称 if (TextUtils.equals("7", bean.getNobleId()) && !TextUtils.isEmpty(bean.getContentColor())) { @@ -889,7 +965,7 @@ public class LiveTextRender { if (textView != null) { createPrefix(drawable, bean, new CreatePrefixCallback() { @Override - public void onPrefixCallback(SpannableStringBuilder builder) { + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { int start = builder.length(); String name = bean.getUserNiceName() + " "; builder.append(name); @@ -904,15 +980,15 @@ public class LiveTextRender { @Override public void onLoadFailed() { if (textView != null) { - createPrefix(null, bean, new CreatePrefixCallback() { - @Override - public void onPrefixCallback(SpannableStringBuilder builder) { - int start = builder.length(); - String name = bean.getUserNiceName() + " "; - builder.append(name); - textView.setText(builder); - } - }); + createPrefix(null, bean, new CreatePrefixCallback() { + @Override + public void onPrefixCallback(SpannableStringBuilder builder, int prefixWidth) { + int start = builder.length(); + String name = bean.getUserNiceName() + " "; + builder.append(name); + textView.setText(builder); + } + }); } } diff --git a/live/src/main/res/layout/item_live_chat.xml b/live/src/main/res/layout/item_live_chat.xml index c4d360d8c..da2996682 100644 --- a/live/src/main/res/layout/item_live_chat.xml +++ b/live/src/main/res/layout/item_live_chat.xml @@ -10,7 +10,7 @@ @@ -17,7 +16,6 @@ android:layout_height="wrap_content" android:layout_marginStart="5.33dp" android:layout_marginTop="4.67dp" - android:background="@drawable/background_pk_time" android:gravity="center_vertical" android:orientation="horizontal"> @@ -61,9 +59,8 @@