直播间推荐气泡文字

This commit is contained in:
18401019693
2022-09-19 13:43:18 +08:00
parent c95fd2d49c
commit 6fef3ee243
13 changed files with 164 additions and 15 deletions

View File

@@ -54,6 +54,7 @@ import com.yunbao.live.R;
import com.yunbao.live.adapter.VerticalPagerAdapter;
import com.yunbao.live.bean.ImUserBean;
import com.yunbao.live.bean.LiveBean;
import com.yunbao.live.bean.LiveChatBean;
import com.yunbao.live.dialog.LiveFansFragment;
import com.yunbao.live.dialog.LiveGiftDialogFragment;
import com.yunbao.live.dialog.LiveHDDialogFragment;
@@ -798,6 +799,14 @@ public class LiveAudienceActivity extends LiveActivity {
case TRUMPET_NOTIFY:
manager.showFullScreen(event.getMsgModel());
break;
case RECOMMEND_CARD_NOTIFY:
LiveChatBean chatBean = new LiveChatBean();
chatBean.setMsgModel(event.getMsgModel());
chatBean.setType(LiveChatBean.RECOMMEND_CARD_NOTIFY);
chatBean.setBubble(event.getMsgModel().getSystemBubble());
manager.onChat(chatBean, 1);
break;
}
@@ -857,7 +866,8 @@ public class LiveAudienceActivity extends LiveActivity {
/**
* 跳转当前页面
*/
public static void forward(Context context, LiveBean liveBean, int liveType, int liveTypeVal, String key, int position, int liveSdk) {
public static void forward(Context context, LiveBean liveBean, int liveType,
int liveTypeVal, String key, int position, int liveSdk) {
Intent intent = new Intent(context, LiveAudienceActivity.class);
intent.putExtra(Constants.LIVE_BEAN, liveBean);
intent.putExtra(Constants.LIVE_TYPE, liveType);

View File

@@ -37,12 +37,14 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.yunbao.live.bean.LiveChatBean.RECOMMEND_CARD_NOTIFY;
/**
* Created by cxf on 2018/10/10.
*/
public class LiveChatAdapter extends RecyclerView.Adapter {
public final static int MSG_HOUR_RANK_CHANGE=-100;//收到小时榜推送,发送一条弹幕
public final static int MSG_HOUR_RANK_CHANGE = -100;//收到小时榜推送,发送一条弹幕
private Context mContext;
private List<LiveChatBean> mList;
@@ -284,7 +286,7 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
} else if (bean.getType() == LiveChatBean.SYSTEM) {
boolean isContains = false;
for (LiveChatBean model : mList) {
if (!TextUtils.isEmpty(model.getContent())&&model.getContent().contains("堅決維護青少年群體精神文明健康")) {
if (!TextUtils.isEmpty(model.getContent()) && model.getContent().contains("堅決維護青少年群體精神文明健康")) {
isContains = true;
}
}
@@ -320,11 +322,15 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
mTextView.setText(R.string.automatic_chat);
bean.setHeart(position);
}
}else if(bean.getType()==MSG_HOUR_RANK_CHANGE){
mBg.setBackgroundResource(R.drawable.bg_chat_automatic_item);
mTextView.setText(bean.getContent());
bean.setHeart(position);
}else {
} else if (bean.getType() == MSG_HOUR_RANK_CHANGE) {
mBg.setBackgroundResource(R.drawable.bg_chat_automatic_item);
mTextView.setText(bean.getContent());
bean.setHeart(position);
} else if (bean.getType() == RECOMMEND_CARD_NOTIFY) {
//加载.9图聊天气泡
LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getBubble(), 1);
LiveTextRender.recommendCardNotify(mContext, mTextView, bean);
} else {
if (bean.getBubble() != null && !bean.getBubble().equals("")) {
//加载.9图聊天气泡
LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getBubble(), 1);

View File

@@ -1,6 +1,7 @@
package com.yunbao.live.bean;
import com.alibaba.fastjson.annotation.JSONField;
import com.yunbao.common.bean.MsgModel;
/**
* Created by cxf on 2017/8/22.
@@ -14,6 +15,7 @@ public class LiveChatBean {
public static final int ENTER_ROOM = 3;
public static final int LIGHT = 4;
public static final int RED_PACK = 5;
public static final int RECOMMEND_CARD_NOTIFY = 10;
private String id;
private String userNiceName;
@@ -37,6 +39,16 @@ public class LiveChatBean {
private String anchorName;
private String prankIcon;
private String hot_card;
private MsgModel msgModel = new MsgModel();//自定义消息体
public MsgModel getMsgModel() {
return msgModel;
}
public LiveChatBean setMsgModel(MsgModel msgModel) {
this.msgModel = msgModel;
return this;
}
public String getHot_card() {
return hot_card;

View File

@@ -129,7 +129,8 @@ public class LiveAudienceEvent extends BaseModel {
POPULAR(17, "人气票任务"),
NOTICE(18, "系统通知"),
ONLINE(19, "在线客服"),
TRUMPET_NOTIFY(20, "全服喇叭");
TRUMPET_NOTIFY(20, "全服喇叭"),
RECOMMEND_CARD_NOTIFY(21, "贵族推荐通知");
private int type;
private String name;

View File

@@ -459,6 +459,16 @@ public class SocketRyClient {
.setMsgModel(msg.get(0)));
}
break;
case Constants.RECOMMEND_CARD_NOTIFY://推荐卡消息通知
SocketModel recommendCardNotifyModel = GsonUtils.fromJson(socketMsg, SocketModel.class);
List<MsgModel> recommendCardNotifyMsg = recommendCardNotifyModel.getMsg();
if (recommendCardNotifyMsg.size() > 0) {
Bus.get().post(new LiveAudienceEvent()
.setType(LiveAudienceEvent.LiveAudienceType.RECOMMEND_CARD_NOTIFY)
.setMsgModel(recommendCardNotifyMsg.get(0)));
}
break;
}
}

View File

@@ -6,8 +6,8 @@ import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import androidx.core.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;
@@ -20,6 +20,8 @@ import android.view.View.MeasureSpec;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext;
import com.yunbao.common.Constants;
@@ -57,6 +59,38 @@ public class LiveTextRender {
sFontSizeSpan3 = new AbsoluteSizeSpan(14, true);
}
/**
* 直播间推荐卡
*
* @param textView
* @param bean
*/
public static void recommendCardNotify(Context context, TextView textView, LiveChatBean bean) {
String recommend;
Drawable drawable;
if (TextUtils.equals(bean.getMsgModel().getRecommendCardType(), "1")) {
recommend = context.getString(R.string.emperor_hint);
drawable = context.getResources().getDrawable(R.mipmap.emperor_rom);
} else {
recommend = context.getString(R.string.better_emperor_hint);
drawable = context.getResources().getDrawable(R.mipmap.super_emperor_rom);
}
String recommendCard = String.format(recommend, bean.getMsgModel().getUserName(), bean.getMsgModel().getAnchorName());
SpannableString spannableString = new SpannableString(recommendCard);
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#ffff00"));
ForegroundColorSpan colorSpan2 = new ForegroundColorSpan(Color.parseColor("#a1f3ff"));
//18 43
drawable.setBounds(0, 0, DpUtil.dp2px(46), DpUtil.dp2px(23));
//用这个drawable对象代替字符串easy
ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
//包括0但是不包括"easy".length()即4。[0,4)。值得注意的是当我们复制这个图片的时候,实际是复制了"easy"这个字符串。
spannableString.setSpan(span, recommendCard.indexOf("!") + 1, recommendCard.indexOf("!") + 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
spannableString.setSpan(colorSpan, spannableString.getSpanStart(span), spannableString.getSpanStart(span) + bean.getMsgModel().getUserName().length() + 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
spannableString.setSpan(colorSpan2, recommendCard.lastIndexOf(context.getString(R.string.anchor)) + 2, recommendCard.lastIndexOf(","), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
textView.setText(spannableString);
}
/**
* 生成前缀

View File

@@ -566,6 +566,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
@Override
public void onChat(LiveChatBean bean, int index) {
Log.e("LiveChatBean", GsonUtils.toJson(bean));
if (bean.getType() == 1) {
if (!bean.getContent().contains(mLiveBean.getUserNiceName())) {
return;

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB