VidiDin-Android/app/src/main/java/com/gamedog/vididin/widget/HomeDragIconView.kt

97 lines
2.5 KiB
Kotlin
Raw Normal View History

2025-11-18 05:30:49 +00:00
package com.gamedog.vididin.widget
2025-11-25 06:59:50 +00:00
import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
2025-11-18 05:30:49 +00:00
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
2025-11-25 06:59:50 +00:00
import androidx.core.view.isVisible
2025-11-18 05:30:49 +00:00
import com.gamedog.vididin.databinding.LayoutDragIconViewBinding
2025-11-25 06:59:50 +00:00
import com.gamedog.vididin.manager.TaskManager
2025-11-18 05:30:49 +00:00
class HomeDragIconView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
2025-11-25 06:59:50 +00:00
private var mBinding: LayoutDragIconViewBinding
2025-11-18 05:30:49 +00:00
init {
mBinding = LayoutDragIconViewBinding.inflate(LayoutInflater.from(context), this, true)
2025-11-25 06:59:50 +00:00
mBinding.run {
progressBar.setProgressListener { progress->
if (progress >= 100) {
tvGoldNum.text = buildString {
append("+")
append(TaskManager.instance().getHomeWatchDurationRewardNum())
}
2025-11-18 05:30:49 +00:00
2025-11-25 06:59:50 +00:00
executeGoldNumAnim()
}
}
2025-11-18 05:30:49 +00:00
}
}
2025-11-25 06:59:50 +00:00
private fun executeGoldNumAnim() {
val animView = mBinding.llGoldRoot
val alphaAnimator = ObjectAnimator.ofFloat(
animView,
"alpha",
0.5f, 1.0f, 0.5f
).apply {
duration = 500
}
val scaleXAnimator = ObjectAnimator.ofFloat(
animView,
"scaleX",
0.5f, 1.0f, 0.5f
).apply {
duration = 500
}
val scaleYAnimator = ObjectAnimator.ofFloat(
animView,
"scaleY",
0.5f, 1.0f, 0.5f
).apply {
duration = 500
}
val animatorSet = AnimatorSet()
animatorSet.playTogether(alphaAnimator, scaleXAnimator, scaleYAnimator)
animatorSet.addListener(object : Animator.AnimatorListener {
override fun onAnimationCancel(animation: Animator) {
animView.isVisible = false
mBinding.progressBar.setProgress(0)
}
override fun onAnimationEnd(animation: Animator) {
animView.isVisible = false
mBinding.progressBar.setProgress(0)
}
override fun onAnimationRepeat(animation: Animator) {
}
override fun onAnimationStart(animation: Animator) {
}
})
animatorSet.start()
}
2025-11-18 05:30:49 +00:00
}