From 3bebde7111b4a204a4a94646d2981bea563f6eff Mon Sep 17 00:00:00 2001 From: renhaoting <370797079@qq.com> Date: Wed, 17 Dec 2025 14:35:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AA=E5=B1=8F=E9=A1=B5=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=B9=BF=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 1 + .../vididin/features/splash/SplashActivity.kt | 135 +++++++++++++++++- app/src/main/res/values/styles.xml | 6 + 3 files changed, 138 insertions(+), 4 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 10cec49..ebeff5a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,6 +30,7 @@ android:name="com.gamedog.vididin.features.splash.SplashActivity" android:exported="true" android:launchMode="singleTop" + android:theme="@style/Theme.App.TransparentSplash" android:screenOrientation="portrait"> diff --git a/app/src/main/java/com/gamedog/vididin/features/splash/SplashActivity.kt b/app/src/main/java/com/gamedog/vididin/features/splash/SplashActivity.kt index 05ac468..2e24d18 100644 --- a/app/src/main/java/com/gamedog/vididin/features/splash/SplashActivity.kt +++ b/app/src/main/java/com/gamedog/vididin/features/splash/SplashActivity.kt @@ -3,16 +3,19 @@ package com.gamedog.vididin.features.splash import android.app.Activity import android.content.Intent import android.view.LayoutInflater -import androidx.core.view.ViewCompat -import androidx.core.view.WindowInsetsCompat -import androidx.core.view.updatePadding import androidx.lifecycle.lifecycleScope import com.ama.core.architecture.appBase.AppViewsEmptyViewModelActivity import com.gamedog.vididin.main.interfaces.OnTabStyleListener import com.gamedog.vididin.router.Router +import com.remax.bill.ads.AdResult +import com.remax.bill.ads.PreloadController +import com.remax.bill.ads.bidding.AppOpenBiddingInitializer +import com.remax.bill.ads.config.AdConfigManager import com.remax.bill.ads.ext.AdShowExt import com.remax.bill.ads.log.AdLogger +import com.vididin.real.money.game.R import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.async import kotlinx.coroutines.delay import kotlinx.coroutines.launch import com.vididin.real.money.game.databinding.ActivitySplashBinding as ViewBinding @@ -22,9 +25,14 @@ import com.vididin.real.money.game.databinding.ActivitySplashBinding as ViewBind @AndroidEntryPoint class SplashActivity : AppViewsEmptyViewModelActivity(), OnTabStyleListener { + private var isAdLoaded = false + private var startTime = 0L + override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater) override fun ViewBinding.initViews() { + startTime = System.currentTimeMillis() + with(binding) { } @@ -37,6 +45,9 @@ class SplashActivity : AppViewsEmptyViewModelActivity(), OnTabStyle override fun ViewBinding.initListeners() { startFallbackTimer() + + // 初始化广告和应用 + initializeApp() } override fun ViewBinding.initObservers() { @@ -54,9 +65,125 @@ class SplashActivity : AppViewsEmptyViewModelActivity(), OnTabStyle } } + private fun initializeApp() { + lifecycleScope.launch { + try { + async { performOtherInitializations() } + val adMobInitDeferred = async { initializeAd() } + + val adMobResult = adMobInitDeferred.await() + + // 处理AdMob初始化结果 + when (adMobResult) { + is AdResult.Success -> { + // 2. 加载开屏广告 + showAppOpenAd() + } + + is AdResult.Failure -> { + AdLogger.e("AdMob SDK初始化失败: ${adMobResult.error.message}") + // 初始化失败,延迟后直接跳转 + delayAndJumpToMain() + } + + AdResult.Loading -> { + AdLogger.d("AdMob SDK初始化中...") + } + } + + } catch (e: Exception) { + AdLogger.e("应用初始化异常", e) + delayAndJumpToMain() + } + } + } + + + private suspend fun initializeAd(): AdResult { + 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毫秒,总共10秒完成动画 + } + } + + + 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) + /*DataReportManager.reportData( + "loading_page_end", mapOf( + "pass_time" to ceil((System.currentTimeMillis() - startTime) / 1000.0).toInt() + ) + )*/ + }) { + is AdResult.Success -> { + delayAndJumpToMain() + } + + is AdResult.Failure -> { + AdLogger.e("开屏广告显示失败: ${result.error.message}") + // 开屏失败尝试展示插页 + if (AdConfigManager.shouldShowInterstitialAfterAppOpenFailure()) { + lifecycleScope.launch { + try { + when (val interstitialResult = AdShowExt.showInterstitialAd(this@SplashActivity)) { + is AdResult.Success -> { + delayAndJumpToMain() + } + + is AdResult.Failure -> { + delayAndJumpToMain() + } + + AdResult.Loading -> { + } + } + + } catch (e: Exception) { + delayAndJumpToMain() + } + } + } else { + delayAndJumpToMain() + } + } + + AdResult.Loading -> { + AdLogger.d("开屏广告显示中...") + } + } + } + + private suspend fun delayAndJumpToMain() { + val elapsedTime = System.currentTimeMillis() - startTime + val remainingTime = MIN_SPLASH_TIME - elapsedTime + + if (remainingTime > 0) { + delay(remainingTime) + } + + Router.Main.startActivity(this@SplashActivity) + } companion object { - const val MAX_SPLASH_TIME = 5 * 1000L + const val MAX_SPLASH_TIME = 10 * 1000L + const val MIN_SPLASH_TIME = 2 * 1000L internal fun startActivity(activity: Activity) { activity.startActivity(Intent(activity.applicationContext, SplashActivity::class.java)) diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index aeead6c..784b335 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -6,4 +6,10 @@ bold + + \ No newline at end of file