3秒钟 还未成功,就退出 不显示广告

This commit is contained in:
renhaoting 2026-01-15 15:26:20 +08:00
parent fa18c550ed
commit 7b86f83177
7 changed files with 34 additions and 9 deletions

View File

@ -22,6 +22,7 @@ import com.remax.bill.ads.ext.AdShowExt
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import com.viddin.videos.free.R
import com.viddin.videos.free.databinding.ActivityWatchAdBinding as ViewBinding
@ -30,6 +31,7 @@ import com.viddin.videos.free.databinding.ActivityWatchAdBinding as ViewBinding
class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyleListener {
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
private var mIsLoadSuccess: Boolean = false
private var mRewardedDollarNum: Double = 0.0
override var mEnableBannerAd = false
@ -177,18 +179,27 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
}
} else {
lifecycleScope.launch {
binding.root.postDelayed({
if (!mIsLoadSuccess) {
handleLoadFailed()
}
}, 3000)
try {
when(AdShowExt.showRewardedVideoAd(this@WatchAdActivity, { rewardedData ->
mRewardedDollarNum = rewardedData.rewardNum
}, {
notifyAdWatchFinish()
}, {
mIsLoadSuccess = true
})) {
is AdResult.Success -> {
val temp = 111
mIsLoadSuccess = true
}
is AdResult.Failure -> {
val temp = 111
handleLoadFailed()
}
AdResult.Loading -> {
@ -202,6 +213,10 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
}
}
private fun handleLoadFailed() {
AndroidUtil.showToast(R.string.ad_load_fail)
finish()
}
companion object {

View File

@ -64,4 +64,8 @@
<string name="has_claim_box_cash_hint">Has claimed %s cash successfully.</string>
<string name="watch_full_reward_ad_hint">Watch the full video to get rewards!</string>
<string name="ad_load_fail">Ad failed to load</string>
</resources>

View File

@ -236,5 +236,6 @@
<string name="withdraw_fail_dailog_common_hint">Retirada falhou. Verifique o histórico de retiradas para detalhes.</string>
<string name="not_enough_gold">Não tens ouro suficiente.</string>
<string name="ad_load_fail">O anúncio não carregou</string>
</resources>

View File

@ -136,7 +136,8 @@ class RewardedAdController private constructor() {
activity: Activity,
adUnitId: String? = null,
onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)? = null,
closeCallback: () -> Unit
closeCallback: () -> Unit,
readyCallback:() -> Unit,
): AdResult<Unit> {
val finalAdUnitId = adUnitId ?: BuildConfig.ADMOB_REWARDED_ID
@ -190,6 +191,7 @@ class RewardedAdController private constructor() {
if (cachedAd != null) {
ADLoadingDialog.hide()
readyCallback.invoke()
AdLogger.d("Admob使用缓存中的激励广告广告位ID: %s", finalAdUnitId)
// 3. 显示广告

View File

@ -295,7 +295,8 @@ object AdShowExt {
suspend fun showRewardedVideoAd(
activity: Activity,
rewardCallback: ((CommonRewardedData) -> Unit)? = null,
closeCallback: ()->Unit
closeCallback: ()->Unit,
readyCallback:() -> Unit,
): AdResult<Unit> {
AdLogger.d("激励视频广告竞价开始")
val winner = RewardedBiddingManager.bidding(activity)
@ -312,7 +313,7 @@ object AdShowExt {
{ rewardItem, commonRewardedData ->
rewardCallback?.invoke(commonRewardedData)
AdLogger.e("AdMob激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
}, closeCallback
}, closeCallback, readyCallback
)
}
BiddingWinner.PANGLE -> {
@ -323,7 +324,7 @@ object AdShowExt {
{ pagRewardItem, commonRewardedData ->
rewardCallback?.invoke(commonRewardedData)
AdLogger.e("Pangle激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
}, closeCallback
}, closeCallback, readyCallback
)
}
BiddingWinner.TOPON -> {
@ -336,7 +337,7 @@ object AdShowExt {
rewardCallback?.invoke(rewardedData)
//xxxx
AdLogger.e("TopOn激励视频奖励回调, 奖励值:$revenueValue")
}, closeCallback
}, closeCallback, readyCallback
)
}
}

View File

@ -102,7 +102,7 @@ class PangleRewardedAdController private constructor() {
activity: Activity,
adUnitId: String? = null,
onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)? = null,
closeCallback: () -> Unit
closeCallback: () -> Unit, readyCallback:() -> Unit,
): AdResult<Unit> {
val finalAdUnitId = adUnitId ?: BuildConfig.PANGLE_REWARDED_ID
@ -149,6 +149,7 @@ class PangleRewardedAdController private constructor() {
ADLoadingDialog.hide()
currentRewardedAd = null
currentAdUnitId = null
readyCallback.invoke()
showAdInternal(activity, ad, finalAdUnitId, onRewardEarned, closeCallback)
} else {
ADLoadingDialog.hide()

View File

@ -131,7 +131,7 @@ class TopOnRewardedAdController private constructor() {
activity: Activity,
placementId: String? = null,
onRewardEarned: ((String, Int, Double) -> Unit)? = null,
closeCallback: ()->Unit
closeCallback: ()->Unit, readyCallback:() -> Unit,
): AdResult<Unit> {
val finalPlacementId = resolvePlacementId(placementId)
if (finalPlacementId.isBlank()) {
@ -184,6 +184,7 @@ class TopOnRewardedAdController private constructor() {
if (entry != null && entry.ad.isAdReady) {
ADLoadingDialog.hide()
readyCallback.invoke()
AdLogger.d("TopOn使用缓存激励广告展示广告位ID: %s", finalPlacementId)
entry.listener.awaitShow(activity, onRewardEarned, closeCallback)
} else {