feat : 游戏飘屏 修改 实现方案

This commit is contained in:
eggmanQQQ
2024-10-15 16:30:23 +08:00
parent 367a55654b
commit 84ff7be54e
4 changed files with 229 additions and 74 deletions

View File

@@ -138,6 +138,48 @@ class TemplateMessageAdapter(val listener: Listener?) {
textView.movementMethod = LinkMovementMethod()
}
fun convertText(textView: TextView, attachment: TemplateMessage?) {
if (attachment == null) {
textView.text = ""
return
}
val nodeList = attachment.getNodeList()
val textBuilder = TextSpannableBuilder(textView)
nodeList.forEach {
if (it is TemplateNode.NormalNode) {
val textColor = parseColor(it.textColor)
if (textColor != null) {
textBuilder.append(it.text, ForegroundColorSpan(textColor))
} else {
textBuilder.append(it.text)
}
} else if (it is TemplateNode.SpecialNode) {
when (it.content.type) {
Content.TEXT -> {
val text = it.content.text?.getFirstText()
if (!text.isNullOrEmpty()) {
val textColor = parseColor(it.content.textColor)
val clickSpan = createClickSpan(textView.context, it.content, listener)
val list = ArrayList<Any>()
if (textColor != null) {
list.add(ForegroundColorSpan(textColor))
}
if (clickSpan != null) {
list.add(clickSpan)
}
textBuilder.append(text, *list.toArray())
}
}
}
}
}
textView.text = textBuilder.build()
textView.setOnClickListener(null)
textView.movementMethod = LinkMovementMethod()
}
private fun createClickSpan(
context: Context,
content: Content,

View File

@@ -2,43 +2,30 @@ package com.chwl.app.notify.views
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import androidx.constraintlayout.widget.Group
import com.chwl.app.R
import com.chwl.app.avroom.activity.AVRoomActivity
import com.chwl.app.avroom.widget.TemplateMessageAdapter
import com.chwl.app.databinding.LayoutLuckyBagGiftNotifyBinding
import com.chwl.app.common.widget.CircleImageView
import com.chwl.app.support.float.BaseFloatView
import com.chwl.app.ui.utils.ImageLoadUtils
import com.chwl.app.ui.widget.dialog.AllServiceGiftGoRoomTipsDialog
import com.chwl.app.utils.CommonJumpHelper
import com.chwl.core.gift.bean.LuckyBagNoticeInfo
import com.chwl.app.ui.utils.loadImage
import com.chwl.core.gift.event.NotifyEvent
import com.chwl.core.home.bean.BannerInfo
import com.chwl.core.im.custom.bean.RoomTemplateNotifyMsgBean
import com.chwl.core.utils.extension.subAndReplaceDot
import com.chwl.core.im.custom.bean.TemplateMessage.Content
import com.chwl.library.common.util.isVerify
import com.chwl.library.common.util.setVis
import com.chwl.library.rxbus.RxBus
import com.chwl.library.widget.SVGAView
import com.example.lib_utils.ktx.getColorById
import com.example.lib_utils.ktx.singleClick
import com.example.lib_utils.log.ILog
import com.example.lib_utils.spannable.SpannableTextBuilder
import com.netease.nim.uikit.support.glide.GlideApp
import com.opensource.svgaplayer.SVGADrawable
import com.opensource.svgaplayer.SVGAImageView
import com.opensource.svgaplayer.SVGAParser
import com.opensource.svgaplayer.SVGAVideoEntity
import org.greenrobot.eventbus.EventBus
import java.net.URL
import java.text.MessageFormat
class BaiShunGameNotify(context: Context) : BaseFloatView(context),
TemplateMessageAdapter.Listener {
@@ -78,7 +65,7 @@ class BaiShunGameNotify(context: Context) : BaseFloatView(context),
val drawable = SVGADrawable(videoItem)
svgaView.setImageDrawable(drawable)
svgaView.startAnimation()
setView(data,textView)
setView2(data,textView)
}
override fun onError() {
@@ -89,18 +76,84 @@ class BaiShunGameNotify(context: Context) : BaseFloatView(context),
)
} else {
svgaView.loadFile("svga/baishun_notify_bg.svga")
setView(data,textView)
setView2(data,textView)
}
}
private fun setView(data:RoomTemplateNotifyMsgBean,textView:TextView) {
val textSize = data.fontSize?.toFloat() ?: 12f
val textColor = templateMessageAdapter.parseColor(data.textColor) ?: Color.WHITE
textView.textSize = textSize
textView.setTextColor(textColor)
startEnterAnim()
templateMessageAdapter.convert(textView, data)
// private fun setView(data:RoomTemplateNotifyMsgBean,textView:TextView) {
// val textSize = data.fontSize?.toFloat() ?: 12f
// val textColor = templateMessageAdapter.parseColor(data.textColor) ?: Color.WHITE
// textView.textSize = textSize
// textView.setTextColor(textColor)
// startEnterAnim()
// templateMessageAdapter.convert(textView, data)
// val go = findViewById<ImageView>(R.id.go)
// go.setVis(true)
// go.setOnClickListener {
// val event = NotifyEvent()
// event.action = NotifyEvent.Action.ACT_BAI_SHUN_GAME
// event.data = data.skipContent
// EventBus.getDefault().post(event)
// }
// startDelayRemove()
// }
private fun setView2(data:RoomTemplateNotifyMsgBean,textView:TextView) {
var gameIcon = ""
var avatar = ""
var nick = ""
var diamondNum = ""
val contents = data.contents
val firstText = data.template?.getFirstText()
if (contents.isVerify()) {
contents?.forEachIndexed { index, content ->
if (content.type == Content.TEXT){
if (content.key == "nick"){
nick = content.text?.getFirstText()?:""
}else if (content.key == "diamondNum"){
diamondNum = content.text?.getFirstText()?:""
}
}else if (content.type == Content.IMAGE){
if (content.key == "gameIcon"){
gameIcon = content.image ?:""
}else if (content.key == "avatar"){
avatar = content.image ?:""
}
}
}
}
if (gameIcon.isVerify()) {
val gameIconView = findViewById<ImageView>(R.id.gameIcon)
gameIconView.loadImage(gameIcon)
}
if (avatar.isVerify()) {
val avatarView = findViewById<CircleImageView>(R.id.avatar)
avatarView.loadImage(avatar)
}
// "{gameIcon} {avatar} {nick} Win {diamondNum} Coins"
// if (firstText.isVerify()) {
// val replaceGameIcon = firstText?.replace("{gameIcon}","")
// val replaceAvatar = replaceGameIcon?.replace("{avatar}","")
// val replaceNick = replaceAvatar?.replace("{nick}",nick)
// val replaceDiamondNum = replaceNick?.replace("{diamondNum}",diamondNum)
// var newText = replaceDiamondNum
// if (newText.isVerify()) {
// val spStr = SpannableString(newText)
// val start: Int = newText!!.indexOf(nick)
// val end = start + nick.length
// val colorSpan = ForegroundColorSpan(Color.parseColor("#FF3b3b"))
// spStr.setSpan(colorSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
// }
// }
templateMessageAdapter.convertText(textView, data)
val go = findViewById<ImageView>(R.id.go)
go.setVis(true)
go.setOnClickListener {
@@ -109,6 +162,9 @@ class BaiShunGameNotify(context: Context) : BaseFloatView(context),
event.data = data.skipContent
EventBus.getDefault().post(event)
}
val allView = findViewById<Group>(R.id.allView)
startEnterAnim()
allView.setVis(true)
startDelayRemove()
}

View File

@@ -10,38 +10,58 @@
android:id="@+id/iv_bg"
android:layout_width="match_parent"
android:layout_height="70dp"
app:clearsAfterDetached="true"
android:layout_marginTop="@dimen/dp_68"
app:layout_constraintTop_toTopOf="parent"
app:autoPlay="true"
app:clearsAfterDetached="true"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/smash_eggs_notity_bg_4" />
<ImageView
android:id="@+id/gameIcon"
android:layout_width="44dp"
android:layout_height="44dp"
android:scaleType="fitXY"
android:layout_marginStart="@dimen/dp_40"
app:layout_constraintBottom_toBottomOf="@+id/iv_bg"
app:layout_constraintStart_toStartOf="@+id/iv_bg"
app:layout_constraintTop_toTopOf="@+id/iv_bg" />
<com.chwl.app.common.widget.CircleImageView
android:id="@+id/avatar"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginStart="@dimen/dp_5"
android:src="@drawable/default_avatar"
app:layout_constraintBottom_toBottomOf="@+id/iv_bg"
app:layout_constraintStart_toEndOf="@+id/gameIcon"
app:layout_constraintTop_toTopOf="@+id/iv_bg" />
<com.coorchice.library.SuperTextView
android:id="@+id/tv_text"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginStart="@dimen/dp_40"
android:layout_marginHorizontal="@dimen/dp_5"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:includeFontPadding="false"
android:lineSpacingExtra="0dp"
android:lines="2"
android:lineSpacingMultiplier="0.8"
android:textColor="@color/white"
android:textDirection="locale"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@id/iv_bg"
app:layout_constraintEnd_toStartOf="@id/go"
app:layout_constraintStart_toStartOf="@id/iv_bg"
app:layout_constraintStart_toEndOf="@id/avatar"
app:layout_constraintTop_toTopOf="@id/iv_bg"
tools:layout_height="wrap_content"
tools:text="Message" />
tools:text="Message\nMessage" />
<ImageView
android:id="@+id/go"
android:layout_width="35dp"
android:visibility="invisible"
tools:visibility="visible"
android:layout_height="25dp"
android:layout_marginEnd="@dimen/dp_40"
android:src="@drawable/ic_notify_go"
@@ -49,4 +69,12 @@
app:layout_constraintEnd_toEndOf="@id/iv_bg"
app:layout_constraintTop_toTopOf="@+id/tv_text" />
<androidx.constraintlayout.widget.Group
android:id="@+id/allView"
app:constraint_referenced_ids="gameIcon,avatar,tv_text,go"
android:visibility="invisible"
tools:visibility="visible"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</merge>

105
mode.json
View File

@@ -1,63 +1,92 @@
//{
// first=107,
// second=1072,
// data=
// ''
//}
{
"template": {
"ar": "تهانينا لـ {avatar}【{nick}】 في {gameIcon} للحصول على مكافأة 【{diamondNum} عملة ذهبية】!",
"en": "Congratulations to {avatar} [{nick}] for having great luck in {gameIcon} and receiving a reward of [{diamondNum} coins]!",
"zh": "恭喜{avatar}【{nick}】在{gameIcon}中運氣爆棚,獲得【{diamondNum}金幣】獎勵!"
},
"resourceContent": "https://image.molistar.xyz/greedy_floating_notify.png",
"partitionId": 1,
"resourceHeight": 60,
"skipContent": "1006",
"textColor": "#FFFFFF",
"resourceTop": 23,
"svgaTextKey": "noble_text_tx",
"resourceWidth": 375,
"contents": [
{
"height": 20,
"image": "https://img.molistar.xyz/default_avatar_molistar.png",
"width": 20,
"type": "IMAGE",
"key": "avatar",
"height": 20
"type": "IMAGE",
"width": 20
},
{
"fontSize": 12,
"key": "nick",
"text": {
"ar": "英文区",
"en": "英文区",
"zh": "英文区"
},
"type": "TEXT",
"textColor": "#FEF23E",
"key": "nick"
"type": "TEXT"
},
{
"image": "https://image.molistar.xyz/greedy.png",
"width": 20,
"type": "IMAGE",
"height": 20,
"image": "https://image.pekolive.com/Lucky77.png",
"key": "gameIcon",
"height": 20
"type": "IMAGE",
"width": 20
},
{
"fontSize": 12,
"key": "diamondNum",
"text": {
"ar": "5000",
"en": "5000",
"zh": "5000"
"ar": "60000",
"en": "60000",
"zh": "60000"
},
"type": "TEXT",
"textColor": "#00EAFF",
"key": "diamondNum"
"type": "TEXT"
}
],
"skipType": 7,
"dimensionRatio": "375:60",
"fontSize": 12,
"resourceType": "IMAGE"
"nodeList": [
{
"content": {
"$ref": "$.contents[2]"
}
},
{
"text": " ",
"textColor": "#FFFFFF"
},
{
"content": {
"$ref": "$.contents[0]"
}
},
{
"text": " ",
"textColor": "#FFFFFF"
},
{
"content": {
"$ref": "$.contents[1]"
}
},
{
"text": " Win ",
"textColor": "#FFFFFF"
},
{
"content": {
"$ref": "$.contents[3]"
}
},
{
"text": " Coins",
"textColor": "#FFFFFF"
}
],
"partitionId": 1,
"resourceContent": "https://image.molistar.xyz/mini_game_floating_2.svga",
"resourceHeight": 60,
"resourceType": "SVGA",
"resourceWidth": 375,
"skipContent": "136",
"skipType": 7,
"svgaTextKey": "noble_text_tx",
"template": {
"ar": "{gameIcon} {avatar} {nick} Win {diamondNum} Coins",
"en": "{gameIcon} {avatar} {nick} Win {diamondNum} Coins",
"zh": "{gameIcon} {avatar} {nick} Win {diamondNum} Coins"
},
"textColor": "#FFFFFF"
}