首页金币获取逻辑及UI
This commit is contained in:
parent
df87261b62
commit
f5162cb3a8
|
|
@ -6,4 +6,7 @@ object VididinEvents {
|
|||
const val Event_Account_Cash_Changed = 602
|
||||
const val Event_Account_Bank_Info_Changed = 603
|
||||
|
||||
|
||||
const val Event_HOME_WATCH_Time_TICK = 700
|
||||
|
||||
}
|
||||
|
|
@ -15,10 +15,14 @@ import com.ama.core.architecture.appBase.AppViewsFragment
|
|||
import com.ama.core.architecture.appBase.OnFragmentBackgroundListener
|
||||
import com.ama.core.architecture.util.setStatusBarDarkFont
|
||||
import com.ama.core.common.util.asSafe
|
||||
import com.gamedog.vididin.VididinEvents
|
||||
import com.gamedog.vididin.core.login.login.AccountManager
|
||||
import com.gamedog.vididin.main.fragments.home.HomeFragmentStateAdapter
|
||||
import com.gamedog.vididin.main.fragments.home.fragment.HomeItemFragment
|
||||
import com.gamedog.vididin.main.interfaces.OnSwitchTabListener
|
||||
import com.gamedog.vididin.main.interfaces.OnTabStyleListener
|
||||
import com.gamedog.vididin.youtubestatistic.RewardConst
|
||||
import com.gamedog.vididin.youtubestatistic.TickerTimer
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.getValue
|
||||
|
|
@ -31,6 +35,7 @@ import com.gamedog.vididin.main.fragments.home.YoutubeUiState as UiState
|
|||
@AndroidEntryPoint
|
||||
class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwitchTabListener, OnFragmentBackgroundListener {
|
||||
|
||||
private var mTotalMs: Long = 0L
|
||||
override val mViewModel: ViewModel by viewModels()
|
||||
override var isBackgroundBright: Boolean = true
|
||||
|
||||
|
|
@ -54,6 +59,22 @@ class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwit
|
|||
viewPager2.setPageTransformer { _, _ -> }
|
||||
viewPager2.offscreenPageLimit = 1
|
||||
viewPager2.adapter = mViewPagerAdapter
|
||||
|
||||
registerEvents({
|
||||
handleWatchTimeTick()
|
||||
}, VididinEvents.Event_HOME_WATCH_Time_TICK,)
|
||||
}
|
||||
|
||||
private fun handleWatchTimeTick() {
|
||||
mTotalMs += TickerTimer.Notify_Interval_MS
|
||||
if (mTotalMs < RewardConst.HOME_WATCH_DURATION) {
|
||||
binding?.dragIconView?.setProgress(mTotalMs * 100/RewardConst.HOME_WATCH_DURATION)
|
||||
} else {
|
||||
mTotalMs = 0L
|
||||
binding?.dragIconView?.setProgress(mTotalMs * 100/ RewardConst.HOME_WATCH_DURATION)
|
||||
AccountManager.addGold(RewardConst.HOME_WATCH_REWARD_NUM)
|
||||
binding?.dragIconView?.showRewardGoldAnim()
|
||||
}
|
||||
}
|
||||
|
||||
override fun ViewBinding.initListeners() {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.gamedog.vididin.beans.YoutubeVideo
|
|||
import com.gamedog.vididin.main.WatchVideoDialog
|
||||
import com.gamedog.vididin.router.Router
|
||||
import com.gamedog.vididin.widget.MyPlayerControlView
|
||||
import com.gamedog.vididin.youtubestatistic.TickerTimer
|
||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants
|
||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.YouTubePlayer
|
||||
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener
|
||||
|
|
@ -34,6 +35,7 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
|||
private var mIsPlaying: Boolean = false
|
||||
private var mCurPlayedSecond: Float = 0F
|
||||
private var mTotalDuration: Float = -1F
|
||||
private val mTickerTimer = TickerTimer()
|
||||
|
||||
|
||||
override fun inflateViewBinding(
|
||||
|
|
@ -167,6 +169,8 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
|||
} else {
|
||||
showPlayIconAnim()
|
||||
}
|
||||
|
||||
if (mIsPlaying) mTickerTimer.start() else mTickerTimer.pause()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import android.view.LayoutInflater
|
|||
import android.widget.LinearLayout
|
||||
import androidx.core.view.isVisible
|
||||
import com.gamedog.vididin.databinding.LayoutDragIconViewBinding
|
||||
import com.gamedog.vididin.manager.TaskManager
|
||||
|
||||
class HomeDragIconView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
|
@ -24,45 +23,36 @@ class HomeDragIconView @JvmOverloads constructor(
|
|||
init {
|
||||
mBinding = LayoutDragIconViewBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
mBinding.run {
|
||||
progressBar.setProgressListener { progress->
|
||||
if (progress >= 100) {
|
||||
tvGoldNum.text = buildString {
|
||||
append("+")
|
||||
append(TaskManager.instance().getHomeWatchDurationRewardNum())
|
||||
}
|
||||
|
||||
executeGoldNumAnim()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun executeGoldNumAnim() {
|
||||
fun showRewardGoldAnim() {
|
||||
val animView = mBinding.llGoldRoot
|
||||
|
||||
val alphaAnimator = ObjectAnimator.ofFloat(
|
||||
animView,
|
||||
"alpha",
|
||||
0.5f, 1.0f, 0.5f
|
||||
0.5f, 1.0f
|
||||
).apply {
|
||||
duration = 500
|
||||
duration = 1500
|
||||
}
|
||||
|
||||
val scaleXAnimator = ObjectAnimator.ofFloat(
|
||||
animView,
|
||||
"scaleX",
|
||||
0.5f, 1.0f, 0.5f
|
||||
0.5f, 1.1f, 1F
|
||||
).apply {
|
||||
duration = 500
|
||||
duration = 1500
|
||||
}
|
||||
|
||||
val scaleYAnimator = ObjectAnimator.ofFloat(
|
||||
animView,
|
||||
"scaleY",
|
||||
0.5f, 1.0f, 0.5f
|
||||
0.5f, 1.1f, 1F
|
||||
).apply {
|
||||
duration = 500
|
||||
duration = 1500
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -70,13 +60,15 @@ class HomeDragIconView @JvmOverloads constructor(
|
|||
animatorSet.playTogether(alphaAnimator, scaleXAnimator, scaleYAnimator)
|
||||
animatorSet.addListener(object : Animator.AnimatorListener {
|
||||
override fun onAnimationCancel(animation: Animator) {
|
||||
animView.isVisible = false
|
||||
mBinding.progressBar.setProgress(0)
|
||||
postDelayed({
|
||||
animView.visibility = INVISIBLE
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
animView.isVisible = false
|
||||
mBinding.progressBar.setProgress(0)
|
||||
postDelayed({
|
||||
animView.visibility = INVISIBLE
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
override fun onAnimationRepeat(animation: Animator) {
|
||||
|
|
@ -84,12 +76,18 @@ class HomeDragIconView @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
override fun onAnimationStart(animation: Animator) {
|
||||
|
||||
animView.isVisible = true
|
||||
}
|
||||
})
|
||||
animatorSet.start()
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun setProgress(progress: Long) {
|
||||
mBinding.progressBar.setProgress(progress.toInt())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package com.gamedog.vididin.youtubestatistic
|
||||
|
||||
class RewardConst {
|
||||
companion object {
|
||||
const val HOME_WATCH_DURATION = 5 * 1000L
|
||||
const val HOME_WATCH_REWARD_NUM = 28
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
package com.gamedog.vididin.youtubestatistic
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.Looper
|
||||
import com.ama.core.architecture.util.eventbus.NotifyMan
|
||||
import com.gamedog.vididin.VididinEvents
|
||||
|
||||
|
||||
|
||||
|
||||
class TickerTimer() {
|
||||
|
||||
private val mCountHandler: Handler by lazy {
|
||||
Handler(Looper.getMainLooper())
|
||||
}
|
||||
private val mCounterRunnable by lazy {
|
||||
object : Runnable {
|
||||
override fun run() {
|
||||
if (isRunning) {
|
||||
handleNewTick()
|
||||
mCountHandler.postDelayed(this, Notify_Interval_MS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Volatile
|
||||
private var isRunning = false
|
||||
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
const val Notify_Interval_MS = 50L
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Synchronized
|
||||
fun start() {
|
||||
isRunning = true
|
||||
mCountHandler.postDelayed(mCounterRunnable, Notify_Interval_MS)
|
||||
}
|
||||
|
||||
|
||||
private fun handleNewTick() {
|
||||
NotifyMan.instance().sendEvent(VididinEvents.Event_HOME_WATCH_Time_TICK, null)
|
||||
}
|
||||
|
||||
fun pause() {
|
||||
if (!isRunning) return
|
||||
isRunning = false
|
||||
}
|
||||
|
||||
|
||||
fun release() {
|
||||
isRunning = false
|
||||
mCounterRunnable.let { mCountHandler.removeCallbacks(it) }
|
||||
}
|
||||
|
||||
/*
|
||||
private val mHandlerThread = HandlerThread("HomeCountTimeThread")
|
||||
private val mCountHandler: Handler by lazy {
|
||||
Handler(mHandlerThread.looper)
|
||||
}
|
||||
private val mCounterRunnable by lazy {
|
||||
object : Runnable {
|
||||
override fun run() {
|
||||
if (isRunning) {
|
||||
handleNewTick()
|
||||
mCountHandler.postDelayed(this, Notify_Interval_MS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Volatile
|
||||
private var isRunning = false
|
||||
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
const val HOME_WATCH_DURATION = 5 * 1000L
|
||||
const val Notify_Interval_MS = 50L
|
||||
}
|
||||
|
||||
init {
|
||||
mHandlerThread.start()
|
||||
}
|
||||
|
||||
|
||||
@Synchronized
|
||||
fun start() {
|
||||
isRunning = true
|
||||
mCountHandler.postDelayed(mCounterRunnable, Notify_Interval_MS)
|
||||
}
|
||||
|
||||
|
||||
private fun handleNewTick() {
|
||||
NotifyMan.instance().sendEvent(VididinEvents.Event_HOME_WATCH_Time_TICK, null)
|
||||
}
|
||||
|
||||
fun pause() {
|
||||
if (!isRunning) return
|
||||
isRunning = false
|
||||
}
|
||||
|
||||
|
||||
fun release() {
|
||||
isRunning = false
|
||||
mCounterRunnable.let { mCountHandler.removeCallbacks(it) }
|
||||
mHandlerThread.quitSafely()
|
||||
}*/
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_horizontal"
|
||||
android:paddingVertical="7dp"
|
||||
tools:ignore="ResourceName">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:padding="8dp"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_gold_root"
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:visibility="gone"
|
||||
android:visibility="invisible"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
app:backgroundColor="@color/progress_background"
|
||||
app:progressWidth="2dp"
|
||||
app:centerIcon="@mipmap/home_envelope"
|
||||
app:currentProgress="35"
|
||||
app:currentProgress="0"
|
||||
app:maxProgress="100"
|
||||
/>
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
android:orientation="vertical"/>
|
||||
|
||||
<com.gamedog.vididin.widget.HomeDragIconView
|
||||
android:id="@+id/drag_icon_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="40dp"
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
|
||||
|
||||
<color name="progress_green">#FF00FF5E</color>
|
||||
<color name="progress_background">#99000000</color>
|
||||
<color name="progress_background">#33FFFFFF</color>
|
||||
<color name="gray_84">#ff938a84</color>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue