Sfoglia il codice sorgente

feat: 送礼倍数

tongmengxiao 3 mesi fa
parent
commit
948e1b6000

+ 135 - 65
room/src/main/java/com/swago/room/giftdandao/GiftDanDaoView.kt

@@ -1,16 +1,16 @@
 package com.swago.room.giftdandao
 
 import android.animation.Animator
+import android.animation.AnimatorInflater
+import android.animation.AnimatorListenerAdapter
 import android.animation.AnimatorSet
 import android.animation.ObjectAnimator
 import android.app.Service
 import android.content.Context
 import android.os.Vibrator
 import android.util.AttributeSet
-import android.util.Log
 import android.view.LayoutInflater
 import android.view.View
-import android.view.animation.BounceInterpolator
 import android.view.animation.DecelerateInterpolator
 import android.widget.FrameLayout
 import android.widget.ImageView
@@ -26,7 +26,6 @@ import com.swago.baseswago.util.DpPxUtil
 import com.swago.baseswago.util.LogUtil
 import com.swago.baseswago.util.SwagoInfo
 import com.swago.baseswago.util.UserInfo
-import com.swago.room.BuildConfig
 import com.swago.room.R
 import com.swago.room.databinding.ViewItemGiftBinding
 import java.io.File
@@ -52,6 +51,10 @@ class GiftDanDaoView : FrameLayout {
         ArrayList<ImageView>()
     }
 
+    private val imageViewPrizeData by lazy {
+        ArrayList<ImageView>()
+    }
+
     constructor(context: Context) : super(context) {
         initView(context)
     }
