新增参数 needShowSplashAd
This commit is contained in:
parent
93ca811144
commit
c9e9984ee6
|
|
@ -22,7 +22,6 @@ import com.remax.bill.ads.ext.AdShowExt
|
|||
import com.remax.bill.ads.log.AdLogger
|
||||
import com.viddin.videos.free.R
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -34,8 +33,9 @@ import com.viddin.videos.free.databinding.ActivitySplashBinding as ViewBinding
|
|||
@AndroidEntryPoint
|
||||
class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyleListener {
|
||||
|
||||
private var mHasGotoMain: Boolean = false
|
||||
private var mStartMs: Long = 0L
|
||||
private var isAdLoaded = false
|
||||
private var isAdShowSuccess = false
|
||||
private var startTime = 0L
|
||||
|
||||
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
|
||||
|
|
@ -71,24 +71,23 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
|
|||
}
|
||||
|
||||
override fun ViewBinding.initObservers() {
|
||||
//TODO("Not yet implemented")
|
||||
|
||||
}
|
||||
|
||||
override fun onTabIsDarkFont(isDarkFont: Boolean) {
|
||||
//TODO("Not yet implemented")
|
||||
|
||||
}
|
||||
|
||||
private fun startJumpTimer() {
|
||||
lifecycleScope.launch {
|
||||
delay(MAX_SPLASH_TIME)
|
||||
gotoMain()
|
||||
gotoMain(isAdShowSuccess)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initializeApp() {
|
||||
lifecycleScope.launch() {
|
||||
try {
|
||||
async { performOtherInitializations() }
|
||||
val adMobInitDeferred = async { initializeAd() }
|
||||
val adMobResult = adMobInitDeferred.await()
|
||||
|
||||
|
|
@ -102,7 +101,7 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
|
|||
is AdResult.Failure -> {
|
||||
AdLogger.e("AdMob SDK初始化失败: ${adMobResult.error.message}")
|
||||
// 初始化失败,延迟后直接跳转
|
||||
delayAndJumpToMain()
|
||||
delayAndJumpToMain(isAdShowSuccess)
|
||||
}
|
||||
|
||||
AdResult.Loading -> {
|
||||
|
|
@ -112,7 +111,7 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
|
|||
|
||||
} catch (e: Exception) {
|
||||
AdLogger.e("应用初始化异常", e)
|
||||
delayAndJumpToMain()
|
||||
delayAndJumpToMain(isAdShowSuccess)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -122,26 +121,9 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
|
|||
return AppOpenBiddingInitializer.initialize(this@SplashActivity, R.mipmap.ic_launcher)
|
||||
}
|
||||
|
||||
private suspend fun performOtherInitializations() {
|
||||
for (i in 0..100 step 1) {
|
||||
// 检测到广告已显示,立即设置进度为100
|
||||
if (isAdLoaded) {
|
||||
//selfBindView.progressBar.progress = 100
|
||||
break
|
||||
}
|
||||
//selfBindView.progressBar.progress = i
|
||||
delay(100) // 改为100毫秒
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private suspend fun showAppOpenAd() {
|
||||
if (isAdLoaded) {
|
||||
return
|
||||
}
|
||||
|
||||
when (val result = AdShowExt.showAppOpenAd(this@SplashActivity) { loaded ->
|
||||
isAdLoaded = loaded
|
||||
PreloadController.preload(this)
|
||||
PreloadController.preloadPangle(this)
|
||||
PreloadController.preloadTopOn(this)
|
||||
|
|
@ -152,7 +134,8 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
|
|||
)
|
||||
}) {
|
||||
is AdResult.Success -> {
|
||||
delayAndJumpToMain()
|
||||
isAdShowSuccess = true
|
||||
delayAndJumpToMain(false)
|
||||
}
|
||||
|
||||
is AdResult.Failure -> {
|
||||
|
|
@ -163,11 +146,11 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
|
|||
try {
|
||||
when (val interstitialResult = AdShowExt.showInterstitialAd(this@SplashActivity)) {
|
||||
is AdResult.Success -> {
|
||||
delayAndJumpToMain()
|
||||
delayAndJumpToMain(true)
|
||||
}
|
||||
|
||||
is AdResult.Failure -> {
|
||||
delayAndJumpToMain()
|
||||
delayAndJumpToMain(true)
|
||||
}
|
||||
|
||||
AdResult.Loading -> {
|
||||
|
|
@ -175,11 +158,11 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
|
|||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
delayAndJumpToMain()
|
||||
delayAndJumpToMain(isAdShowSuccess)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delayAndJumpToMain()
|
||||
delayAndJumpToMain(isAdShowSuccess)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +172,7 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun delayAndJumpToMain() {
|
||||
private suspend fun delayAndJumpToMain(needShowSplashAd: Boolean) {
|
||||
val elapsedTime = System.currentTimeMillis() - startTime
|
||||
val remainingTime = MIN_SPLASH_TIME - elapsedTime
|
||||
|
||||
|
|
@ -197,12 +180,15 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
|
|||
delay(remainingTime)
|
||||
}
|
||||
|
||||
gotoMain()
|
||||
gotoMain(needShowSplashAd)
|
||||
}
|
||||
|
||||
private fun gotoMain() {
|
||||
Router.Main.startActivity(this@SplashActivity)
|
||||
finish()
|
||||
private fun gotoMain(needShowSplashAd: Boolean) {
|
||||
if (!mHasGotoMain) {
|
||||
mHasGotoMain = true
|
||||
Router.Main.startActivity(this@SplashActivity)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun startLoadingAnim() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue