From ac14be2c88f4dad9798284eede4b17e5cce9b7d9 Mon Sep 17 00:00:00 2001 From: max Date: Tue, 23 Apr 2024 18:58:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=B0=83=E6=95=B4=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E9=A3=98=E5=B1=8F-SVGA=E6=96=B9=E6=A1=88=EF=BC=88=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E5=81=9A=E8=BF=9B=E5=9C=BA/=E9=80=80=E5=87=BA?= =?UTF-8?q?=E5=8A=A8=E7=94=BB=EF=BC=8C=E4=B8=8D=E7=94=A8SVGA=E7=9A=84?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=96=87=E6=9C=AC=E4=BA=86=EF=BC=8C=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E5=8F=A0=E5=8A=A0=E4=B8=80=E4=B8=AATextView=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/notify/views/TemplateSvgaNotify.kt | 77 ++++++++----------- .../layout/layout_template_notify_image.xml | 2 +- .../layout/layout_template_notify_svga.xml | 39 ++++++++++ .../custom/bean/RoomTemplateNotifyMsgBean.kt | 2 + 4 files changed, 76 insertions(+), 44 deletions(-) create mode 100644 app/src/main/res/layout/layout_template_notify_svga.xml diff --git a/app/src/main/java/com/chwl/app/notify/views/TemplateSvgaNotify.kt b/app/src/main/java/com/chwl/app/notify/views/TemplateSvgaNotify.kt index 444dae304..a4af04eb0 100644 --- a/app/src/main/java/com/chwl/app/notify/views/TemplateSvgaNotify.kt +++ b/app/src/main/java/com/chwl/app/notify/views/TemplateSvgaNotify.kt @@ -2,18 +2,18 @@ package com.chwl.app.notify.views import android.content.Context import android.graphics.Color -import android.text.Layout -import android.text.StaticLayout -import android.text.TextPaint +import android.view.LayoutInflater +import android.view.View +import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout +import com.chwl.app.R import com.chwl.app.avroom.widget.TemplateMessageAdapter -import com.chwl.app.common.svga.SimpleSvgaCallback import com.chwl.app.support.float.BaseFloatView import com.chwl.app.utils.CommonJumpHelper import com.chwl.core.home.bean.BannerInfo import com.chwl.core.im.custom.bean.RoomTemplateNotifyMsgBean +import com.example.lib_utils.log.ILog import com.opensource.svgaplayer.SVGADrawable -import com.opensource.svgaplayer.SVGADynamicEntity import com.opensource.svgaplayer.SVGAImageView import com.opensource.svgaplayer.SVGAParser import com.opensource.svgaplayer.SVGAVideoEntity @@ -21,17 +21,14 @@ import java.net.URL class TemplateSvgaNotify(context: Context) : BaseFloatView(context), - TemplateMessageAdapter.Listener { + TemplateMessageAdapter.Listener, ILog { private val templateMessageAdapter = TemplateMessageAdapter(this) - private val svgaView = SVGAImageView(context) var onShowUserCard: ((String) -> Unit)? = null init { - svgaView.loops = 1 - svgaView.clearsAfterDetached = true - addView(svgaView, LayoutParams(LayoutParams.MATCH_PARENT, 0)) + LayoutInflater.from(context).inflate(R.layout.layout_template_notify_svga, this, true) } override fun onBind(item: Any) { @@ -49,53 +46,47 @@ class TemplateSvgaNotify(context: Context) : BaseFloatView(context), requestRemoveSelf() return } - val params = svgaView.layoutParams as ConstraintLayout.LayoutParams - params.dimensionRatio = data.getDimensionRatio() ?: "75:11" - svgaView.layoutParams = params - svgaView.callback = object : SimpleSvgaCallback() { - override fun onFinished() { - requestRemoveSelf() - } - } + val textView = rootView.findViewById(R.id.tv_text) + val textSize = data.fontSize?.toFloat() ?: 12f + val textColor = + templateMessageAdapter.parseColor(data.textColor) ?: Color.WHITE + textView.textSize = textSize + textView.setTextColor(textColor) + + val svgaView = rootView.findViewById(R.id.iv_bg) SVGAParser.shareParser().decodeFromURL( URL(resourceContent), object : SVGAParser.ParseCompletion { override fun onComplete(videoItem: SVGAVideoEntity) { - val text = templateMessageAdapter.parse(context, data) ?: "" - val textKey = data.getSvgaTextKey() - val textSize = data.fontSize?.toFloat() ?: 24f - val textColor = - templateMessageAdapter.parseColor(data.textColor) ?: Color.WHITE - val dynamicEntity = SVGADynamicEntity() - val textPaint = TextPaint() - textPaint.color = textColor //字體顏色 - textPaint.textSize = textSize //字體大小 - dynamicEntity.setDynamicText( - StaticLayout( - text, - 0, - text.length, - textPaint, - 0, - Layout.Alignment.ALIGN_CENTER, - 1.0f, - 0.0f, - false - ), textKey - ) + logD("onComplete width:${videoItem.videoSize.width}") + logD("onComplete height:${videoItem.videoSize.height}") + val width = videoItem.videoSize.width + val height = videoItem.videoSize.height + var dimensionRatio = "75:11" + if (width > 0 && height > 0) { + dimensionRatio = "$width:$height" + } + val params = svgaView.layoutParams as ConstraintLayout.LayoutParams + params.dimensionRatio = dimensionRatio + svgaView.layoutParams = params val skipType = data.skipType if (skipType != null) { - svgaView.setOnClickListener { + val clickAction = View.OnClickListener { if (skipType == BannerInfo.SKIP_TYPE_ROOM_USER_CARD) { onShowUserCard?.invoke(data.skipContent ?: "") } else { CommonJumpHelper.bannerJump(context, skipType, data.skipContent) } } + rootView.setOnClickListener(clickAction) + textView.setOnClickListener(clickAction) } - val drawable = SVGADrawable(videoItem, dynamicEntity) + val drawable = SVGADrawable(videoItem) svgaView.setImageDrawable(drawable) - svgaView.stepToFrame(0, true) + svgaView.startAnimation() + templateMessageAdapter.convert(textView, data) + startEnterAnim() + startDelayRemove() } override fun onError() { diff --git a/app/src/main/res/layout/layout_template_notify_image.xml b/app/src/main/res/layout/layout_template_notify_image.xml index 5cbefa66c..18623e893 100644 --- a/app/src/main/res/layout/layout_template_notify_image.xml +++ b/app/src/main/res/layout/layout_template_notify_image.xml @@ -32,7 +32,7 @@ app:layout_constraintEnd_toEndOf="@id/iv_bg" app:layout_constraintStart_toStartOf="@id/iv_bg" app:layout_constraintTop_toTopOf="@id/iv_bg" - app:layout_constraintWidth_percent="0.626" + app:layout_constraintWidth_percent="0.68" tools:layout_height="wrap_content" tools:text="Message" /> diff --git a/app/src/main/res/layout/layout_template_notify_svga.xml b/app/src/main/res/layout/layout_template_notify_svga.xml new file mode 100644 index 000000000..355e35e36 --- /dev/null +++ b/app/src/main/res/layout/layout_template_notify_svga.xml @@ -0,0 +1,39 @@ + + + + + + + diff --git a/core/src/main/java/com/chwl/core/im/custom/bean/RoomTemplateNotifyMsgBean.kt b/core/src/main/java/com/chwl/core/im/custom/bean/RoomTemplateNotifyMsgBean.kt index f9c91800b..7a59671f3 100644 --- a/core/src/main/java/com/chwl/core/im/custom/bean/RoomTemplateNotifyMsgBean.kt +++ b/core/src/main/java/com/chwl/core/im/custom/bean/RoomTemplateNotifyMsgBean.kt @@ -12,7 +12,9 @@ class RoomTemplateNotifyMsgBean : TemplateMessage() { var resourceContent: String? = null var skipType: Int? = null var skipContent: String? = null + @Deprecated("已不需要,自己可以获取到") var resourceWidth: Int? = null + @Deprecated("已不需要,自己可以获取到") var resourceHeight: Int? = null // SVGA-文本的坑位KEY