From 2c0a52ec48b307feeccd747eb7c18d2f74222552 Mon Sep 17 00:00:00 2001 From: renhaoting <370797079@qq.com> Date: Thu, 18 Dec 2025 16:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BF=80=E5=8A=B1ad=20=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../features/watchad/WatchAdActivity.kt | 26 ++++--------------- .../remax/bill/ads/RewardedAdController.kt | 20 +++++++------- .../java/com/remax/bill/ads/ext/AdShowExt.kt | 9 ++++--- .../ads/pangle/PangleRewardedAdController.kt | 11 +++++--- .../ads/topon/TopOnRewardedAdController.kt | 15 ++++++++--- 6 files changed, 40 insertions(+), 43 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ebeff5a..a5cb81e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -50,7 +50,7 @@ - + diff --git a/app/src/main/java/com/gamedog/vididin/features/watchad/WatchAdActivity.kt b/app/src/main/java/com/gamedog/vididin/features/watchad/WatchAdActivity.kt index 0a02d99..4c740be 100644 --- a/app/src/main/java/com/gamedog/vididin/features/watchad/WatchAdActivity.kt +++ b/app/src/main/java/com/gamedog/vididin/features/watchad/WatchAdActivity.kt @@ -119,6 +119,8 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity(), OnTabStyl if (shouldNotifyOneAdWatched) { NotifyMan.instance().sendEvent(VididinEvents.EVENT_FINISHED_ONE_AD, NotifyMan.NotifyData(1)) } + + finish() } private fun stateCounter() { @@ -129,8 +131,7 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity(), OnTabStyl } override fun onFinish() { - notifyAdWatchFinish() - finish() + } } mCountDownTimer.start() @@ -163,10 +164,11 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity(), OnTabStyl try { when(AdShowExt.showRewardedVideoAd(this@WatchAdActivity, { rewardedData -> mRewardedDollarNum = rewardedData.rewardNum + }, { + notifyAdWatchFinish() })) { is AdResult.Success -> { val temp = 111 - } is AdResult.Failure -> { @@ -180,24 +182,6 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity(), OnTabStyl } catch (e: Exception) { e.printStackTrace() } - - /*try { - when (val result = AdShowExt.showInterstitialAd(this@WatchAdActivity)) { - is AdResult.Success -> { - //callback.invoke() - } - - is AdResult.Failure -> { - //callback.invoke() - } - - AdResult.Loading -> { - } - } - - } catch (e: Exception) { - //callback.invoke() - }*/ } } diff --git a/bill/src/main/java/com/remax/bill/ads/RewardedAdController.kt b/bill/src/main/java/com/remax/bill/ads/RewardedAdController.kt index ff81cb0..87dea60 100644 --- a/bill/src/main/java/com/remax/bill/ads/RewardedAdController.kt +++ b/bill/src/main/java/com/remax/bill/ads/RewardedAdController.kt @@ -28,13 +28,7 @@ import com.remax.bill.ads.ext.CommonRewardedData import com.remax.bill.ads.log.AdLogger import com.remax.bill.ads.util.PositionGet import com.remax.bill.ui.dialog.ADLoadingDialog -import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.launch import kotlin.math.ceil -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine import kotlin.also import kotlin.collections.count @@ -138,7 +132,12 @@ class RewardedAdController private constructor() { /** * 显示广告 */ - suspend fun showAd(activity: Activity, adUnitId: String? = null, onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)? = null): AdResult { + suspend fun showAd( + activity: Activity, + adUnitId: String? = null, + onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)? = null, + closeCallback: () -> Unit + ): AdResult { val finalAdUnitId = adUnitId ?: BuildConfig.ADMOB_REWARDED_ID // 累积触发统计 @@ -194,7 +193,7 @@ class RewardedAdController private constructor() { AdLogger.d("Admob使用缓存中的激励广告,广告位ID: %s", finalAdUnitId) // 3. 显示广告 - val result = showAdInternal(activity, cachedAd.ad, finalAdUnitId, onRewardEarned) + val result = showAdInternal(activity, cachedAd.ad, finalAdUnitId, onRewardEarned, closeCallback) result } else { @@ -380,7 +379,8 @@ class RewardedAdController private constructor() { activity: Activity, rewardedAd: RewardedAd, adUnitId: String, - onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)? + onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)?, + closeCallback: () -> Unit ): AdResult { return suspendCancellableCoroutine { continuation -> var hasRewarded = false @@ -411,6 +411,8 @@ class RewardedAdController private constructor() { if (continuation.isActive) { continuation.resume(result) } + + closeCallback.invoke() } override fun onAdFailedToShowFullScreenContent(adError: AdError) { diff --git a/bill/src/main/java/com/remax/bill/ads/ext/AdShowExt.kt b/bill/src/main/java/com/remax/bill/ads/ext/AdShowExt.kt index 9e95b5a..5cae9dc 100644 --- a/bill/src/main/java/com/remax/bill/ads/ext/AdShowExt.kt +++ b/bill/src/main/java/com/remax/bill/ads/ext/AdShowExt.kt @@ -294,7 +294,8 @@ object AdShowExt { */ suspend fun showRewardedVideoAd( activity: Activity, - rewardCallback: ((CommonRewardedData) -> Unit)? = null + rewardCallback: ((CommonRewardedData) -> Unit)? = null, + closeCallback: ()->Unit ): AdResult { AdLogger.d("激励视频广告竞价开始") val winner = RewardedBiddingManager.bidding(activity) @@ -311,7 +312,7 @@ object AdShowExt { { rewardItem, commonRewardedData -> rewardCallback?.invoke(commonRewardedData) AdLogger.e("AdMob激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}") - } + }, closeCallback ) } BiddingWinner.PANGLE -> { @@ -322,7 +323,7 @@ object AdShowExt { { pagRewardItem, commonRewardedData -> rewardCallback?.invoke(commonRewardedData) AdLogger.e("Pangle激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}") - } + }, closeCallback ) } BiddingWinner.TOPON -> { @@ -334,7 +335,7 @@ object AdShowExt { val rewardedData = CommonRewardedData(revenueValue.toFloat()) rewardCallback?.invoke(rewardedData) AdLogger.e("TopOn激励视频奖励回调, 奖励值:$revenueValue") - } + }, closeCallback ) } } diff --git a/bill/src/main/java/com/remax/bill/ads/pangle/PangleRewardedAdController.kt b/bill/src/main/java/com/remax/bill/ads/pangle/PangleRewardedAdController.kt index 23a512f..99c33de 100644 --- a/bill/src/main/java/com/remax/bill/ads/pangle/PangleRewardedAdController.kt +++ b/bill/src/main/java/com/remax/bill/ads/pangle/PangleRewardedAdController.kt @@ -35,7 +35,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine import kotlin.coroutines.resume import kotlin.math.ceil -import kotlin.math.roundToLong /** * Pangle激励视频广告控制器 @@ -102,7 +101,8 @@ class PangleRewardedAdController private constructor() { suspend fun showAd( activity: Activity, adUnitId: String? = null, - onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)? = null + onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)? = null, + closeCallback: () -> Unit ): AdResult { val finalAdUnitId = adUnitId ?: BuildConfig.PANGLE_REWARDED_ID @@ -149,7 +149,7 @@ class PangleRewardedAdController private constructor() { ADLoadingDialog.hide() currentRewardedAd = null currentAdUnitId = null - showAdInternal(activity, ad, finalAdUnitId, onRewardEarned) + showAdInternal(activity, ad, finalAdUnitId, onRewardEarned, closeCallback) } else { ADLoadingDialog.hide() totalShowFailCount++ @@ -249,7 +249,8 @@ class PangleRewardedAdController private constructor() { activity: Activity, rewardedAd: PAGRewardedAd, adUnitId: String, - onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)? + onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)?, + closeCallback: () -> Unit ): AdResult { val applicationContext = activity.applicationContext return suspendCancellableCoroutine { continuation -> @@ -351,6 +352,8 @@ class PangleRewardedAdController private constructor() { if (continuation.isActive) { continuation.resume(AdResult.Success(Unit)) } + + closeCallback.invoke() } override fun onUserEarnedReward(rewardItem: PAGRewardItem) { diff --git a/bill/src/main/java/com/remax/bill/ads/topon/TopOnRewardedAdController.kt b/bill/src/main/java/com/remax/bill/ads/topon/TopOnRewardedAdController.kt index 8e55c0b..59ff3d7 100644 --- a/bill/src/main/java/com/remax/bill/ads/topon/TopOnRewardedAdController.kt +++ b/bill/src/main/java/com/remax/bill/ads/topon/TopOnRewardedAdController.kt @@ -19,7 +19,6 @@ import com.remax.base.ads.AdRevenueManager import com.remax.base.ads.RevenueInfo import com.remax.base.ext.KvIntDelegate import com.remax.base.report.DataReportManager -import com.remax.bill.ads.PreloadController import com.thinkup.core.api.AdError import com.thinkup.core.api.TUAdInfo import com.thinkup.core.api.TUAdRevenueListener @@ -131,7 +130,8 @@ class TopOnRewardedAdController private constructor() { suspend fun showAd( activity: Activity, placementId: String? = null, - onRewardEarned: ((String, Int, Double) -> Unit)? = null + onRewardEarned: ((String, Int, Double) -> Unit)? = null, + closeCallback: ()->Unit ): AdResult { val finalPlacementId = resolvePlacementId(placementId) if (finalPlacementId.isBlank()) { @@ -185,7 +185,7 @@ class TopOnRewardedAdController private constructor() { if (entry != null && entry.ad.isAdReady) { ADLoadingDialog.hide() AdLogger.d("TopOn使用缓存激励广告展示,广告位ID: %s", finalPlacementId) - entry.listener.awaitShow(activity, onRewardEarned) + entry.listener.awaitShow(activity, onRewardEarned, closeCallback) } else { ADLoadingDialog.hide() AdResult.Failure(createAdException("广告加载失败")) @@ -297,6 +297,7 @@ class TopOnRewardedAdController private constructor() { private var cacheTime: Long = System.currentTimeMillis() private var hasRewarded: Boolean = false private var rewardCallback: ((String, Int, Double) -> Unit)? = null + private var closeCallback: (()->Unit)? = null fun attachLoadContinuation(continuation: kotlinx.coroutines.CancellableContinuation) { loadContinuation = continuation @@ -324,13 +325,18 @@ class TopOnRewardedAdController private constructor() { showContinuation = null } - suspend fun awaitShow(activity: Activity, onRewardEarned: ((String, Int, Double) -> Unit)?): AdResult { + suspend fun awaitShow( + activity: Activity, + onRewardEarned: ((String, Int, Double) -> Unit)?, + closeCallback: () -> Unit + ): AdResult { if (!rewardedVideoAd.isAdReady) { AdLogger.w("TopOn激励广告未准备好,展示终止,广告位ID: %s", placementId) return AdResult.Failure(createAdException("广告未准备好")) } rewardCallback = onRewardEarned + this.closeCallback = closeCallback hasRewarded = false return suspendCancellableCoroutine { continuation -> @@ -483,6 +489,7 @@ class TopOnRewardedAdController private constructor() { } } + closeCallback?.invoke() resumeShow(AdResult.Success(Unit)) }