3秒钟 还未成功,就退出 不显示广告
This commit is contained in:
parent
fa18c550ed
commit
7b86f83177
|
|
@ -22,6 +22,7 @@ import com.remax.bill.ads.ext.AdShowExt
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import com.viddin.videos.free.R
|
||||||
import com.viddin.videos.free.databinding.ActivityWatchAdBinding as ViewBinding
|
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 {
|
class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyleListener {
|
||||||
|
|
||||||
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
|
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
|
||||||
|
private var mIsLoadSuccess: Boolean = false
|
||||||
private var mRewardedDollarNum: Double = 0.0
|
private var mRewardedDollarNum: Double = 0.0
|
||||||
override var mEnableBannerAd = false
|
override var mEnableBannerAd = false
|
||||||
|
|
||||||
|
|
@ -177,18 +179,27 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
|
binding.root.postDelayed({
|
||||||
|
if (!mIsLoadSuccess) {
|
||||||
|
handleLoadFailed()
|
||||||
|
}
|
||||||
|
}, 3000)
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
when(AdShowExt.showRewardedVideoAd(this@WatchAdActivity, { rewardedData ->
|
when(AdShowExt.showRewardedVideoAd(this@WatchAdActivity, { rewardedData ->
|
||||||
mRewardedDollarNum = rewardedData.rewardNum
|
mRewardedDollarNum = rewardedData.rewardNum
|
||||||
}, {
|
}, {
|
||||||
notifyAdWatchFinish()
|
notifyAdWatchFinish()
|
||||||
|
}, {
|
||||||
|
mIsLoadSuccess = true
|
||||||
})) {
|
})) {
|
||||||
is AdResult.Success -> {
|
is AdResult.Success -> {
|
||||||
val temp = 111
|
mIsLoadSuccess = true
|
||||||
}
|
}
|
||||||
|
|
||||||
is AdResult.Failure -> {
|
is AdResult.Failure -> {
|
||||||
val temp = 111
|
handleLoadFailed()
|
||||||
}
|
}
|
||||||
|
|
||||||
AdResult.Loading -> {
|
AdResult.Loading -> {
|
||||||
|
|
@ -202,6 +213,10 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleLoadFailed() {
|
||||||
|
AndroidUtil.showToast(R.string.ad_load_fail)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
||||||
|
|
@ -64,4 +64,8 @@
|
||||||
<string name="has_claim_box_cash_hint">Has claimed %s cash successfully.</string>
|
<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="watch_full_reward_ad_hint">Watch the full video to get rewards!</string>
|
||||||
|
|
||||||
|
<string name="ad_load_fail">Ad failed to load</string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -236,5 +236,6 @@
|
||||||
<string name="withdraw_fail_dailog_common_hint">Retirada falhou. Verifique o histórico de retiradas para detalhes.</string>
|
<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="not_enough_gold">Não tens ouro suficiente.</string>
|
||||||
|
|
||||||
|
<string name="ad_load_fail">O anúncio não carregou</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -136,7 +136,8 @@ class RewardedAdController private constructor() {
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
adUnitId: String? = null,
|
adUnitId: String? = null,
|
||||||
onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)? = null,
|
onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)? = null,
|
||||||
closeCallback: () -> Unit
|
closeCallback: () -> Unit,
|
||||||
|
readyCallback:() -> Unit,
|
||||||
): AdResult<Unit> {
|
): AdResult<Unit> {
|
||||||
val finalAdUnitId = adUnitId ?: BuildConfig.ADMOB_REWARDED_ID
|
val finalAdUnitId = adUnitId ?: BuildConfig.ADMOB_REWARDED_ID
|
||||||
|
|
||||||
|
|
@ -190,6 +191,7 @@ class RewardedAdController private constructor() {
|
||||||
|
|
||||||
if (cachedAd != null) {
|
if (cachedAd != null) {
|
||||||
ADLoadingDialog.hide()
|
ADLoadingDialog.hide()
|
||||||
|
readyCallback.invoke()
|
||||||
AdLogger.d("Admob使用缓存中的激励广告,广告位ID: %s", finalAdUnitId)
|
AdLogger.d("Admob使用缓存中的激励广告,广告位ID: %s", finalAdUnitId)
|
||||||
|
|
||||||
// 3. 显示广告
|
// 3. 显示广告
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,8 @@ object AdShowExt {
|
||||||
suspend fun showRewardedVideoAd(
|
suspend fun showRewardedVideoAd(
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
rewardCallback: ((CommonRewardedData) -> Unit)? = null,
|
rewardCallback: ((CommonRewardedData) -> Unit)? = null,
|
||||||
closeCallback: ()->Unit
|
closeCallback: ()->Unit,
|
||||||
|
readyCallback:() -> Unit,
|
||||||
): AdResult<Unit> {
|
): AdResult<Unit> {
|
||||||
AdLogger.d("激励视频广告竞价开始")
|
AdLogger.d("激励视频广告竞价开始")
|
||||||
val winner = RewardedBiddingManager.bidding(activity)
|
val winner = RewardedBiddingManager.bidding(activity)
|
||||||
|
|
@ -312,7 +313,7 @@ object AdShowExt {
|
||||||
{ rewardItem, commonRewardedData ->
|
{ rewardItem, commonRewardedData ->
|
||||||
rewardCallback?.invoke(commonRewardedData)
|
rewardCallback?.invoke(commonRewardedData)
|
||||||
AdLogger.e("AdMob激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
|
AdLogger.e("AdMob激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
|
||||||
}, closeCallback
|
}, closeCallback, readyCallback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
BiddingWinner.PANGLE -> {
|
BiddingWinner.PANGLE -> {
|
||||||
|
|
@ -323,7 +324,7 @@ object AdShowExt {
|
||||||
{ pagRewardItem, commonRewardedData ->
|
{ pagRewardItem, commonRewardedData ->
|
||||||
rewardCallback?.invoke(commonRewardedData)
|
rewardCallback?.invoke(commonRewardedData)
|
||||||
AdLogger.e("Pangle激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
|
AdLogger.e("Pangle激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
|
||||||
}, closeCallback
|
}, closeCallback, readyCallback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
BiddingWinner.TOPON -> {
|
BiddingWinner.TOPON -> {
|
||||||
|
|
@ -336,7 +337,7 @@ object AdShowExt {
|
||||||
rewardCallback?.invoke(rewardedData)
|
rewardCallback?.invoke(rewardedData)
|
||||||
//xxxx
|
//xxxx
|
||||||
AdLogger.e("TopOn激励视频奖励回调, 奖励值:$revenueValue")
|
AdLogger.e("TopOn激励视频奖励回调, 奖励值:$revenueValue")
|
||||||
}, closeCallback
|
}, closeCallback, readyCallback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ class PangleRewardedAdController private constructor() {
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
adUnitId: String? = null,
|
adUnitId: String? = null,
|
||||||
onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)? = null,
|
onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)? = null,
|
||||||
closeCallback: () -> Unit
|
closeCallback: () -> Unit, readyCallback:() -> Unit,
|
||||||
): AdResult<Unit> {
|
): AdResult<Unit> {
|
||||||
val finalAdUnitId = adUnitId ?: BuildConfig.PANGLE_REWARDED_ID
|
val finalAdUnitId = adUnitId ?: BuildConfig.PANGLE_REWARDED_ID
|
||||||
|
|
||||||
|
|
@ -149,6 +149,7 @@ class PangleRewardedAdController private constructor() {
|
||||||
ADLoadingDialog.hide()
|
ADLoadingDialog.hide()
|
||||||
currentRewardedAd = null
|
currentRewardedAd = null
|
||||||
currentAdUnitId = null
|
currentAdUnitId = null
|
||||||
|
readyCallback.invoke()
|
||||||
showAdInternal(activity, ad, finalAdUnitId, onRewardEarned, closeCallback)
|
showAdInternal(activity, ad, finalAdUnitId, onRewardEarned, closeCallback)
|
||||||
} else {
|
} else {
|
||||||
ADLoadingDialog.hide()
|
ADLoadingDialog.hide()
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ class TopOnRewardedAdController private constructor() {
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
placementId: String? = null,
|
placementId: String? = null,
|
||||||
onRewardEarned: ((String, Int, Double) -> Unit)? = null,
|
onRewardEarned: ((String, Int, Double) -> Unit)? = null,
|
||||||
closeCallback: ()->Unit
|
closeCallback: ()->Unit, readyCallback:() -> Unit,
|
||||||
): AdResult<Unit> {
|
): AdResult<Unit> {
|
||||||
val finalPlacementId = resolvePlacementId(placementId)
|
val finalPlacementId = resolvePlacementId(placementId)
|
||||||
if (finalPlacementId.isBlank()) {
|
if (finalPlacementId.isBlank()) {
|
||||||
|
|
@ -184,6 +184,7 @@ class TopOnRewardedAdController private constructor() {
|
||||||
|
|
||||||
if (entry != null && entry.ad.isAdReady) {
|
if (entry != null && entry.ad.isAdReady) {
|
||||||
ADLoadingDialog.hide()
|
ADLoadingDialog.hide()
|
||||||
|
readyCallback.invoke()
|
||||||
AdLogger.d("TopOn使用缓存激励广告展示,广告位ID: %s", finalPlacementId)
|
AdLogger.d("TopOn使用缓存激励广告展示,广告位ID: %s", finalPlacementId)
|
||||||
entry.listener.awaitShow(activity, onRewardEarned, closeCallback)
|
entry.listener.awaitShow(activity, onRewardEarned, closeCallback)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue