新增 H5活动通用飘屏

This commit is contained in:
wzq
2023-09-18 15:32:52 +08:00
parent 873ecf1d2b
commit c631c1d3a8
11 changed files with 346 additions and 163 deletions

Binary file not shown.

View File

@@ -99,6 +99,7 @@ import com.yizhuan.xchat_android_core.gift.bean.GiftInfo;
import com.yizhuan.xchat_android_core.gift.bean.LuckyBagNoticeInfo;
import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.FairyMsgAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.NotifyH5Attachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomBoxPrizeAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomBoxPrizeInfo;
import com.yizhuan.xchat_android_core.im.custom.bean.RoomLuckySeaAttachment;
@@ -1260,6 +1261,19 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
.setChatRoomMessage(message));
}
break;
case CustomAttachment.CUSTOM_MSG_NOTIFY_H5:
if (baseProtocol.getSecond() == CustomAttachment.CUSTOM_MSG_NOTIFY_H5_SUB_WHOLE_SERVICE) {
NotifyH5Attachment.Bean bean = JSON.parseObject(String.valueOf(baseProtocol.getData()), NotifyH5Attachment.Bean.class);
NotifyH5Attachment notifyH5Attachment = new NotifyH5Attachment(baseProtocol.getSecond());
notifyH5Attachment.setBean(bean);
ChatRoomMessage notifyH5Msg = ChatRoomMessageBuilder.createChatRoomCustomMessage(
String.valueOf(AvRoomDataManager.get().getRoomId()), notifyH5Attachment);
IMNetEaseManager.get().getChatRoomEventObservable()
.onNext(new RoomEvent()
.setEvent(RoomEvent.NOTIFY_H5)
.setChatRoomMessage(notifyH5Msg));
}
break;
case CUSTOM_MSG_LUCKY_SEA://星级厨房
if (baseProtocol.getSecond() == CUSTOM_MSG_LUCKY_SEA_GIFT_SERVER_ALL) {
RoomLuckySeaAttachment attachment = new RoomLuckySeaAttachment(CUSTOM_MSG_LUCKY_SEA, CUSTOM_MSG_LUCKY_SEA_GIFT_SERVER_ALL);

View File

@@ -32,7 +32,6 @@ import com.yizhuan.erban.avroom.activity.AVRoomActivity
import com.yizhuan.erban.avroom.bean.RoomPlayBean
import com.yizhuan.erban.avroom.helper.AnimHelper
import com.yizhuan.erban.common.svga.SimpleSvgaCallback
import com.yizhuan.erban.databinding.LayoutNotifyTarotIntermediateBinding
import com.yizhuan.erban.databinding.LayoutRoomEffectBinding
import com.yizhuan.erban.ui.utils.ImageLoadUtils
import com.yizhuan.erban.ui.utils.isDestroyed
@@ -178,6 +177,10 @@ class RoomEffectView @JvmOverloads constructor(
addPlayNotify(roomEvent.event, roomEvent.chatRoomMessage)
}
RoomEvent.NOTIFY_H5 -> {
addPlayNotify(roomEvent.event, roomEvent.chatRoomMessage)
}
RoomEvent.RECEIVE_ROOM_LUCKY_BAG_NOTICE, RoomEvent.RECEIVE_SERVICE_LUCKY_BAG_NOTICE ->//全服福袋
//廳內福袋
addPlayNotify(roomEvent.event, roomEvent.chatRoomMessage)
@@ -278,167 +281,195 @@ class RoomEffectView @JvmOverloads constructor(
.observeOn(AndroidSchedulers.mainThread())
.takeWhile { messagesPlay.size > 0 && !mContext.isDestroyed() }
.subscribe {
if (binding.flPlayNotify.childCount == 0) {
when (messagesPlay[0].event) {
RoomEvent.BOX_NOTIFY -> {//寻爱
if ((mContext as AVRoomActivity).isTopActivity) {
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 180.0),
0,
0
)
} else {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 60.0),
0,
0
)
}
showBoxNotify(
messagesPlay.removeAt(0)
if (binding.flPlayNotify.childCount != 0) {
return@subscribe
}
when (messagesPlay[0].event) {
RoomEvent.BOX_NOTIFY -> {//寻爱
if ((mContext as AVRoomActivity).isTopActivity) {
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 180.0),
0,
0
)
} else {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 60.0),
0,
0
)
}
showBoxNotify(
messagesPlay.removeAt(0)
)
}
}
RoomEvent.BOX_NOTIFY_SVGA -> {//寻爱
if ((mContext as AVRoomActivity).isTopActivity) {
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 180.0),
0,
0
)
} else {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 60.0),
0,
0
)
}
showBoxNotifyBySVGA(messagesPlay.removeAt(0))
}
}
RoomEvent.TAROT_NOTIFY -> {
if ((mContext as AVRoomActivity).isTopActivity) {
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 180.0),
0,
0
)
} else {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 60.0),
0,
0
)
}
showTarotNotify(
messagesPlay.removeAt(0)
RoomEvent.BOX_NOTIFY_SVGA -> {//寻爱
if ((mContext as AVRoomActivity).isTopActivity) {
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 180.0),
0,
0
)
} else {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 60.0),
0,
0
)
}
showBoxNotifyBySVGA(messagesPlay.removeAt(0))
}
}
RoomEvent.TAROT_NOTIFY_SVGA -> {
if ((mContext as AVRoomActivity).isTopActivity) {
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 180.0),
0,
0
)
} else {
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 60.0),
0,
0
)
}
showTarotNotifyBySVGA(messagesPlay.removeAt(0))
}
}
RoomEvent.RECEIVE_ROOM_LUCKY_BAG_NOTICE, RoomEvent.RECEIVE_SERVICE_LUCKY_BAG_NOTICE -> {//福袋
RoomEvent.TAROT_NOTIFY -> {
if ((mContext as AVRoomActivity).isTopActivity) {
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 180.0), 0, 0)
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 180.0),
0,
0
)
} else {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 60.0), 0, 0)
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 60.0),
0,
0
)
}
showLuckyBagNotify(
showTarotNotify(
messagesPlay.removeAt(0)
)
}
}
RoomEvent.LUCKY_SEA_GIFT_ROOM_NOTIFY -> {//星级厨房
RoomEvent.TAROT_NOTIFY_SVGA -> {
if ((mContext as AVRoomActivity).isTopActivity) {
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 180.0), 0, 0)
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 180.0),
0,
0
)
} else {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 60.0), 0, 0)
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, 60.0),
0,
0
)
}
showLuckySeaNotify(
messagesPlay.removeAt(0)
)
showTarotNotifyBySVGA(messagesPlay.removeAt(0))
}
}
RoomEvent.NOTIFY_H5 -> {
if (!(mContext as AVRoomActivity).isTopActivity) {
return@subscribe
}
RoomEvent.LUCKY_SEA_GIFT_SERVER_NOTIFY -> {//星级厨房
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 180.0), 0, 0)
} else {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 60.0), 0, 0)
}
showLuckySeaNotifyBySVGA(
messagesPlay.removeAt(0)
)
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
margin(
binding.clNotify,
0,
UIUtil.dip2px(context, if (isPlay) 180.0 else 60.0),
0,
0
)
val msg = messagesPlay.removeAt(0)
val attachment = msg.chatRoomMessage.attachment as NotifyH5Attachment
val bean = attachment.bean ?: return@subscribe
if (bean.floatingType == 0) {
showNotifyH5(bean)
} else {
showNotifyH5WithAnim(bean)
}
RoomEvent.FAIRY_DRAW_GIFT_L4,
RoomEvent.FAIRY_DRAW_GIFT_L5,
RoomEvent.FAIRY_CONVERT_L1,
RoomEvent.FAIRY_CONVERT_L2,
RoomEvent.FAIRY_CONVERT_L3 -> {//夺宝
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 180.0), 0, 0)
} else {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 60.0), 0, 0)
}
showFairyNotify(
messagesPlay.removeAt(0)
)
}
RoomEvent.RECEIVE_ROOM_LUCKY_BAG_NOTICE, RoomEvent.RECEIVE_SERVICE_LUCKY_BAG_NOTICE -> {//福袋
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 180.0), 0, 0)
} else {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 60.0), 0, 0)
}
showLuckyBagNotify(
messagesPlay.removeAt(0)
)
}
RoomEvent.LUCKY_SEA_GIFT_ROOM_NOTIFY -> {//星级厨房
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 180.0), 0, 0)
} else {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 60.0), 0, 0)
}
showLuckySeaNotify(
messagesPlay.removeAt(0)
)
}
RoomEvent.LUCKY_SEA_GIFT_SERVER_NOTIFY -> {//星级厨房
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 180.0), 0, 0)
} else {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 60.0), 0, 0)
}
showLuckySeaNotifyBySVGA(
messagesPlay.removeAt(0)
)
}
RoomEvent.FAIRY_DRAW_GIFT_L4,
RoomEvent.FAIRY_DRAW_GIFT_L5,
RoomEvent.FAIRY_CONVERT_L1,
RoomEvent.FAIRY_CONVERT_L2,
RoomEvent.FAIRY_CONVERT_L3 -> {//夺宝
isPlayAnim = true
val isPlay = onPlayAnimCallback?.invoke() ?: false
if (isPlay) {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 180.0), 0, 0)
} else {
margin(binding.clNotify, 0, UIUtil.dip2px(context, 60.0), 0, 0)
}
showFairyNotify(
messagesPlay.removeAt(0)
)
}
}
}
@@ -839,11 +870,80 @@ class RoomEffectView @JvmOverloads constructor(
)
}
private fun showNotifyH5(data: NotifyH5Attachment.Bean) {
val textView = LayoutInflater.from(mContext)
.inflate(R.layout.layout_notify_h5, null) as TextView
textView.text = data.content
animationPlay = AnimationUtils.loadAnimation(mContext, R.anim.anim_box_notify)
binding.flPlayNotify.addView(textView)
textView.startAnimation(animationPlay)
binding.flPlayNotify.postDelayed(
{
animationPlay = AnimationUtils.loadAnimation(mContext, R.anim.anim_box_notify_close)
textView.startAnimation(animationPlay)
},
SHOW_TIME.toLong()
)
binding.flPlayNotify.postDelayed({
binding.flPlayNotify.removeView(textView)
isPlayAnim = false
}, CLOSE_TIME.toLong())
}
private fun showNotifyH5WithAnim(data: NotifyH5Attachment.Bean) {
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.flPlayNotify.post {
binding.flPlayNotify.removeView(svgaImageView)
isPlayAnim = false
}
}
}
binding.flPlayNotify.addView(svgaImageView)
shareParser().decodeFromAssets(
"svga/svga_notify_h5.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(
data.content,
0,
data.content.length,
textPaint,
0,
Layout.Alignment.ALIGN_CENTER,
1.0f,
0.0f,
false
), "bg"
)
val drawable = SVGADrawable(videoItem, dynamicEntity)
svgaImageView.setImageDrawable(drawable)
svgaImageView.stepToFrame(0, true)
}
override fun onError() {}
},
null
)
}
private fun showTarotNotify(roomPlayBean: RoomPlayBean) {
val chatRoomMessage = roomPlayBean.chatRoomMessage
val attachment = chatRoomMessage.attachment as TarotAttachment
val textView =
LayoutInflater.from(mContext).inflate(R.layout.layout_notify_tarot_intermediate, null) as TextView
LayoutInflater.from(mContext)
.inflate(R.layout.layout_notify_tarot_intermediate, null) as TextView
val string = mContext.getString(
R.string.avroom_widget_roomeffectview_026,
StringUtils.abbreviate(RegexUtil.getPrintableString(attachment.tarotMsgBean.nick), 8),
@@ -933,32 +1033,36 @@ class RoomEffectView @JvmOverloads constructor(
}
}
binding.flPlayNotify.addView(svgaImageView)
shareParser().decodeFromAssets("svga/svga_tarot_senior.svga", object : SVGAParser.ParseCompletion {
override fun onComplete(videoItem: SVGAVideoEntity) {
val dynamicEntity = SVGADynamicEntity()
val textPaint = TextPaint()
textPaint.color = Color.WHITE //字體顏色
textPaint.textSize = 22f
dynamicEntity.setDynamicText(
StaticLayout(
text,
0,
text.length,
textPaint,
0,
Layout.Alignment.ALIGN_CENTER,
1.0f,
0.0f,
false
), "taxt"
)
val drawable = SVGADrawable(videoItem, dynamicEntity)
svgaImageView.setImageDrawable(drawable)
svgaImageView.stepToFrame(0, true)
}
shareParser().decodeFromAssets(
"svga/svga_tarot_senior.svga",
object : SVGAParser.ParseCompletion {
override fun onComplete(videoItem: SVGAVideoEntity) {
val dynamicEntity = SVGADynamicEntity()
val textPaint = TextPaint()
textPaint.color = Color.WHITE //字體顏色
textPaint.textSize = 22f
dynamicEntity.setDynamicText(
StaticLayout(
text,
0,
text.length,
textPaint,
0,
Layout.Alignment.ALIGN_CENTER,
1.0f,
0.0f,
false
), "taxt"
)
val drawable = SVGADrawable(videoItem, dynamicEntity)
svgaImageView.setImageDrawable(drawable)
svgaImageView.stepToFrame(0, true)
}
override fun onError() {}
}, null)
override fun onError() {}
},
null
)
}
private fun showBoxNotifyBySVGA(roomPlayBean: RoomPlayBean) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<com.coorchice.library.SuperTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="@drawable/bg_notify_h5"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingStart="@dimen/dp_50"
android:paddingEnd="0dp"
android:textColor="@color/white"
android:textSize="11sp"
tools:layout_height="wrap_content"
tools:text="@string/avroom_widget_roomeffectview_026" />

