Просмотр исходного кода

feat: 道具卡添加财富等级入口

huangdong 1 год назад
Родитель
Сommit
73f66207f9

+ 0 - 14
app/src/main/java/com/adealink/weparty/module/level/util/LevelUIUtil.kt

@@ -95,20 +95,6 @@ fun getLevelLabelSvgaRes(level: Int): String {
 }
 
 
-fun getLevelChatBubbleRes(level: Int): Int? {
-//    4.聊天气泡(6个):46、56、76、96、116、136
-    if (level < 46) {
-        return null
-    }
-    return when (level) {
-        in 46..55 -> R.drawable.level_chat_bubble_v46
-        in 56..75 -> R.drawable.level_chat_bubble_v56
-        in 76..95 -> R.drawable.level_chat_bubble_v76
-        in 96..115 -> R.drawable.level_chat_bubble_v96
-        in 116..135 -> R.drawable.level_chat_bubble_v116
-        else -> R.drawable.level_chat_bubble_v136
-    }
-}
 
 
 const val GLOD_COLOR_TEXT_LIMITED_LEVEL = 20

+ 61 - 60
app/src/main/java/com/adealink/weparty/module/level/view/UserLevelView.kt

@@ -12,7 +12,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
 import androidx.core.view.updateLayoutParams
 import com.adealink.frame.aab.util.getCompatColor
 import com.adealink.frame.aab.util.getCompatString
-import com.adealink.frame.util.DisplayUtil
+import com.adealink.frame.log.Log
 import com.adealink.weparty.R
 import com.adealink.weparty.commonui.ext.dp
 import com.adealink.weparty.databinding.LevelLayoutUserLevelBinding
@@ -24,92 +24,94 @@ import com.opensource.svgaplayer.control.SVGAManager.Companion.parser
 
 /**
  * 1. 用户等级View,必须指定默认高度, 宽度为wrap_content
- * 2. 要旧svga,不要使用新svga,会有问题
  */
 class UserLevelView @JvmOverloads constructor(
     context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
 ) : ConstraintLayout(context, attrs, defStyleAttr) {
 
     companion object {
-        private val svgaCache = LruCache<String, SVGAVideoEntity>(20) // 缓存SVGAVideoEntity,避免内存过载
-
-        private val DEFAULT_TEXT_SIZE = 66f
-        private val DEFAULT_HEIGHT = DisplayUtil.dp2px(49f).toFloat() //标准高度
+        private val svgaCache = LruCache<String, SVGAVideoEntity>(20)
+        private const val KEY_LEVEL_LABEL_SVGA = "text"
+        private const val DEFAULT_TEXT_SIZE = 66f
     }
 
-    val binding = LevelLayoutUserLevelBinding.inflate(LayoutInflater.from(context), this)
+    private val binding = LevelLayoutUserLevelBinding.inflate(LayoutInflater.from(context), this)
+
+    var level: Int = 0
 
     init {
         visibility = View.GONE
-        binding.svgaLevelBg.clearsAfterDetached = false
-        binding.svgaLevelBg.setQuickRecycled(false)
-        binding.svgaLevelBg.setAutoPlay(true)
+        binding.svgaLevelBg.apply {
+            clearsAfterDetached = false
+            setQuickRecycled(false)
+            setAutoPlay(true)
+        }
     }
 
-    private val KEY_LEVEL_LABEL_SVGA = "text"
-    var level: Int = 0
-
     fun updateLevel(level: Int) {
         this.level = level
+
         if (level <= 0) {
             visibility = View.GONE
-            binding.svgaLevelBg.setVideoItem(null, null)
-            binding.svgaLevelBg.stopAnimation()
-        } else {
-            visibility = View.VISIBLE
-            val levelText = getCompatString(R.string.level_user_level, level)
-
-            //根据比例设置宽度
-            if (level < 60) {
-                val viewHeight = layoutParams.height
-                binding.svgaLevelBg.updateLayoutParams {
-                    width = (viewHeight / 100f * 265).toInt()
-                    height = viewHeight
-                }
-            } else {
-                val viewHeight = layoutParams.height
-                binding.svgaLevelBg.updateLayoutParams {
-                    width = (viewHeight / 100f * 286).toInt()
-                    height = viewHeight
-                }
+            binding.svgaLevelBg.apply {
+                setVideoItem(null, null)
+                stopAnimation()
             }
+            return
+        }
 
-            val name= getLevelLabelSvgaRes(level = level)
-            val callback=object : SVGAParser.ParseCompletion {
-                override fun onComplete(videoItem: SVGAVideoEntity) {
-                    val dynamicEntity = SVGADynamicEntity()
-                    val textPaint = TextPaint().apply {
-                        textSize = DEFAULT_TEXT_SIZE
-                        color = getCompatColor(R.color.color_FFFFF979)
-                        textAlign = Paint.Align.CENTER
-                        typeface = Typeface.DEFAULT_BOLD
-                    }
+        visibility = View.VISIBLE
 
-                    dynamicEntity.setDynamicText(levelText, textPaint, KEY_LEVEL_LABEL_SVGA)
-                    binding.svgaLevelBg.setVideoItem(videoItem, dynamicEntity)
-                    binding.svgaLevelBg.startAnimation()
+        val levelText = getCompatString(R.string.level_user_level, level)
+        val svgaName = getLevelLabelSvgaRes(level)
+        val viewHeight = layoutParams.height
 
-                    // **解析成功后,将解析结果缓存起来**
-                    svgaCache.put(name, videoItem)
-                }
+        // 设置 svga 背景宽高
+        val svgaWidth = if (level < 60) (viewHeight / 100f * 265).toInt()
+        else (viewHeight / 100f * 286).toInt()
 
-                override fun onError(error: Throwable?) {
+        binding.svgaLevelBg.updateLayoutParams {
+            width = svgaWidth
+            height = viewHeight
+        }
 
-                }
+        // 优先尝试缓存
+        svgaCache.get(svgaName)?.let {
+            setSVGAWithText(it, levelText)
+            return
+        }
 
+        val parserCallback = object : SVGAParser.ParseCompletion {
+            override fun onComplete(svgaEntity: SVGAVideoEntity) {
+                setSVGAWithText(svgaEntity, levelText)
+                svgaCache.put(svgaName, svgaEntity)
             }
 
-            // **先检查缓存,是否已经解析过该资源**
-            svgaCache.get(name)?.let {
-//                Log.d("TAG", "updateLevel: cache,${svgaCache.size()}")
-                callback.onComplete(it) // 直接返回缓存的解析结果
-                return
+            override fun onError(error: Throwable?) {
+                error?.printStackTrace()
+                Log.e("UserLevelView", "SVGA parse error", error)
             }
+        }
+
+        val svgaSize = if (level < 60) 132.dp() else 140.dp()
+        parser.decodeFromAssets(svgaName, parserCallback, svgaSize)
+    }
 
+    private fun setSVGAWithText(videoItem: SVGAVideoEntity, levelText: String) {
+        val textPaint = TextPaint().apply {
+            textSize = DEFAULT_TEXT_SIZE
+            color = getCompatColor(R.color.color_FFFFF979)
+            textAlign = Paint.Align.CENTER
+            typeface = Typeface.DEFAULT_BOLD
+        }
+
+        val dynamicEntity = SVGADynamicEntity().apply {
+            setDynamicText(levelText, textPaint, KEY_LEVEL_LABEL_SVGA)
+        }
 
-            parser.decodeFromAssets(
-                getLevelLabelSvgaRes(level = level),callback, if (level < 60) 132.dp() else 140.dp()
-            )
+        binding.svgaLevelBg.apply {
+            setVideoItem(videoItem, dynamicEntity)
+            startAnimation()
         }
     }
 
@@ -117,5 +119,4 @@ class UserLevelView @JvmOverloads constructor(
         super.onAttachedToWindow()
         binding.svgaLevelBg.startAnimation()
     }
-
-}
+}

+ 3 - 3
app/src/main/java/com/adealink/weparty/module/store/data/StoreData.kt

@@ -284,7 +284,7 @@ data class UserGoodInfo(
     val ringDesc: String? = null,  //戒指描述
     @GsonNullable
     @SerializedName("activityType")
-    val activityType: Int? = null,  // 特权活动类型 0, "默认"  1, "VIP"  2, "SVIP"  3,魅力等级  4, "财富等级" 见PrivilegeActivityType
+    val activityType: Int? = null,  // 特权活动类型 0, "默认"  1, "VIP"  2, "SVIP"  4,魅力等级  3, "财富等级" 见PrivilegeActivityType
     @GsonNullable
     @SerializedName("activityLevel")
     val activityLevel: Int? = null,  // 特权活动类型
@@ -306,8 +306,8 @@ enum class PrivilegeActivityType(val type: Int) {
     COMMON(0), //"默认"
     VIP(1), //, "VIP"
     SVIP(2), //, "SVIP"
-    CHARM(3), //, "魅力等级"
-    WEALTH(4), //, "财富等级"
+    CHARM(4), //, "魅力等级"
+    WEALTH(3), //, "财富等级"
 }
 
 infix fun UserGoodInfo.contentsTheSame(other: UserGoodInfo): Boolean =

+ 3 - 0
module/backpack/src/main/java/com/adealink/weparty/backpack/adapter/BackpackGoodsUsingItemViewBinder.kt

@@ -289,6 +289,9 @@ class BackpackGoodsUsingItemViewBinder(
             PrivilegeActivityType.VIP.type -> {
                 getCompatString(APP_R.string.profile_vip)
             }
+            PrivilegeActivityType.WEALTH.type -> {
+                getCompatString(APP_R.string.module_wealthlevel)
+            }
 
 //            PrivilegeActivityType.SVIP.type -> {
 //                getCompatString(APP_R.string.commonui_svip)

+ 7 - 0
module/backpack/src/main/java/com/adealink/weparty/backpack/fragment/BackpackUsingTabFragment.kt

@@ -169,6 +169,13 @@ class BackpackUsingTabFragment : BaseFragment(R.layout.fragment_backpack), IBack
                     )
                     .start()
             }
+            PrivilegeActivityType.WEALTH.type -> {
+                Router.build(activity, Level.LevelDetail.PATH)
+                    .putExtra(
+                        Level.Common.EXTRA_UID,
+                        ProfileModule.getMyUid()
+                    ).start()
+            }
         }
 //
 //            PrivilegeActivityType.SVIP.type -> {

+ 11 - 1
module/level/src/main/java/com/adealink/weparty/level/adapter/itembinder/LevelUserLevelInfoViewBinder.kt

@@ -1,6 +1,7 @@
 package com.adealink.weparty.level.adapter.itembinder
 
 import android.annotation.SuppressLint
+import android.net.Uri
 import android.view.LayoutInflater
 import android.view.ViewGroup
 import androidx.constraintlayout.widget.ConstraintLayout
@@ -10,6 +11,7 @@ import com.adealink.frame.aab.util.getCompatDrawable
 import com.adealink.frame.aab.util.getCompatString
 import com.adealink.frame.util.DisplayUtil
 import com.adealink.weparty.commonui.ext.dp
+import com.adealink.weparty.commonui.ext.show
 import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
 import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
 import com.adealink.weparty.effect.AnimExtraConfig
@@ -45,7 +47,15 @@ class LevelUserLevelInfoViewBinder :
             binding.userLevel.text = getCompatString(R.string.level_level_num_3, item.userLevelInfo.level)
 
             // 勋章特效
-            binding.levelEffectView.setImageDrawable(getCompatDrawable(R.drawable.level_upgrade_user_card_crown))
+            item.userMedal?.let {
+                if(it.dynamicUrl.isNotEmpty()){
+                    binding.levelEffectView.setUrl(it.dynamicUrl, extraConfig = AnimExtraConfig(loop = -1))
+                }else{
+                    binding.levelImView.show()
+                    binding.levelImView.setImageURI(Uri.parse(it.url))
+                }
+
+            }
 
             binding.levelExpView.doOnAttach {
                 val expProgressMaxWith = binding.levelExpView.layoutParams.width

+ 1 - 1
module/level/src/main/java/com/adealink/weparty/level/viewmodel/WealthLevelViewModel.kt

@@ -221,7 +221,7 @@ class WealthLevelViewModel : VapcEffectViewModel(), IWealthLevelViewModel, ILeve
             val honors = rewardMap[ProductTypeConstant.MEDAL.type]
             honors?.let {
                 //同步荣耀勋章到个人信息卡片
-                if(dataList.size>0){
+                if(dataList.size > 0){
                     val userCardInfo =  dataList.first()
                     if(userCardInfo is LevelUserInfoData){
                         honors.forEach {

BIN
module/level/src/main/res/drawable-xhdpi/level_upgrade_user_card_crown.webp


+ 11 - 1
module/level/src/main/res/layout/layout_user_level_info.xml

@@ -88,7 +88,7 @@
         app:layout_constraintTop_toBottomOf="@+id/avatar"
         tools:text="667 EXP to Next Level" />
 
-    <com.opensource.svgaplayer.WenextSvgaView
+    <com.adealink.weparty.effect.WeAnimView
         android:id="@+id/level_effect_view"
         android:layout_width="120dp"
         android:layout_height="120dp"
@@ -97,5 +97,15 @@
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintTop_toTopOf="parent"
         tools:src="@drawable/common_default_avatar_ic" />
+    <androidx.appcompat.widget.AppCompatImageView
+        android:id="@+id/level_im_view"
+        android:layout_width="120dp"
+        android:layout_height="120dp"
+        android:layout_marginTop="122dp"
+        android:layout_marginEnd="36.5dp"
+        android:visibility="gone"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
+        tools:src="@drawable/common_default_avatar_ic" />
 
 </androidx.constraintlayout.widget.ConstraintLayout>