视频页 插屏广告
This commit is contained in:
parent
3bebde7111
commit
e36722ced8
|
|
@ -16,7 +16,6 @@ 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.beans.YoutubeVideo
|
||||
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
|
||||
|
|
@ -24,6 +23,8 @@ 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.RewardConst.Companion.Check_Interval_MS
|
||||
import com.remax.bill.ads.AdResult
|
||||
import com.remax.bill.ads.ext.AdShowExt
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.getValue
|
||||
|
|
@ -35,6 +36,7 @@ import com.gamedog.vididin.main.fragments.home.YoutubeUiState as UiState
|
|||
|
||||
@AndroidEntryPoint
|
||||
class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwitchTabListener, OnFragmentBackgroundListener {
|
||||
private var mWatchedVideoTotal = 0
|
||||
|
||||
private var mTotalMs: Long = 0L
|
||||
override val mViewModel: ViewModel by viewModels()
|
||||
|
|
@ -61,9 +63,31 @@ class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwit
|
|||
viewPager2.offscreenPageLimit = 1
|
||||
viewPager2.adapter = mViewPagerAdapter
|
||||
|
||||
registerEvents({
|
||||
handleWatchTimeTick()
|
||||
}, VididinEvents.Event_HOME_WATCH_Time_TICK,)
|
||||
registerEvents({ data->
|
||||
when (data?.mEventType) {
|
||||
VididinEvents.Event_HOME_WATCH_Time_TICK -> {
|
||||
handleWatchTimeTick()
|
||||
}
|
||||
|
||||
VididinEvents.Event_Finish_One_Video -> {
|
||||
handleEventOneVideoWatched()
|
||||
}
|
||||
}
|
||||
|
||||
}, VididinEvents.Event_HOME_WATCH_Time_TICK, VididinEvents.Event_Finish_One_Video)
|
||||
}
|
||||
|
||||
private fun handleEventOneVideoWatched() {
|
||||
mWatchedVideoTotal ++
|
||||
|
||||
if (mWatchedVideoTotal % VIDEO_NUM_GAP_FOR_AD == 0) {
|
||||
lifecycleScope.launch {
|
||||
showInterstitialAd {
|
||||
// TODO - need do anything for ad show
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun handleWatchTimeTick() {
|
||||
|
|
@ -152,6 +176,27 @@ class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwit
|
|||
}
|
||||
|
||||
|
||||
private fun showInterstitialAd(callback: () -> Unit) {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
when (val result = AdShowExt.showInterstitialAd(requireActivity())) {
|
||||
is AdResult.Success -> {
|
||||
callback.invoke()
|
||||
}
|
||||
|
||||
is AdResult.Failure -> {
|
||||
callback.invoke()
|
||||
}
|
||||
|
||||
AdResult.Loading -> {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
callback.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setHomeTabStyle(f: Fragment?) {
|
||||
isBackgroundBright = f.asSafe<OnFragmentBackgroundListener>()?.isBackgroundBright ?: return
|
||||
|
|
@ -159,6 +204,8 @@ class HomeFragment : AppViewsFragment<ViewBinding, UiState, ViewModel>(), OnSwit
|
|||
}
|
||||
|
||||
companion object {
|
||||
const val VIDEO_NUM_GAP_FOR_AD = 3
|
||||
|
||||
internal fun newInstance() = HomeFragment()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue