|
@@ -0,0 +1,192 @@
|
|
|
+package com.swago.room.reward
|
|
|
+
|
|
|
+import android.animation.Animator
|
|
|
+import android.animation.ObjectAnimator
|
|
|
+import android.content.Context
|
|
|
+import android.util.AttributeSet
|
|
|
+import android.view.LayoutInflater
|
|
|
+import android.view.View
|
|
|
+import android.widget.FrameLayout
|
|
|
+import android.widget.Toast
|
|
|
+import com.swago.baseswago.baseroom.IRoomActiveListener
|
|
|
+import com.swago.baseswago.baseroom.IRoomInfo
|
|
|
+import com.swago.baseswago.baseroom.RoomTimer
|
|
|
+import com.swago.baseswago.baseroom.SwagoRoomManager
|
|
|
+import com.swago.baseswago.model.RedEnvelope
|
|
|
+import com.swago.baseswago.model.live.OnlineRewardsModel
|
|
|
+import com.swago.baseswago.util.AppContext
|
|
|
+import com.swago.baseswago.util.LogUtil
|
|
|
+import com.swago.baseswago.util.NoDoubleClickListener
|
|
|
+import com.swago.baseswago.util.TimeUtil
|
|
|
+import com.swago.room.R
|
|
|
+import com.swago.room.databinding.ViewRewardsBinding
|
|
|
+
|
|
|
+
|
|
|
+class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener {
|
|
|
+ private var binding: ViewRewardsBinding? = null
|
|
|
+ private var timeL = 0L
|
|
|
+ private var duration:String = ""
|
|
|
+ private var nextCoins:Int = 0
|
|
|
+ private var coins:Int = 0
|
|
|
+ private var nextTime:Int = 0
|
|
|
+ private var rewardsModel: OnlineRewardsModel ?= null
|
|
|
+ private var scaleXAnimator:ObjectAnimator ?= null
|
|
|
+ private var scaleYAnimator:ObjectAnimator ?= null
|
|
|
+ var openGetCoins:((duration:String,coins:Int,nextCoins:Int,nextTime:Int) ->Unit)? = null
|
|
|
+ private
|
|
|
+ constructor(context: Context) : this(context, null)
|
|
|
+ constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
|
|
+ constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
|
|
|
+ context,
|
|
|
+ attrs,
|
|
|
+ defStyle
|
|
|
+ ){
|
|
|
+ initView()
|
|
|
+ }
|
|
|
+ private fun initView() {
|
|
|
+ SwagoRoomManager.addListener(this)
|
|
|
+ RoomTimer.timeTickList.add(this)
|
|
|
+ binding = ViewRewardsBinding.inflate(LayoutInflater.from(context), this, true)
|
|
|
+
|
|
|
+ binding?.ivRewards?.setOnClickListener(object: NoDoubleClickListener(){
|
|
|
+ override fun onClick() {
|
|
|
+ if (rewardsModel == null){
|
|
|
+ Toast.makeText(AppContext.getContext(), "10级以上用户可以领取", Toast.LENGTH_SHORT).show()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ timeL ++
|
|
|
+ scaleXAnimator?.cancel()
|
|
|
+ scaleYAnimator?.cancel()
|
|
|
+ binding?.tvTime?.setBackgroundResource(R.mipmap.bg_time_reward)
|
|
|
+ openGetCoins?.invoke(duration,coins,nextCoins,nextTime)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ startAnimation()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun startAnimation(){
|
|
|
+ // 创建X轴放大的动画
|
|
|
+ scaleXAnimator = ObjectAnimator.ofFloat(binding?.clReward, "scaleX", 1.0f, 1.05f)
|
|
|
+ scaleXAnimator?.setDuration(500)
|
|
|
+ scaleXAnimator?.repeatCount = ObjectAnimator.INFINITE
|
|
|
+ scaleXAnimator?.repeatMode = ObjectAnimator.REVERSE
|
|
|
+
|
|
|
+ // 创建Y轴放大的动画
|
|
|
+ scaleYAnimator = ObjectAnimator.ofFloat(binding?.clReward, "scaleY", 1.0f, 1.05f)
|
|
|
+ scaleYAnimator?.setDuration(500)
|
|
|
+ scaleYAnimator?.repeatCount = ObjectAnimator.INFINITE
|
|
|
+ scaleYAnimator?.repeatMode = ObjectAnimator.REVERSE
|
|
|
+
|
|
|
+ }
|
|
|
+ override fun changeRoom(iRoomInfo: IRoomInfo) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun leaveRoom(iRoomInfo: IRoomInfo) {
|
|
|
+ visibility = View.GONE
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun joinedRoom(iRoomInfo: IRoomInfo) {
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun endRoom(iRoomInfo: IRoomInfo?) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun closeRoomed() {
|
|
|
+ RoomTimer.timeTickList.remove(this)
|
|
|
+ SwagoRoomManager.removeListener(this)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onTimeCount(time: Int) {
|
|
|
+ when{
|
|
|
+ timeL== 300L -> {
|
|
|
+ // 启动动画
|
|
|
+ duration ="five"
|
|
|
+ scaleXAnimator?.start()
|
|
|
+ scaleYAnimator?.start()
|
|
|
+ binding?.tvTime?.setBackgroundResource(R.mipmap.bg_get_reward)
|
|
|
+ binding?.tvTime?.text = "Get!"
|
|
|
+ }
|
|
|
+
|
|
|
+ timeL== 600L -> {
|
|
|
+ // 启动动画
|
|
|
+ duration ="ten"
|
|
|
+ scaleXAnimator?.start()
|
|
|
+ scaleYAnimator?.start()
|
|
|
+ binding?.tvTime?.setBackgroundResource(R.mipmap.bg_get_reward)
|
|
|
+ binding?.tvTime?.text = "Get!"
|
|
|
+ }
|
|
|
+
|
|
|
+ timeL== 900L -> {
|
|
|
+ // 启动动画
|
|
|
+ duration ="fifteen"
|
|
|
+ scaleXAnimator?.start()
|
|
|
+ scaleYAnimator?.start()
|
|
|
+ binding?.tvTime?.setBackgroundResource(R.mipmap.bg_get_reward)
|
|
|
+ binding?.tvTime?.text = "Get!"
|
|
|
+ }
|
|
|
+ timeL== 1800L -> {
|
|
|
+ // 启动动画
|
|
|
+ duration ="thirty"
|
|
|
+ scaleXAnimator?.start()
|
|
|
+ scaleYAnimator?.start()
|
|
|
+ binding?.tvTime?.setBackgroundResource(R.mipmap.bg_get_reward)
|
|
|
+ binding?.tvTime?.text = "Get!"
|
|
|
+ }
|
|
|
+
|
|
|
+ timeL> 1800L -> {
|
|
|
+ scaleXAnimator?.cancel()
|
|
|
+ scaleYAnimator?.cancel()
|
|
|
+ visibility = View.GONE
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ timeL ++
|
|
|
+ binding?.tvTime?.text = TimeUtil.convertMinSecond(timeL)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ fun setOnlineCoin(model: OnlineRewardsModel){
|
|
|
+ timeL = model.onlineDuration * 60L
|
|
|
+ timeL ++
|
|
|
+ rewardsModel = model
|
|
|
+ if (!model.five){
|
|
|
+ coins = model.coin.five
|
|
|
+ nextCoins = model.coin.ten
|
|
|
+ nextTime = 10
|
|
|
+ binding?.tvCoins?.text = "+${model.coin.five}"
|
|
|
+ visibility = View.VISIBLE
|
|
|
+ binding?.tvTime?.text = TimeUtil.convertMinSecond(timeL)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!model.ten){
|
|
|
+ coins = model.coin.ten
|
|
|
+ nextCoins = model.coin.fifteen
|
|
|
+ nextTime = 15
|
|
|
+ binding?.tvCoins?.text = "+${model.coin.ten}"
|
|
|
+ visibility = View.VISIBLE
|
|
|
+ binding?.tvTime?.text = TimeUtil.convertMinSecond(timeL)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!model.fifteen){
|
|
|
+ coins = model.coin.fifteen
|
|
|
+ nextCoins = model.coin.thirty
|
|
|
+ nextTime = 30
|
|
|
+ binding?.tvCoins?.text = "+${model.coin.fifteen}"
|
|
|
+ visibility = View.VISIBLE
|
|
|
+ binding?.tvTime?.text = TimeUtil.convertMinSecond(timeL)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!model.thirty){
|
|
|
+ coins = model.coin.thirty
|
|
|
+ nextCoins = 0
|
|
|
+ nextTime = 0
|
|
|
+ binding?.tvCoins?.text = "+${model.coin.thirty}"
|
|
|
+ visibility = View.VISIBLE
|
|
|
+ binding?.tvTime?.text = TimeUtil.convertMinSecond(timeL)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|