直播间推荐气泡文字

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

@ -164,6 +164,7 @@ public class Constants {
public static final String SOCKET_PRIZE_POOL_WIN = "jackpotWin";//奖池中奖 public static final String SOCKET_PRIZE_POOL_WIN = "jackpotWin";//奖池中奖
public static final String SOCKET_PRIZE_POOL_UP = "jackpotUp";//奖池升级 public static final String SOCKET_PRIZE_POOL_UP = "jackpotUp";//奖池升级
public static final String SOCKET_HOUR = "SendHourChart";//小时榜更新 public static final String SOCKET_HOUR = "SendHourChart";//小时榜更新
public static final String RECOMMEND_CARD_NOTIFY = "recommendCardNotify";//推荐卡通知消息
//游戏socket //游戏socket
public static final String SOCKET_GAME_ZJH = "startGame";//炸金花 public static final String SOCKET_GAME_ZJH = "startGame";//炸金花

View File

@ -19,7 +19,7 @@ public class MsgModel extends BaseModel {
private String method = ""; private String method = "";
@SerializedName("user_id") @SerializedName("user_id")
private String userId = ""; private String userId = "";
@SerializedName("user_name") @SerializedName(value = "user_name", alternate = {"userName"})
private String userName = ""; private String userName = "";
@SerializedName("noble_id") @SerializedName("noble_id")
private String nobleId = ""; private String nobleId = "";
@ -28,6 +28,73 @@ public class MsgModel extends BaseModel {
@SerializedName("anchor_id") @SerializedName("anchor_id")
private String anchorId = ""; private String anchorId = "";
/**
* 推荐消息
* _method_ : recommendCardNotify
* action : 0
* msgtype : 1
* recommendCardType : 2
* userName : 哈哈哈
* anchorName : what-hap
* systemBubble : https://downs.yaoulive.com/20220721/1c5448119a159fcb154dd3fefe0a0f36.png
*/
@SerializedName("action")
private String action = "";
@SerializedName("msgtype")
private String msgtype = "";
@SerializedName("recommendCardType")
private String recommendCardType = "";
@SerializedName("anchorName")
private String anchorName = "";
@SerializedName("systemBubble")
private String systemBubble = "";
public String getAction() {
return action;
}
public MsgModel setAction(String action) {
this.action = action;
return this;
}
public String getMsgtype() {
return msgtype;
}
public MsgModel setMsgtype(String msgtype) {
this.msgtype = msgtype;
return this;
}
public String getRecommendCardType() {
return recommendCardType;
}
public MsgModel setRecommendCardType(String recommendCardType) {
this.recommendCardType = recommendCardType;
return this;
}
public String getAnchorName() {
return anchorName;
}
public MsgModel setAnchorName(String anchorName) {
this.anchorName = anchorName;
return this;
}
public String getSystemBubble() {
return systemBubble;
}
public MsgModel setSystemBubble(String systemBubble) {
this.systemBubble = systemBubble;
return this;
}
public String getMethod() { public String getMethod() {
return method; return method;
} }

View File

@ -126,11 +126,8 @@ public class ImgLoader {
} }
public static void displayDrawable(Context context, String url, final DrawableCallback callback) { public static void displayDrawable(Context context, String url, final DrawableCallback callback) {
if (!contextIsExist(context)) {
return; if (TextUtils.isEmpty(url)||!contextIsExist(context)) {
}
if (TextUtils.isEmpty(url)) {
if (callback != null) if (callback != null)
callback.onLoadFailed(); callback.onLoadFailed();
} else { } else {
@ -143,6 +140,13 @@ public class ImgLoader {
} }
} }
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
if (callback != null)
callback.onLoadFailed();
}
@Override @Override
public void onLoadCleared(@Nullable Drawable placeholder) { public void onLoadCleared(@Nullable Drawable placeholder) {

View File

@ -903,5 +903,8 @@
<string name="better_emperor">超皇</string> <string name="better_emperor">超皇</string>
<string name="can_not_go">無法前往神秘人的個人主頁。</string> <string name="can_not_go">無法前往神秘人的個人主頁。</string>
<string name="mystery_man">神秘人</string> <string name="mystery_man">神秘人</string>
<string name="tell_the_world">昭告天下!</string>
<string name="better_emperor_hint">昭告天下! %s 向所有人推薦了主播 %s , 一眼萬年情之所鐘!</string>
<string name="emperor_hint">昭告天下! %s 向所有人推薦了主播 %s , 灼灼風華一瞥驚鴻!</string>
</resources> </resources>

View File

@ -54,6 +54,7 @@ import com.yunbao.live.R;
import com.yunbao.live.adapter.VerticalPagerAdapter; import com.yunbao.live.adapter.VerticalPagerAdapter;
import com.yunbao.live.bean.ImUserBean; import com.yunbao.live.bean.ImUserBean;
import com.yunbao.live.bean.LiveBean; import com.yunbao.live.bean.LiveBean;
import com.yunbao.live.bean.LiveChatBean;
import com.yunbao.live.dialog.LiveFansFragment; import com.yunbao.live.dialog.LiveFansFragment;
import com.yunbao.live.dialog.LiveGiftDialogFragment; import com.yunbao.live.dialog.LiveGiftDialogFragment;
import com.yunbao.live.dialog.LiveHDDialogFragment; import com.yunbao.live.dialog.LiveHDDialogFragment;
@ -798,6 +799,14 @@ public class LiveAudienceActivity extends LiveActivity {
case TRUMPET_NOTIFY: case TRUMPET_NOTIFY:
manager.showFullScreen(event.getMsgModel()); manager.showFullScreen(event.getMsgModel());
break; 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 intent = new Intent(context, LiveAudienceActivity.class);
intent.putExtra(Constants.LIVE_BEAN, liveBean); intent.putExtra(Constants.LIVE_BEAN, liveBean);
intent.putExtra(Constants.LIVE_TYPE, liveType); intent.putExtra(Constants.LIVE_TYPE, liveType);

View File

@ -37,6 +37,8 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static com.yunbao.live.bean.LiveChatBean.RECOMMEND_CARD_NOTIFY;
/** /**
* Created by cxf on 2018/10/10. * Created by cxf on 2018/10/10.
*/ */
@ -324,6 +326,10 @@ public class LiveChatAdapter extends RecyclerView.Adapter {
mBg.setBackgroundResource(R.drawable.bg_chat_automatic_item); mBg.setBackgroundResource(R.drawable.bg_chat_automatic_item);
mTextView.setText(bean.getContent()); mTextView.setText(bean.getContent());
bean.setHeart(position); bean.setHeart(position);
} else if (bean.getType() == RECOMMEND_CARD_NOTIFY) {
//加载.9图聊天气泡
LoadDian9TuUtil.loadDian9Tu(mContext, mBg, bean.getBubble(), 1);
LiveTextRender.recommendCardNotify(mContext, mTextView, bean);
} else { } else {
if (bean.getBubble() != null && !bean.getBubble().equals("")) { if (bean.getBubble() != null && !bean.getBubble().equals("")) {
//加载.9图聊天气泡 //加载.9图聊天气泡

View File

@ -1,6 +1,7 @@
package com.yunbao.live.bean; package com.yunbao.live.bean;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.yunbao.common.bean.MsgModel;
/** /**
* Created by cxf on 2017/8/22. * 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 ENTER_ROOM = 3;
public static final int LIGHT = 4; public static final int LIGHT = 4;
public static final int RED_PACK = 5; public static final int RED_PACK = 5;
public static final int RECOMMEND_CARD_NOTIFY = 10;
private String id; private String id;
private String userNiceName; private String userNiceName;
@ -37,6 +39,16 @@ public class LiveChatBean {
private String anchorName; private String anchorName;
private String prankIcon; private String prankIcon;
private String hot_card; 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() { public String getHot_card() {
return hot_card; return hot_card;

View File

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

View File

@ -459,6 +459,16 @@ public class SocketRyClient {
.setMsgModel(msg.get(0))); .setMsgModel(msg.get(0)));
} }
break; 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.Typeface;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import androidx.core.content.ContextCompat;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan; import android.text.style.AbsoluteSizeSpan;
@ -20,6 +20,8 @@ import android.view.View.MeasureSpec;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.content.ContextCompat;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext; import com.yunbao.common.CommonAppContext;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
@ -57,6 +59,38 @@ public class LiveTextRender {
sFontSizeSpan3 = new AbsoluteSizeSpan(14, true); 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 @Override
public void onChat(LiveChatBean bean, int index) { public void onChat(LiveChatBean bean, int index) {
Log.e("LiveChatBean", GsonUtils.toJson(bean));
if (bean.getType() == 1) { if (bean.getType() == 1) {
if (!bean.getContent().contains(mLiveBean.getUserNiceName())) { if (!bean.getContent().contains(mLiveBean.getUserNiceName())) {
return; return;

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB