From 447f8537f143d4b2b728dfe47f9b7fee7b83df97 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Tue, 11 Oct 2022 17:26:49 +0800 Subject: [PATCH] =?UTF-8?q?dian9=E5=9B=BE=E9=97=AE=E9=A2=98=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=97=B4=E8=81=8A=E5=A4=A9=E5=88=97=E8=A1=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yunbao/common/Constants.java | 1 + .../common/bean/AiAutomaticSpeechModel.java | 81 +++++++++++++++++++ .../live/activity/LiveAudienceActivity.java | 3 + .../yunbao/live/adapter/LiveChatAdapter.java | 4 + .../com/yunbao/live/bean/LiveChatBean.java | 13 +++ .../yunbao/live/event/LiveAudienceEvent.java | 15 +++- .../yunbao/live/socket/SocketRyClient.java | 8 ++ .../com/yunbao/live/utils/LiveTextRender.java | 2 +- .../yunbao/live/utils/LoadDian9TuUtil.java | 10 ++- .../yunbao/live/views/LiveRoomViewHolder.java | 20 ++++- .../live/views/PortraitLiveManager.java | 12 +++ 11 files changed, 162 insertions(+), 7 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java diff --git a/common/src/main/java/com/yunbao/common/Constants.java b/common/src/main/java/com/yunbao/common/Constants.java index c4faa9609..55259cf46 100644 --- a/common/src/main/java/com/yunbao/common/Constants.java +++ b/common/src/main/java/com/yunbao/common/Constants.java @@ -166,6 +166,7 @@ public class Constants { public static final String SOCKET_HOUR = "SendHourChart";//小时榜更新 public static final String RECOMMEND_CARD_NOTIFY = "recommendCardNotify";//推荐卡通知消息 public static final String STAR_CHALLENGE_UPDATE = "starChallengeUpdate";//星级助力 + public static final String AI_AUTOMATIC_SPEECH = "aiAutomaticSpeech";//机器人助手 //游戏socket public static final String SOCKET_GAME_ZJH = "startGame";//炸金花 diff --git a/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java b/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java new file mode 100644 index 000000000..b6b55f8ce --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/AiAutomaticSpeechModel.java @@ -0,0 +1,81 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; + +/** + * 机器人助手IM消息 + */ +public class AiAutomaticSpeechModel extends BaseModel { + //助手名字颜色 + @SerializedName("name_color") + private String nameColor; + //助手名字 + @SerializedName("ai_name") + private String aiName; + //说话内容 + @SerializedName("content") + private String content; + //被@用户名字 + @SerializedName("user_name") + private String userName; + //标签图片 + @SerializedName("icon") + private String icon; + //气泡背景 + @SerializedName("system_bubble") + private String systemBubble; + + public String getNameColor() { + return nameColor; + } + + public AiAutomaticSpeechModel setNameColor(String nameColor) { + this.nameColor = nameColor; + return this; + } + + public String getAiName() { + return aiName; + } + + public AiAutomaticSpeechModel setAiName(String aiName) { + this.aiName = aiName; + return this; + } + + public String getContent() { + return content; + } + + public AiAutomaticSpeechModel setContent(String content) { + this.content = content; + return this; + } + + public String getUserName() { + return userName; + } + + public AiAutomaticSpeechModel setUserName(String userName) { + this.userName = userName; + return this; + } + + public String getIcon() { + return icon; + } + + public AiAutomaticSpeechModel setIcon(String icon) { + this.icon = icon; + return this; + } + + public String getSystemBubble() { + return systemBubble; + } + + public AiAutomaticSpeechModel setSystemBubble(String systemBubble) { + this.systemBubble = systemBubble; + return this; + } +} 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 f678ae668..357db4ad4 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -846,6 +846,9 @@ public class LiveAudienceActivity extends LiveActivity { case START_MESSAGE: manager.starMessage(event.getMsgModel()); break; + case AI_AUTOMATIC_SPEECH: + manager.aiAutomaticSpeech(event.getAiAutomaticSpeechModel()); + break; } diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java index 17c3656d7..63a8f469d 100644 --- a/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java +++ b/live/src/main/java/com/yunbao/live/adapter/LiveChatAdapter.java @@ -1,5 +1,6 @@ package com.yunbao.live.adapter; +import static com.yunbao.live.bean.LiveChatBean.AI_AUTOMATIC_SPEECH; import static com.yunbao.live.bean.LiveChatBean.RECOMMEND_CARD_NOTIFY; import android.annotation.SuppressLint; @@ -331,6 +332,9 @@ public class LiveChatAdapter extends RecyclerView.Adapter { //加载.9图聊天气泡 LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getBubble(), 1); LiveTextRender.recommendCardNotify(mContext, mTextView, bean); + } else if (bean.getType() == AI_AUTOMATIC_SPEECH) { + //加载.9图聊天气泡 + LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getAiAutomaticSpeechModel().getSystemBubble(), 1); } else { if (bean.getBubble() != null && !bean.getBubble().equals("")) { //加载.9图聊天气泡 diff --git a/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java b/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java index c6b55e3a6..69a2df8ad 100644 --- a/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java +++ b/live/src/main/java/com/yunbao/live/bean/LiveChatBean.java @@ -2,6 +2,7 @@ package com.yunbao.live.bean; import com.alibaba.fastjson.annotation.JSONField; import com.google.gson.annotations.SerializedName; +import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.MsgModel; /** @@ -17,6 +18,7 @@ public class LiveChatBean { public static final int LIGHT = 4; public static final int RED_PACK = 5; public static final int RECOMMEND_CARD_NOTIFY = 10; + public static final int AI_AUTOMATIC_SPEECH = 101; private String id; private String userNiceName; @@ -41,6 +43,17 @@ public class LiveChatBean { private String prankIcon; private String hot_card; private MsgModel msgModel = new MsgModel();//自定义消息体 + private AiAutomaticSpeechModel aiAutomaticSpeechModel = new AiAutomaticSpeechModel();//机器人消息体 + + public AiAutomaticSpeechModel getAiAutomaticSpeechModel() { + return aiAutomaticSpeechModel; + } + + public LiveChatBean setAiAutomaticSpeechModel(AiAutomaticSpeechModel aiAutomaticSpeechModel) { + this.aiAutomaticSpeechModel = aiAutomaticSpeechModel; + return this; + } + @SerializedName("noble_id") private String nobleId = ""; diff --git a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java index b010559ef..f3f74f899 100644 --- a/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java +++ b/live/src/main/java/com/yunbao/live/event/LiveAudienceEvent.java @@ -1,6 +1,7 @@ package com.yunbao.live.event; import com.yunbao.common.bean.ActiveModel; +import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.AnchorRecommendItemModel; import com.yunbao.common.bean.BaseModel; import com.yunbao.common.bean.MsgModel; @@ -18,6 +19,16 @@ public class LiveAudienceEvent extends BaseModel { private int liveType; private int liveTypeVal; private MsgModel msgModel;//全服消息 + private AiAutomaticSpeechModel aiAutomaticSpeechModel;//机器人消息 + + public AiAutomaticSpeechModel getAiAutomaticSpeechModel() { + return aiAutomaticSpeechModel; + } + + public LiveAudienceEvent setAiAutomaticSpeechModel(AiAutomaticSpeechModel aiAutomaticSpeechModel) { + this.aiAutomaticSpeechModel = aiAutomaticSpeechModel; + return this; + } public MsgModel getMsgModel() { return msgModel; @@ -134,7 +145,9 @@ public class LiveAudienceEvent extends BaseModel { SLIDE_SETTINGS(22, "滑動設置"), NEW_MESSAGE_REMINDER(23, "新消息提醒"), AT_MESSAGE(24, "@消息"), - START_MESSAGE(25, "星级消息"); + START_MESSAGE(25, "星级消息"), + AI_AUTOMATIC_SPEECH(26, "机器人助手"), + ; private int type; private String name; diff --git a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java index ae4e1894e..56ca5b216 100644 --- a/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java +++ b/live/src/main/java/com/yunbao/live/socket/SocketRyClient.java @@ -21,6 +21,7 @@ import com.blankj.utilcode.util.GsonUtils; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; +import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.FansMedalBean; import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.SocketModel; @@ -480,6 +481,13 @@ public class SocketRyClient { .setMsgModel(starChallengeMsg.get(0))); } break; + case Constants.AI_AUTOMATIC_SPEECH: + //{"name_color":"#f19ec2","ai_name":"助手小小P","content":"@1 ","user_name":"1","icon":"https://downs.yaoulive.com/xzs_tab.png","system_bubble":"https://downs.yaoulive.com/xzs_qipao.9.png"} + AiAutomaticSpeechModel aiAutomaticSpeechModel = GsonUtils.fromJson(map.getString("ct"), AiAutomaticSpeechModel.class); + Bus.get().post(new LiveAudienceEvent() + .setType(LiveAudienceEvent.LiveAudienceType.AI_AUTOMATIC_SPEECH) + .setAiAutomaticSpeechModel(aiAutomaticSpeechModel)); + break; } } 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 062a0021b..13ef5c17f 100644 --- a/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java +++ b/live/src/main/java/com/yunbao/live/utils/LiveTextRender.java @@ -254,7 +254,7 @@ public class LiveTextRender { } public static void gz(final Context context, final TextView textView, final LiveChatBean bean) { - ImgLoader.displayDrawable(context, bean.getMedal_new(), new ImgLoader.DrawableCallback() { + ImgLoader.displayDrawable(context, TextUtils.isEmpty(bean.getMedal_new())?bean.getMedal():bean.getMedal_new(), new ImgLoader.DrawableCallback() { @Override public void onLoadSuccess(Drawable drawable) { gzDrawables = null; diff --git a/live/src/main/java/com/yunbao/live/utils/LoadDian9TuUtil.java b/live/src/main/java/com/yunbao/live/utils/LoadDian9TuUtil.java index 47d5afe5e..d2e3275b3 100644 --- a/live/src/main/java/com/yunbao/live/utils/LoadDian9TuUtil.java +++ b/live/src/main/java/com/yunbao/live/utils/LoadDian9TuUtil.java @@ -33,13 +33,15 @@ public class LoadDian9TuUtil { } } Glide.with(context) - .asBitmap() + .asFile() .load(imgUrl) - .into(new CustomTarget() { + .into(new CustomTarget() { @Override - public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + public void onResourceReady(@NonNull File resource, @Nullable Transition transition) { try { - setNinePathImage(context, imageView, resource, position); + FileInputStream is = new FileInputStream(resource); + setNinePathImage(context, imageView, BitmapFactory.decodeStream(is), position); + } catch (Exception e) { e.printStackTrace(); } diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java index ac098ad44..4c6ef59ed 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java @@ -60,6 +60,7 @@ import com.opensource.svgaplayer.SVGAVideoEntity; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.Constants; import com.yunbao.common.activity.AbsActivity; +import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.BannerBean; import com.yunbao.common.bean.HourRank; import com.yunbao.common.bean.IMLoginModel; @@ -815,7 +816,9 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis mChatRecyclerView.setLayoutParams(params1); mChatRecyclerView.setHasFixedSize(true); - mChatRecyclerView.setLayoutManager(new LinearLayoutManager(mContext)); + LinearLayoutManager layoutManager = new LinearLayoutManager(mContext); + layoutManager.setStackFromEnd(true); + mChatRecyclerView.setLayoutManager(layoutManager); mChatRecyclerView.addItemDecoration(new TopGradual()); mLiveChatAdapter = new LiveChatAdapter(mContext); mLiveChatAdapter.setOnItemClickListener(new OnItemClickListener() { @@ -3251,4 +3254,19 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis }, 100); } + + /** + * 机器人消息 + * + * @param model + */ + public void aiAutomaticSpeech(AiAutomaticSpeechModel model) { + if (mLiveChatAdapter != null){ + LiveChatBean bean = new LiveChatBean(); + bean.setType(LiveChatBean.AI_AUTOMATIC_SPEECH); + bean.setAiAutomaticSpeechModel(model); + mLiveChatAdapter.insertItem(bean); + } + + } } diff --git a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java index ecfdb0ca4..79dcfe30d 100644 --- a/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java +++ b/live/src/main/java/com/yunbao/live/views/PortraitLiveManager.java @@ -36,6 +36,7 @@ import com.tencent.imsdk.v2.V2TIMManager; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; +import com.yunbao.common.bean.AiAutomaticSpeechModel; import com.yunbao.common.bean.MsgModel; import com.yunbao.common.bean.StarChallengeStatusModel; import com.yunbao.common.bean.UserBean; @@ -1579,4 +1580,15 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe .setCurrentAssistNum(msgModel.getCurrentAssistNum())); } } + + /** + * 机器人消息 + * + * @param model + */ + public void aiAutomaticSpeech(AiAutomaticSpeechModel model) { + if (mLiveRoomViewHolder != null) { + mLiveRoomViewHolder.aiAutomaticSpeech(model); + } + } }