@@ -63,6 +66,9 @@ class GiftDanDaoView : FrameLayout {
     private var svgaPlayWhichType = 0
 
     private var vibrator: Vibrator? = null
+    private var aniamtionRotate:Animator ?= null
+    private var aniamtionScale:Animator ?= null
+    private var aniamtionNum:Animator ?= null
 
     private fun initView(context: Context) {
         vibrator = context.getSystemService(Service.VIBRATOR_SERVICE) as Vibrator
@@ -71,9 +77,48 @@ class GiftDanDaoView : FrameLayout {
         svgParser2 = SVGAParser(context)
         for (i in 0..5){
             val imageView = ImageView(context)
+            val imageViewPrize = ImageView(context)
             imageViewData.add(imageView)
+            imageViewPrizeData.add(imageViewPrize)
         }
         isDevicesRtl = SwagoInfo.isMirror()
+        setAniamtion()
+    }
+
+    private fun setAniamtion() {
+        aniamtionRotate = AnimatorInflater.loadAnimator(context,R.animator.scale_rotate)
+        aniamtionScale = AnimatorInflater.loadAnimator(context,R.animator.scale)
+        aniamtionNum = AnimatorInflater.loadAnimator(context,R.animator.scale)
+        aniamtionRotate?.setTarget(binding?.ivPrizeBg)
+        aniamtionScale?.setTarget(binding?.ivPrizeFrame)
+        aniamtionNum?.setTarget(binding?.llPrizeNum)
+        aniamtionRotate?.addListener(object : AnimatorListenerAdapter() {
+            override fun onAnimationEnd(animation: Animator) {
+                super.onAnimationEnd(animation)
+                binding?.ivPrizeBg?.rotation = 0f
+                binding?.ivPrizeBg?.scaleX = 1.0f
+                binding?.ivPrizeBg?.scaleY = 1.0f
+                aniamtionRotate?.setTarget(binding?.ivPrizeBg)
+            }
+        })
+        aniamtionScale?.addListener(object : AnimatorListenerAdapter() {
+            override fun onAnimationEnd(animation: Animator) {
+                super.onAnimationEnd(animation)
+                binding?.ivPrizeFrame?.rotation = 0f
+                binding?.ivPrizeFrame?.scaleX = 1.0f
+                binding?.ivPrizeFrame?.scaleY = 1.0f
+                aniamtionScale?.setTarget(binding?.ivPrizeFrame)
+            }
+        })
+        aniamtionNum?.addListener(object : AnimatorListenerAdapter() {
+            override fun onAnimationEnd(animation: Animator) {
+                super.onAnimationEnd(animation)
+                binding?.llPrizeNum?.rotation = 0f
+                binding?.llPrizeNum?.scaleX = 1.0f
+                binding?.llPrizeNum?.scaleY = 1.0f
+                aniamtionNum?.setTarget(binding?.llPrizeNum)
+            }
+        })
     }
 
     fun addData(imGiftModel: IMGiftModel) {
@@ -195,82 +240,51 @@ class GiftDanDaoView : FrameLayout {
                 }
             }
 
-
             clItemGift.removeCallbacks(showRunnable)
             clItemGift.postDelayed(showRunnable, 3000)
             if (imGiftModel.multiple != 0) {
                 when (imGiftModel.multiple) {
-                    in 1..50 -> {
-                        iv.visibility = View.VISIBLE
-                        tvWinPrize2.visibility = View.GONE
-                        svgaWinPrize.visibility = View.GONE
-                        val layoutParams = tvWinPrize.layoutParams as ConstraintLayout.LayoutParams
-                        layoutParams.marginStart = DpPxUtil.dip2px(10f)
-                        tvWinPrize.layoutParams = layoutParams
-                        iv.setImageResource(R.mipmap.win_1_50_prize)
-                        clWinPrize.visibility = View.VISIBLE
-                        tvWinPrize.text =
-                            AppContext.getContext().resources.getString(R.string.win_num_prize)
-                                .format(imGiftModel.multiple)
-                    }
-
-                    in 51..100 -> {
-                        iv.visibility = View.VISIBLE
-                        tvWinPrize2.visibility = View.GONE
-                        svgaWinPrize.visibility = View.GONE
-                        val layoutParams = tvWinPrize.layoutParams as ConstraintLayout.LayoutParams
-                        layoutParams.marginStart = DpPxUtil.dip2px(26f)
-                        tvWinPrize.layoutParams = layoutParams
-                        iv.setImageResource(R.mipmap.win_51_100_prize)
-                        clWinPrize.visibility = View.VISIBLE
-                        tvWinPrize.text =
-                            AppContext.getContext().resources.getString(R.string.win_num_prize)
-                                .format(imGiftModel.multiple)
-                    }
-
-                    in 100..500 -> {
-                        iv.visibility = View.GONE
-                        svgaWinPrize.visibility = View.VISIBLE
-                        playSvg2("win_101_500_prize.svga")
-                        clWinPrize.visibility = View.GONE
-                        tvWinPrize2.visibility = View.VISIBLE
-                        tvWinPrize2.text =
-                            AppContext.getContext().resources.getString(R.string.win_num_prize)
-                                .format(imGiftModel.multiple)
-                    }
-
-                    in 501..1000 -> {
-                        iv.visibility = View.GONE
-                        svgaWinPrize.visibility = View.VISIBLE
-                        UserInfo.getUserInfo()?.let {  userInfoModel ->
-                            if (userInfoModel.id == imGiftModel.senderId && imGiftModel.giftId.toInt() == 202){
-                                vibrator?.vibrate(2500)
-                            }
-                        }
-                        playSvg2("win_501_1000_prize.svga")
-                        tvWinPrize2.visibility = View.VISIBLE
-                        tvWinPrize2.text =
-                            AppContext.getContext().resources.getString(R.string.win_num_prize)
-                                .format(imGiftModel.multiple)
+                    in 1..99 -> {
+                        clPrize.visibility = View.VISIBLE
+                        ivPrizeBg.visibility = View.INVISIBLE
+                        ivPrizeFrame.setImageResource(R.mipmap.gift_prize_frame_1_99)
+                    }
+
+                    in 100..499 -> {
+                        clPrize.visibility = View.VISIBLE
+                        ivPrizeBg.visibility = View.VISIBLE
+                        ivPrizeBg.setImageResource(R.mipmap.gift_bg_prize_100_499)
+                        ivPrizeFrame.setImageResource(R.mipmap.gift_prize_frame_100_499)
+                    }
+
+                    in 500..999 -> {
+                        clPrize.visibility = View.VISIBLE
+                        ivPrizeBg.visibility = View.VISIBLE
+                        ivPrizeBg.setImageResource(R.mipmap.gift_bg_prize_100_499)
+                        ivPrizeFrame.setImageResource(R.mipmap.gift_prize_frame_500_999)
                     }
                     else -> {
-                        iv.visibility = View.GONE
-                        svgaWinPrize.visibility = View.VISIBLE
                         UserInfo.getUserInfo()?.let {  userInfoModel ->
                             if (userInfoModel.id == imGiftModel.senderId && imGiftModel.giftId.toInt() == 202){
                                 vibrator?.vibrate(2500)
                             }
                         }
-                        playSvg2("win_1001_prize.svga")
-                        tvWinPrize2.visibility = View.VISIBLE
-                        tvWinPrize2.text =
-                            AppContext.getContext().resources.getString(R.string.win_num_prize)
-                                .format(imGiftModel.multiple)
+                        clPrize.visibility = View.VISIBLE
+                        ivPrizeBg.visibility = View.VISIBLE
+                        ivPrizeBg.setImageResource(R.mipmap.gift_bg_prize_1000)
+                        ivPrizeFrame.setImageResource(R.mipmap.gift_prize_frame_1000)
                     }
                 }
 
-                clWinPrize.removeCallbacks(winPrizeRunnable)
-                clWinPrize.postDelayed(winPrizeRunnable, 1500)
+                clPrize.removeCallbacks(winPrizeRunnable)
+                clPrize.postDelayed(winPrizeRunnable, 1500)
+                if (aniamtionRotate?.isRunning ==false){
+                    aniamtionRotate?.start()
+                }
+                if (aniamtionScale?.isRunning ==false){
+                    aniamtionScale?.start()
+                }
+                loadGiftPrizeNum(imGiftModel.multiple)
             }
         }
     }
@@ -325,6 +339,60 @@ class GiftDanDaoView : FrameLayout {
         }
     }
 
