激励ad 关闭回调
This commit is contained in:
parent
e251550ffb
commit
2c0a52ec48
|
|
@ -50,7 +50,7 @@
|
|||
<activity android:name="com.gamedog.vididin.features.feedback.FeedbackActivity" android:exported="false" />
|
||||
<activity android:name="com.gamedog.vididin.features.withdrawrecord.WithdrawRecordActivity" android:exported="false" />
|
||||
<activity android:name="com.gamedog.vididin.features.privacy.PrivacyActivity" android:exported="false" />
|
||||
<activity android:name="com.gamedog.vididin.features.watchad.WatchAdActivity" android:exported="false" />
|
||||
<activity android:name="com.gamedog.vididin.features.watchad.WatchAdActivity" android:screenOrientation="portrait" android:exported="false" />
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -119,6 +119,8 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), 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<ViewBinding>(), OnTabStyl
|
|||
}
|
||||
|
||||
override fun onFinish() {
|
||||
notifyAdWatchFinish()
|
||||
finish()
|
||||
|
||||
}
|
||||
}
|
||||
mCountDownTimer.start()
|
||||
|
|
@ -163,10 +164,11 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), 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<ViewBinding>(), 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()
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Unit> {
|
||||
suspend fun showAd(
|
||||
activity: Activity,
|
||||
adUnitId: String? = null,
|
||||
onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)? = null,
|
||||
closeCallback: () -> Unit
|
||||
): AdResult<Unit> {
|
||||
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<Unit> {
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -294,7 +294,8 @@ object AdShowExt {
|
|||
*/
|
||||
suspend fun showRewardedVideoAd(
|
||||
activity: Activity,
|
||||
rewardCallback: ((CommonRewardedData) -> Unit)? = null
|
||||
rewardCallback: ((CommonRewardedData) -> Unit)? = null,
|
||||
closeCallback: ()->Unit
|
||||
): AdResult<Unit> {
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Unit> {
|
||||
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<Unit> {
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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<Unit> {
|
||||
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<TopOnRewardedAdEntry?>) {
|
||||
loadContinuation = continuation
|
||||
|
|
@ -324,13 +325,18 @@ class TopOnRewardedAdController private constructor() {
|
|||
showContinuation = null
|
||||
}
|
||||
|
||||
suspend fun awaitShow(activity: Activity, onRewardEarned: ((String, Int, Double) -> Unit)?): AdResult<Unit> {
|
||||
suspend fun awaitShow(
|
||||
activity: Activity,
|
||||
onRewardEarned: ((String, Int, Double) -> Unit)?,
|
||||
closeCallback: () -> Unit
|
||||
): AdResult<Unit> {
|
||||
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))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue