新增参数 needShowSplashAd

This commit is contained in:
renhaoting 2026-01-16 16:53:17 +08:00
parent 93ca811144
commit c9e9984ee6
1 changed files with 21 additions and 35 deletions

View File

@ -22,7 +22,6 @@ import com.remax.bill.ads.ext.AdShowExt
import com.remax.bill.ads.log.AdLogger import com.remax.bill.ads.log.AdLogger
import com.viddin.videos.free.R import com.viddin.videos.free.R
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -34,8 +33,9 @@ import com.viddin.videos.free.databinding.ActivitySplashBinding as ViewBinding
@AndroidEntryPoint @AndroidEntryPoint
class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyleListener { class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyleListener {
private var mHasGotoMain: Boolean = false
private var mStartMs: Long = 0L private var mStartMs: Long = 0L
private var isAdLoaded = false private var isAdShowSuccess = false
private var startTime = 0L private var startTime = 0L
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater) override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
@ -71,24 +71,23 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
} }
override fun ViewBinding.initObservers() { override fun ViewBinding.initObservers() {
//TODO("Not yet implemented")
} }
override fun onTabIsDarkFont(isDarkFont: Boolean) { override fun onTabIsDarkFont(isDarkFont: Boolean) {
//TODO("Not yet implemented")
} }
private fun startJumpTimer() { private fun startJumpTimer() {
lifecycleScope.launch { lifecycleScope.launch {
delay(MAX_SPLASH_TIME) delay(MAX_SPLASH_TIME)
gotoMain() gotoMain(isAdShowSuccess)
} }
} }
private fun initializeApp() { private fun initializeApp() {
lifecycleScope.launch() { lifecycleScope.launch() {
try { try {
async { performOtherInitializations() }
val adMobInitDeferred = async { initializeAd() } val adMobInitDeferred = async { initializeAd() }
val adMobResult = adMobInitDeferred.await() val adMobResult = adMobInitDeferred.await()
@ -102,7 +101,7 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
is AdResult.Failure -> { is AdResult.Failure -> {
AdLogger.e("AdMob SDK初始化失败: ${adMobResult.error.message}") AdLogger.e("AdMob SDK初始化失败: ${adMobResult.error.message}")
// 初始化失败,延迟后直接跳转 // 初始化失败,延迟后直接跳转
delayAndJumpToMain() delayAndJumpToMain(isAdShowSuccess)
} }
AdResult.Loading -> { AdResult.Loading -> {
@ -112,7 +111,7 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
} catch (e: Exception) { } catch (e: Exception) {
AdLogger.e("应用初始化异常", e) AdLogger.e("应用初始化异常", e)
delayAndJumpToMain() delayAndJumpToMain(isAdShowSuccess)
} }
} }
} }
@ -122,26 +121,9 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
return AppOpenBiddingInitializer.initialize(this@SplashActivity, R.mipmap.ic_launcher) 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() { private suspend fun showAppOpenAd() {
if (isAdLoaded) {
return
}
when (val result = AdShowExt.showAppOpenAd(this@SplashActivity) { loaded -> when (val result = AdShowExt.showAppOpenAd(this@SplashActivity) { loaded ->
isAdLoaded = loaded
PreloadController.preload(this) PreloadController.preload(this)
PreloadController.preloadPangle(this) PreloadController.preloadPangle(this)
PreloadController.preloadTopOn(this) PreloadController.preloadTopOn(this)
@ -152,7 +134,8 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
) )
}) { }) {
is AdResult.Success -> { is AdResult.Success -> {
delayAndJumpToMain() isAdShowSuccess = true
delayAndJumpToMain(false)
} }
is AdResult.Failure -> { is AdResult.Failure -> {
@ -163,11 +146,11 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
try { try {
when (val interstitialResult = AdShowExt.showInterstitialAd(this@SplashActivity)) { when (val interstitialResult = AdShowExt.showInterstitialAd(this@SplashActivity)) {
is AdResult.Success -> { is AdResult.Success -> {
delayAndJumpToMain() delayAndJumpToMain(true)
} }
is AdResult.Failure -> { is AdResult.Failure -> {
delayAndJumpToMain() delayAndJumpToMain(true)
} }
AdResult.Loading -> { AdResult.Loading -> {
@ -175,11 +158,11 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
} }
} catch (e: Exception) { } catch (e: Exception) {
delayAndJumpToMain() delayAndJumpToMain(isAdShowSuccess)
} }
} }
} else { } 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 elapsedTime = System.currentTimeMillis() - startTime
val remainingTime = MIN_SPLASH_TIME - elapsedTime val remainingTime = MIN_SPLASH_TIME - elapsedTime
@ -197,13 +180,16 @@ class SplashActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyle
delay(remainingTime) delay(remainingTime)
} }
gotoMain() gotoMain(needShowSplashAd)
} }
private fun gotoMain() { private fun gotoMain(needShowSplashAd: Boolean) {
if (!mHasGotoMain) {
mHasGotoMain = true
Router.Main.startActivity(this@SplashActivity) Router.Main.startActivity(this@SplashActivity)
finish() finish()
} }
}
private fun startLoadingAnim() { private fun startLoadingAnim() {
val imageView = binding.ivAnim val imageView = binding.ivAnim