+    private fun loadGiftPrizeNum(giftCount: Int) {
+        binding?.apply {
+            val giftContStr = giftCount.toString()
+            if (giftContStr.length>imageViewPrizeData.size){
+                imageViewPrizeData.clear()
+                for (i in 0..giftContStr.length){
+                    val imageView = ImageView(context)
+                    imageViewPrizeData.add(imageView)
+                }
+            }
+            imageViewPrizeData[0].setImageResource(R.mipmap.ic_dan_dao_x)
+            llPrizeNum.removeAllViews()
+            llPrizeNum.addView(imageViewPrizeData[0])
+            giftCount.toString().toCharArray().forEachIndexed {  index,char ->
+                when(char){
+                    '0' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_zero)
+                    }
+                    '1' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_one)
+                    }
+                    '2' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_two)
+                    }
+                    '3' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_three)
+                    }
+                    '4' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_four)
+                    }
+                    '5' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_five)
+                    }
+                    '6' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_six)
+                    }
+                    '7' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_seven)
+                    }
+                    '8' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_eight)
+                    }
+                    '9' -> {
+                        imageViewPrizeData[index+1].setImageResource(R.mipmap.ic_dan_dao_big_nine)
+                    }
+                }
+                llPrizeNum.addView(imageViewPrizeData[index+1])
+                if (aniamtionNum?.isRunning ==false){
+                    aniamtionNum?.start()
+                }
+
+            }
+        }
+    }
     private fun loadGiftNum(giftCount: Int) {
         binding?.apply {
             val giftContStr = giftCount.toString()
@@ -406,11 +474,13 @@ class GiftDanDaoView : FrameLayout {
 
     private val winPrizeRunnable by lazy {
         Runnable {
+            LogUtil.d("winPrizeRunnable" , "clPrize")
             vibrator?.cancel()
             binding!!.clWinPrize.visibility = View.INVISIBLE
             binding!!.tvWinPrize.text = ""
             binding!!.svgaWinPrize.visibility = View.INVISIBLE
             binding!!.tvWinPrize2.text = ""
+            binding!!.clPrize.visibility = INVISIBLE
         }
     }
 

+ 44 - 0
room/src/main/res/animator/scale.xml

@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+    android:ordering="sequentially">
+    <!-- 缩放动画 -->
+    <set android:ordering="together">
+        <objectAnimator
+            android:propertyName="scaleX"
+            android:valueFrom="4.0"
+            android:valueTo="1.0"
+            android:duration="400"/>
+
+        <objectAnimator
+            android:propertyName="scaleY"
+            android:valueFrom="4.0"
+            android:valueTo="1.0"
+            android:duration="400"/>
+    </set>
+    <set android:ordering="together">
+        <objectAnimator
+            android:propertyName="scaleX"
+            android:valueFrom="1.0"
+            android:valueTo="1.2"
+            android:duration="100"/>
+
+        <objectAnimator
+            android:propertyName="scaleY"
+            android:valueFrom="1.0"
+            android:valueTo="1.2"
+            android:duration="100"/>
+    </set>
+    <set android:ordering="together">
+        <objectAnimator
+            android:propertyName="scaleX"
+            android:valueFrom="1.2"
+            android:valueTo="1.0"
+            android:duration="100"/>
+
+        <objectAnimator
+            android:propertyName="scaleY"
+            android:valueFrom="1.2"
+            android:valueTo="1.0"
+            android:duration="100"/>
+    </set>
+</set>

+ 22 - 0
room/src/main/res/animator/scale_rotate.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+    <objectAnimator
+        android:propertyName="rotation"
+        android:valueFrom="0"
+        android:valueTo="360"
+        android:duration="600"
+        android:repeatCount="infinite"
+        android:repeatMode="restart"
+        android:interpolator="@android:anim/linear_interpolator"/>
+    <objectAnimator
+        android:propertyName="scaleX"
+        android:valueFrom="4.0"
+        android:valueTo="1.0"
+        android:duration="400"/>
+
+    <objectAnimator
+        android:propertyName="scaleY"
+        android:valueFrom="4.0"
+        android:valueTo="1.0"
+        android:duration="400"/>
+</set>

+ 11 - 12
room/src/main/res/layout/fragment_base_com.xml

@@ -141,27 +141,26 @@
 
     <com.swago.room.giftdandao.GiftDanDaoView
         android:id="@+id/danDaoView"
-        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        android:layout_marginBottom="480dp"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"/>
+        android:layout_width="match_parent"
+        android:layout_height="300dp"/>
 
     <com.swago.room.giftdandao.GiftDanDaoView
         android:id="@+id/danDaoView2"
-        android:layout_marginBottom="400dp"
-        app:layout_constraintBottom_toBottomOf="parent"
+        android:layout_marginTop="60dp"
+        app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"/>
+        android:layout_width="match_parent"
+        android:layout_height="300dp"/>
 
     <com.swago.room.giftdandao.GiftDanDaoView
         android:id="@+id/danDaoView3"
-        android:layout_marginBottom="320dp"
-        app:layout_constraintBottom_toBottomOf="parent"
+        android:layout_marginTop="120dp"
+        app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"/>
+        android:layout_width="match_parent"
+        android:layout_height="300dp"/>
 
     <ViewStub
         android:id="@+id/joinRoomViewStub"

+ 44 - 4
room/src/main/res/layout/view_item_gift.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="wrap_content"
+    android:layout_height="match_parent"
     android:id="@+id/clItemGift"
     android:visibility="invisible"
     tools:visibility="visible"
@@ -12,6 +12,7 @@
         android:id="@+id/clContainer"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent"
+        app:layout_constraintBottom_toBottomOf="parent"
         android:layout_marginTop="50dp"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
@@ -154,10 +155,7 @@
             </LinearLayout>
 
         </androidx.constraintlayout.widget.ConstraintLayout>
-
-
     </androidx.constraintlayout.widget.ConstraintLayout>
-
     <androidx.constraintlayout.widget.ConstraintLayout
         android:id="@+id/clWinPrize"
         app:layout_constraintStart_toStartOf="parent"
@@ -216,5 +214,47 @@
         android:layout_width="0dp"
         android:maxLines="1"
         android:layout_height="wrap_content"/>
+    <androidx.constraintlayout.widget.ConstraintLayout
+        android:id="@+id/clPrize"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:visibility="invisible"
+        tools:visibility="visible"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent">
+        <ImageView
+            android:id="@+id/iv_prize_bg"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:src="@mipmap/gift_bg_prize_1000"
+            android:scaleType="centerInside"
+            android:layout_marginStart="40dp"
+            android:layout_alignParentTop="true"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent"/>
+        <ImageView
+            android:id="@+id/iv_prize_frame"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:src="@mipmap/gift_prize_frame_1000"
+            android:scaleType="centerInside"
+            android:layout_alignParentTop="true"
+            app:layout_constraintEnd_toEndOf="@+id/iv_prize_bg"
+            app:layout_constraintStart_toStartOf="@+id/iv_prize_bg"
+            app:layout_constraintTop_toTopOf="parent"/>
+        <LinearLayout
+            android:id="@+id/llPrizeNum"
+            android:orientation="horizontal"
+            app:layout_constraintEnd_toEndOf="@+id/iv_prize_frame"
+            app:layout_constraintStart_toStartOf="@+id/iv_prize_frame"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintTop_toTopOf="parent"
+            android:layout_marginTop="@dimen/dp_10"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content">
+
+        </LinearLayout>
+    </androidx.constraintlayout.widget.ConstraintLayout>
 
 </androidx.constraintlayout.widget.ConstraintLayout>

BIN
room/src/main/res/mipmap-xxhdpi/gift_bg_prize_1000.png


BIN
room/src/main/res/mipmap-xxhdpi/gift_bg_prize_100_499.png


BIN
room/src/main/res/mipmap-xxhdpi/gift_prize_frame_1000.png


BIN
room/src/main/res/mipmap-xxhdpi/gift_prize_frame_100_499.png


BIN
room/src/main/res/mipmap-xxhdpi/gift_prize_frame_1_99.png


BIN
room/src/main/res/mipmap-xxhdpi/gift_prize_frame_500_999.png