|
@@ -23,16 +23,19 @@ import com.swago.room.databinding.ViewRewardsBinding
|
|
|
|
|
|
|
|
|
|
class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener {
|
|
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 var binding: ViewRewardsBinding? = null
|
|
|
|
+ private var timeL = 300L //倒计时
|
|
|
|
+ private var totalTime = 0L //在直播间里时间
|
|
|
|
+ private var duration: String = ""
|
|
|
|
+ private var coins: Int = 0
|
|
|
|
+ private var nextCoins: 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
|
|
private
|
|
constructor(context: Context) : this(context, null)
|
|
constructor(context: Context) : this(context, null)
|
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
|
@@ -40,44 +43,48 @@ class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener
|
|
context,
|
|
context,
|
|
attrs,
|
|
attrs,
|
|
defStyle
|
|
defStyle
|
|
- ){
|
|
|
|
|
|
+ ) {
|
|
initView()
|
|
initView()
|
|
}
|
|
}
|
|
|
|
+
|
|
private fun initView() {
|
|
private fun initView() {
|
|
SwagoRoomManager.addListener(this)
|
|
SwagoRoomManager.addListener(this)
|
|
RoomTimer.timeTickList.add(this)
|
|
RoomTimer.timeTickList.add(this)
|
|
binding = ViewRewardsBinding.inflate(LayoutInflater.from(context), this, true)
|
|
binding = ViewRewardsBinding.inflate(LayoutInflater.from(context), this, true)
|
|
|
|
|
|
- binding?.ivRewards?.setOnClickListener(object: NoDoubleClickListener(){
|
|
|
|
|
|
+ binding?.ivRewards?.setOnClickListener(object : NoDoubleClickListener() {
|
|
override fun onClick() {
|
|
override fun onClick() {
|
|
- if (rewardsModel == null){
|
|
|
|
- Toast.makeText(AppContext.getContext(), "10级以上用户可以领取", Toast.LENGTH_SHORT).show()
|
|
|
|
|
|
+ if (rewardsModel == null) {
|
|
|
|
+ Toast.makeText(
|
|
|
|
+ AppContext.getContext(),
|
|
|
|
+ "10级以上用户可以领取",
|
|
|
|
+ Toast.LENGTH_SHORT
|
|
|
|
+ ).show()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- timeL ++
|
|
|
|
- scaleXAnimator?.cancel()
|
|
|
|
- scaleYAnimator?.cancel()
|
|
|
|
- binding?.tvTime?.setBackgroundResource(R.mipmap.bg_time_reward)
|
|
|
|
- openGetCoins?.invoke(duration,coins,nextCoins,nextTime)
|
|
|
|
|
|
+ if (scaleXAnimator?.isRunning == true){
|
|
|
|
+ openGetCoins?.invoke(duration, coins, nextCoins, nextTime)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
})
|
|
})
|
|
startAnimation()
|
|
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
|
|
|
|
|
|
+ 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
|
|
|
|
|
|
+ // 创建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 changeRoom(iRoomInfo: IRoomInfo) {
|
|
|
|
|
|
}
|
|
}
|
|
@@ -99,94 +106,132 @@ class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener
|
|
}
|
|
}
|
|
|
|
|
|
override fun onTimeCount(time: Int) {
|
|
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)
|
|
|
|
|
|
+ if (timeL == 0L){
|
|
|
|
+ if (scaleXAnimator?.isRunning == false){
|
|
|
|
+ startGetAnimation()
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ totalTime ++
|
|
|
|
+ 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)
|
|
|
|
|
|
+ fun checkOnlineTime(model: OnlineRewardsModel?) {
|
|
|
|
+ if (model == null) {
|
|
|
|
+ rewardsModel = null
|
|
return
|
|
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
|
|
|
|
|
|
+ rewardsModel = model
|
|
|
|
+ visibility = View.VISIBLE
|
|
|
|
+ totalTime = model.onlineDuration * 60L
|
|
|
|
+ nextReward()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun startGetAnimation() {
|
|
|
|
+ // 启动动画
|
|
|
|
+ timeL = 0L
|
|
|
|
+ scaleXAnimator?.start()
|
|
|
|
+ scaleYAnimator?.start()
|
|
|
|
+ binding?.tvTime?.setBackgroundResource(R.mipmap.bg_get_reward)
|
|
|
|
+ binding?.tvTime?.text = "Get!"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun setRewardsSuccess(success:Boolean){
|
|
|
|
+ if (success){
|
|
|
|
+ scaleXAnimator?.cancel()
|
|
|
|
+ scaleYAnimator?.cancel()
|
|
|
|
+ binding?.tvTime?.setBackgroundResource(R.mipmap.bg_time_reward)
|
|
|
|
+ when(duration){
|
|
|
|
+ "five" -> {
|
|
|
|
+ totalTime = totalTime.coerceAtLeast(300)
|
|
|
|
+ rewardsModel?.five = true
|
|
|
|
+ nextReward()
|
|
|
|
+ }
|
|
|
|
+ "ten" -> {
|
|
|
|
+ totalTime = totalTime.coerceAtLeast(600)
|
|
|
|
+ rewardsModel?.ten = true
|
|
|
|
+ nextReward()
|
|
|
|
+ }
|
|
|
|
+ "fifteen" -> {
|
|
|
|
+ totalTime = totalTime.coerceAtLeast(900)
|
|
|
|
+ rewardsModel?.fifteen = true
|
|
|
|
+ nextReward()
|
|
|
|
+ }
|
|
|
|
+ "thirty" -> {
|
|
|
|
+ totalTime = totalTime.coerceAtLeast(1800)
|
|
|
|
+ rewardsModel?.thirty = true
|
|
|
|
+ visibility = View.GONE
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- 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
|
|
|
|
|
|
+ }
|
|
|
|
+ private fun nextReward(){
|
|
|
|
+ rewardsModel?.let { model ->
|
|
|
|
+ //待领取的奖励
|
|
|
|
+ if (!model.five){
|
|
|
|
+ visibility = View.VISIBLE
|
|
|
|
+ coins = model.coin.five
|
|
|
|
+ duration = "five"
|
|
|
|
+ nextCoins = model.coin.ten
|
|
|
|
+ nextTime = 10
|
|
|
|
+ binding?.tvCoins?.text = "+${model.coin.five}fiv"
|
|
|
|
+ //领取奖励倒计时
|
|
|
|
+ if (totalTime >= 300){
|
|
|
|
+ startGetAnimation()
|
|
|
|
+ } else {
|
|
|
|
+ timeL = 300 - totalTime
|
|
|
|
+ binding?.tvTime?.text = TimeUtil.convertMinSecond(timeL)
|
|
|
|
+ }
|
|
|
|
+ } else if (!model.ten){
|
|
|
|
+ visibility = View.VISIBLE
|
|
|
|
+ coins = model.coin.ten
|
|
|
|
+ duration = "ten"
|
|
|
|
+ nextCoins = model.coin.fifteen
|
|
|
|
+ nextTime = 15
|
|
|
|
+ binding?.tvCoins?.text = "+${model.coin.ten}ten"
|
|
|
|
+
|
|
|
|
+ //领取奖励倒计时
|
|
|
|
+ if (totalTime >= 600){
|
|
|
|
+ startGetAnimation()
|
|
|
|
+ } else {
|
|
|
|
+ timeL = 600 - totalTime
|
|
|
|
+ binding?.tvTime?.text = TimeUtil.convertMinSecond(timeL)
|
|
|
|
+ }
|
|
|
|
+ } else if (!model.fifteen){
|
|
|
|
+ visibility = View.VISIBLE
|
|
|
|
+ coins = model.coin.fifteen
|
|
|
|
+ duration = "fifteen"
|
|
|
|
+ nextCoins = model.coin.thirty
|
|
|
|
+ nextTime = 30
|
|
|
|
+ binding?.tvCoins?.text = "+${model.coin.fifteen}fif"
|
|
|
|
+ //领取奖励倒计时
|
|
|
|
+ if (totalTime >= 900){
|
|
|
|
+ startGetAnimation()
|
|
|
|
+ } else {
|
|
|
|
+ timeL = 900 - totalTime
|
|
|
|
+ binding?.tvTime?.text = TimeUtil.convertMinSecond(timeL)
|
|
|
|
+ }
|
|
|
|
+ } else if (!model.thirty){
|
|
|
|
+ visibility = View.VISIBLE
|
|
|
|
+ coins = model.coin.thirty
|
|
|
|
+ duration = "thirty"
|
|
|
|
+ nextCoins = 0
|
|
|
|
+ nextTime = 0
|
|
|
|
+ binding?.tvCoins?.text = "+${model.coin.thirty}thi"
|
|
|
|
+ //领取奖励倒计时
|
|
|
|
+ if (totalTime >= 1800){
|
|
|
|
+ startGetAnimation()
|
|
|
|
+ } else {
|
|
|
|
+ timeL = 1800 - totalTime
|
|
|
|
+ binding?.tvTime?.text = TimeUtil.convertMinSecond(timeL)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ visibility =View.GONE
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|