新增礼物合成公屏和房间飘屏

This commit is contained in:
huangjian
2022-08-05 16:11:38 +08:00
parent d2f749917e
commit ee0c6dd138
12 changed files with 207 additions and 16 deletions

Binary file not shown.

View File

@@ -1,7 +1,10 @@
package com.yizhuan.erban.avroom.widget;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_GIFT_COMPOUND;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_RED_PACKAGE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_BOX_ME;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_FANS_TEAM_JOIN;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_GIFT_COMPOUND;
import static com.yizhuan.xchat_android_core.redpackage.RedPackageTypeKt.ALL_DIAMOND;
import static com.yizhuan.xchat_android_core.redpackage.RedPackageTypeKt.ALL_GIFT;
import static com.yizhuan.xchat_android_core.redpackage.RedPackageTypeKt.ROOM_DIAMOND;
@@ -88,6 +91,8 @@ import com.yizhuan.xchat_android_core.im.custom.bean.FaceAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.FansTeamMsgAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.GiftAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.GiftBatchAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.GiftCompoundAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.GiftCompoundMsgBean;
import com.yizhuan.xchat_android_core.im.custom.bean.JoinMiniWorldAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.JoinMiniWorldNoticeAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.MagicAllMicAttachment;
@@ -963,6 +968,8 @@ public class MessageView extends FrameLayout {
setFansTeamMsg(chatRoomMessage, tvContent);
} else if (first == CustomAttachment.CUSTOM_MSG_LUCKY_GIFT) {
setLuckyGiftServerNotifyMsg(chatRoomMessage, tvContent);
} else if (first == CUSTOM_MSG_GIFT_COMPOUND) {
setGiftCompoundMsg(chatRoomMessage, tvContent);
} else {
tvContent.setTextColor(Color.WHITE);
tvContent.setText(tvContent.getResources().getText(R.string.not_support_message_tip));
@@ -976,26 +983,59 @@ public class MessageView extends FrameLayout {
}
}
@SuppressLint("CheckResult")
private void setGiftCompoundMsg(ChatRoomMessage chatRoomMessage, TextView tvContent) {
if (chatRoomMessage.getAttachment() instanceof GiftCompoundAttachment) {
GiftCompoundAttachment giftCompoundAttachment = (GiftCompoundAttachment) chatRoomMessage.getAttachment();
if (giftCompoundAttachment.getSecond() == CUSTOM_MSG_SUB_GIFT_COMPOUND) {
GiftCompoundMsgBean msgInfo = giftCompoundAttachment.getMsgBean();
SpannableBuilder text = new SpannableBuilder(tvContent);
text.append(
msgInfo.getNick(),
new ForegroundColorSpan(roomTipNickColor),
new OriginalDrawStatusClickSpan() {
@Override
public void onClick(@NonNull View widget) {
if (clickConsumer != null) {
Single.just(String.valueOf(msgInfo.getUid())).subscribe(clickConsumer);
}
}
}
)
.append(msgInfo.getMsg(), new ForegroundColorSpan(whiteColor))
.append(msgInfo.getGiftName(), new ForegroundColorSpan(roomTipNickColor));
tvContent.setText(text.build());
tvContent.setOnClickListener(null);
tvContent.setMovementMethod(new LinkMovementMethod());
}
} else {
tvContent.setTextColor(Color.WHITE);
tvContent.setText(tvContent.getResources().getText(R.string.not_support_message_tip));
}
}
@SuppressLint("CheckResult")
private void setFansTeamMsg(ChatRoomMessage chatRoomMessage, TextView tvContent) {
if (chatRoomMessage.getAttachment() instanceof FansTeamMsgAttachment) {
FansTeamMsgAttachment fansTeamMsgAttachment = (FansTeamMsgAttachment) chatRoomMessage.getAttachment();
FansTeamMsgInfo msgInfo = fansTeamMsgAttachment.getFansTeamMsgInfo();
SpannableBuilder text = new SpannableBuilder(tvContent);
text.append("欢迎", new ForegroundColorSpan(whiteColor))
.append(msgInfo.getNickname(), new ForegroundColorSpan(roomTipNickColor),
new OriginalDrawStatusClickSpan() {
@Override
public void onClick(@NonNull View widget) {
if (clickConsumer != null) {
Single.just(String.valueOf(msgInfo.getUid())).subscribe(clickConsumer);
if (fansTeamMsgAttachment.getSecond() == CUSTOM_MSG_SUB_FANS_TEAM_JOIN) {
FansTeamMsgInfo msgInfo = fansTeamMsgAttachment.getFansTeamMsgInfo();
SpannableBuilder text = new SpannableBuilder(tvContent);
text.append("欢迎", new ForegroundColorSpan(whiteColor))
.append(msgInfo.getNickname(), new ForegroundColorSpan(roomTipNickColor),
new OriginalDrawStatusClickSpan() {
@Override
public void onClick(@NonNull View widget) {
if (clickConsumer != null) {
Single.just(String.valueOf(msgInfo.getUid())).subscribe(clickConsumer);
}
}
}
})
.append("加入粉丝团", new ForegroundColorSpan(whiteColor));
tvContent.setText(text.build());
tvContent.setOnClickListener(null);
tvContent.setMovementMethod(new LinkMovementMethod());
})
.append("加入粉丝团", new ForegroundColorSpan(whiteColor));
tvContent.setText(text.build());
tvContent.setOnClickListener(null);
tvContent.setMovementMethod(new LinkMovementMethod());
}
} else {
tvContent.setTextColor(Color.WHITE);
tvContent.setText(tvContent.getResources().getText(R.string.not_support_message_tip));

View File

@@ -106,6 +106,9 @@ class RoomEffectView @JvmOverloads constructor(
private var disposableSingleRoomPK: Disposable? = null
private val messagesSingleRoomPK: MutableList<ChatRoomMessage> by lazy { ArrayList() }
private var disposableGiftCompound: Disposable? = null
private val messagesGiftCompound: MutableList<ChatRoomMessage> by lazy { ArrayList() }
private var isSvgaPlaying = false
private fun loopCarAnim() {
@@ -130,6 +133,7 @@ class RoomEffectView @JvmOverloads constructor(
RoomEvent.BOX_NOTIFY -> addBoxNotify(roomEvent.chatRoomMessage)
RoomEvent.DATING_ALL_NOTIFY -> addDatingAllNotify(roomEvent.chatRoomMessage)
RoomEvent.BOX_NOTIFY_SVGA -> addBoxNotifyBySVGA(roomEvent.chatRoomMessage)
RoomEvent.ROOM_GIFT_COMPOUND -> addGiftCompoundNotify(roomEvent.chatRoomMessage)
RoomEvent.RECEIVE_ROOM_LUCKY_BAG_NOTICE, RoomEvent.RECEIVE_SERVICE_LUCKY_BAG_NOTICE -> //全服福袋
//厅内福袋
addLuckyBagNotify(roomEvent.chatRoomMessage)
@@ -465,6 +469,85 @@ class RoomEffectView @JvmOverloads constructor(
}, null)
}
/**
* 礼物合成,带SVGA背景的消息
*
* @param chatRoomMessage
*/
private fun addGiftCompoundNotify(chatRoomMessage: ChatRoomMessage) {
if (binding.clNotify.visibility == GONE) {
binding.clNotify.visibility = VISIBLE
}
messagesGiftCompound.add(chatRoomMessage)
if (disposableGiftCompound == null || messagesGiftCompound.size == 1) {
disposableGiftCompound = Observable.interval(0, PERIOD.toLong(), TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.takeWhile { messagesGiftCompound.size > 0 }
.subscribe {
showGiftCompoundNotify(
messagesGiftCompound.removeAt(0)
)
}
}
}
private fun showGiftCompoundNotify(chatRoomMessage: ChatRoomMessage) {
val msgBean = (chatRoomMessage.attachment as GiftCompoundAttachment).msgBean
val text = SpannableBuilder()
.append(
msgBean.nick + " ",
ForegroundColorSpan(resources.getColor(R.color.notice_nick))
)
.append(msgBean.msg + " ", ForegroundColorSpan(Color.WHITE))
.append(
msgBean.giftName,
ForegroundColorSpan(resources.getColor(R.color.notice_nick))
)
val svgaImageView = SVGAImageView(mContext)
svgaImageView.loops = 1
svgaImageView.clearsAfterStop = true
val params = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
svgaImageView.layoutParams = params
svgaImageView.callback = object : SimpleSvgaCallback() {
override fun onFinished() {
binding.flGiftCompoundNotify.post {
binding.flGiftCompoundNotify.removeView(svgaImageView)
}
}
}
binding.flGiftCompoundNotify.addView(svgaImageView)
shareParser().decodeFromAssets(
"svga/gift_compound_notify.svga",
object : SVGAParser.ParseCompletion {
override fun onComplete(videoItem: SVGAVideoEntity) {
val dynamicEntity = SVGADynamicEntity()
val textPaint = TextPaint()
textPaint.color = Color.WHITE //字体颜色
textPaint.textSize = 24f //字体大小
dynamicEntity.setDynamicText(
StaticLayout(
text.build(),
0,
text.build().length,
textPaint,
0,
Layout.Alignment.ALIGN_CENTER,
1.0f,
0.0f,
false
), "noble_text_tx"
)
val drawable = SVGADrawable(videoItem, dynamicEntity)
svgaImageView.setImageDrawable(drawable)
svgaImageView.startAnimation()
}
override fun onError() {}
},
null
)
}
/**
* 成员进入飘屏
*
@@ -1037,6 +1120,7 @@ class RoomEffectView @JvmOverloads constructor(
disposableDatingAll?.dispose()
disposableRoomPK?.dispose()
disposableSingleRoomPK?.dispose()
disposableGiftCompound?.dispose()
}
}

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#1a000000" />
<solid android:color="#1aFF9CC3" />
<corners
android:radius="8dp" />
</shape>

View File

@@ -59,6 +59,13 @@
app:layout_constraintDimensionRatio="75:11"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/fl_gift_compound_notify"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintDimensionRatio="75:12"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/fl_svga_box_notify"
android:layout_width="match_parent"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 65 KiB

View File

@@ -1302,6 +1302,12 @@ public final class IMNetEaseManager {
noticeRoomEvent(msg, RoomEvent.ROOM_RANK_TOP_NOTIFY);
}
break;
case CUSTOM_MSG_GIFT_COMPOUND:
if (second == CUSTOM_MSG_SUB_GIFT_COMPOUND) {
noticeRoomEvent(msg, RoomEvent.ROOM_GIFT_COMPOUND);
addMessages(msg);
}
break;
default:
break;
}

View File

@@ -583,6 +583,9 @@ public class CustomAttachParser implements MsgAttachmentParser {
case CustomAttachment.CUSTOM_MSG_ROOM_RANK:
attachment = new RoomRankAttachment(second);
break;
case CustomAttachment.CUSTOM_MSG_GIFT_COMPOUND:
attachment = new GiftCompoundAttachment(second);
break;
default:
LogUtils.e("未定义的first,请现在CustomAttachParser中解析first=" + first + " second=" + second);
break;

View File

@@ -387,6 +387,10 @@ public class CustomAttachment implements MsgAttachment {
public static final int CUSTOM_MSG_ROOM_TASK_TIPS = 92;
public static final int CUSTOM_MSG_SUB_ROOM_TASK_TIPS = 921;
public static final int CUSTOM_MSG_GIFT_COMPOUND = 93;
public static final int CUSTOM_MSG_SUB_GIFT_COMPOUND = 931;
/**
* 自定义消息附件的类型,根据该字段区分不同的自定义消息
*/

View File

@@ -0,0 +1,31 @@
package com.yizhuan.xchat_android_core.im.custom.bean;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
public class GiftCompoundAttachment extends CustomAttachment {
private GiftCompoundMsgBean msgBean;
public GiftCompoundAttachment(int second) {
super(CUSTOM_MSG_GIFT_COMPOUND, second);
}
public GiftCompoundMsgBean getMsgBean() {
return msgBean;
}
public void setMsgBean(GiftCompoundMsgBean msgBean) {
this.msgBean = msgBean;
}
@Override
protected void parseData(JSONObject data) {
msgBean = new Gson().fromJson(data.toJSONString(), GiftCompoundMsgBean.class);
}
@Override
protected JSONObject packData() {
return null;
}
}

View File

@@ -0,0 +1,14 @@
package com.yizhuan.xchat_android_core.im.custom.bean;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class GiftCompoundMsgBean {
private long uid;
private String msg;
private String nick;
private String giftId;
private String giftName;
}

View File

@@ -235,6 +235,8 @@ public class RoomEvent {
public static final int ROOM_PK_ORDER = 92;
public static final int ROOM_GIFT_COMPOUND = 93;
private int event = NONE;
private int micPosition = Integer.MIN_VALUE;
private int posState = -1;