View File

@@ -97,7 +97,6 @@
android:layout_height="20dp"
android:layout_marginStart="@dimen/dp_4"
android:layout_marginTop="@dimen/dp_4"
android:onClick="@{click}"
android:src="@drawable/treasure_box_sub_normal" />
<EditText
@@ -120,7 +119,6 @@
android:layout_height="20dp"
android:layout_marginTop="@dimen/dp_4"
android:layout_marginEnd="@dimen/dp_2"
android:onClick="@{click}"
android:src="@drawable/treasure_box_add_normal" />
</LinearLayout>

View File

@@ -1360,6 +1360,8 @@ public final class IMNetEaseManager {
|| second == CUSTOM_MESS_TAROT_SENIOR_PRIZE_WINNING) {
noticeTarot(msg, second);
}
case CUSTOM_MSG_NOTIFY_H5:
noticeH5(msg);
default:
break;
}
@@ -3338,6 +3340,13 @@ public final class IMNetEaseManager {
.setChatRoomMessage(msg));
}
private void noticeH5(ChatRoomMessage msg) {
getChatRoomEventObservable()
.onNext(new RoomEvent()
.setEvent(RoomEvent.NOTIFY_H5)
.setChatRoomMessage(msg));
}
private void noticeRadish(ChatRoomMessage msg, int second) {
int event = second == CUSTOM_MSG_SUB_RADISH_ALL_ROOM_NOTIFY ? RoomEvent.RADISH_NOTIFY : RoomEvent.RADISH_NOTIFY_SVGA;
getChatRoomEventObservable()

View File

@@ -643,6 +643,9 @@ public class CustomAttachParser implements MsgAttachmentParser {
attachment = new FairyMsgAttachment(first, second);
}
break;
case CustomAttachment.CUSTOM_MSG_NOTIFY_H5:
attachment = new NotifyH5Attachment(second);
break;
default:
LogUtils.e(ResUtil.getString(R.string.custom_bean_customattachparser_01) + first + " second=" + second);
break;

View File

@@ -453,6 +453,21 @@ public class CustomAttachment implements MsgAttachment {
public static final int CUSTOM_MSG_SUB_CONVERT_L2 = 9732; // 召唤L2
public static final int CUSTOM_MSG_SUB_CONVERT_L3 = 9733; // 召唤L3
/**
* H5活动通用飘屏
*/
public static final int CUSTOM_MSG_NOTIFY_H5 = 100;
/**
* H5活动通用飘屏 - 房间
*/
public static final int CUSTOM_MSG_NOTIFY_H5_SUB_ROOM = 1001;
/**
* H5活动通用飘屏 - 全服
*/
public static final int CUSTOM_MSG_NOTIFY_H5_SUB_WHOLE_SERVICE = 1002;
/**
* 自定义消息附件的类型,根据该字段区分不同的自定义消息
*/

View File

@@ -0,0 +1,22 @@
package com.yizhuan.xchat_android_core.im.custom.bean
import com.alibaba.fastjson.JSONObject
import com.google.gson.Gson
class NotifyH5Attachment(second: Int) : CustomAttachment(CUSTOM_MSG_NOTIFY_H5, second) {
var bean: Bean? = null
override fun parseData(data: JSONObject) {
bean = Gson().fromJson(data.toJSONString(), Bean::class.java)
}
data class Bean(
val roomUid: Int,
/**
* 飘屏类型 0 房间静态飘屏 1 全服动态飘屏
*/
val floatingType: Int,
val content: String,
)
}

View File

@@ -261,6 +261,7 @@ public class RoomEvent {
public static final int TAROT_NOTIFY = 107;
public static final int TAROT_NOTIFY_SVGA = 108;
public static final int NOTIFY_H5 = 109;
private int event = NONE;
private int micPosition = Integer.MIN_VALUE;