激励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.feedback.FeedbackActivity" android:exported="false" />
|
||||||
<activity android:name="com.gamedog.vididin.features.withdrawrecord.WithdrawRecordActivity" 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.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) {
|
if (shouldNotifyOneAdWatched) {
|
||||||
NotifyMan.instance().sendEvent(VididinEvents.EVENT_FINISHED_ONE_AD, NotifyMan.NotifyData(1))
|
NotifyMan.instance().sendEvent(VididinEvents.EVENT_FINISHED_ONE_AD, NotifyMan.NotifyData(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stateCounter() {
|
private fun stateCounter() {
|
||||||
|
|
@ -129,8 +131,7 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFinish() {
|
override fun onFinish() {
|
||||||
notifyAdWatchFinish()
|
|
||||||
finish()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCountDownTimer.start()
|
mCountDownTimer.start()
|
||||||
|
|
@ -163,10 +164,11 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
||||||
try {
|
try {
|
||||||
when(AdShowExt.showRewardedVideoAd(this@WatchAdActivity, { rewardedData ->
|
when(AdShowExt.showRewardedVideoAd(this@WatchAdActivity, { rewardedData ->
|
||||||
mRewardedDollarNum = rewardedData.rewardNum
|
mRewardedDollarNum = rewardedData.rewardNum
|
||||||
|
}, {
|
||||||
|
notifyAdWatchFinish()
|
||||||
})) {
|
})) {
|
||||||
is AdResult.Success -> {
|
is AdResult.Success -> {
|
||||||
val temp = 111
|
val temp = 111
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is AdResult.Failure -> {
|
is AdResult.Failure -> {
|
||||||
|
|
@ -180,24 +182,6 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
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.log.AdLogger
|
||||||
import com.remax.bill.ads.util.PositionGet
|
import com.remax.bill.ads.util.PositionGet
|
||||||
import com.remax.bill.ui.dialog.ADLoadingDialog
|
import com.remax.bill.ui.dialog.ADLoadingDialog
|
||||||
import kotlinx.coroutines.SupervisorJob
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlin.math.ceil
|
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 kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import kotlin.also
|
import kotlin.also
|
||||||
import kotlin.collections.count
|
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
|
val finalAdUnitId = adUnitId ?: BuildConfig.ADMOB_REWARDED_ID
|
||||||
|
|
||||||
// 累积触发统计
|
// 累积触发统计
|
||||||
|
|
@ -194,7 +193,7 @@ class RewardedAdController private constructor() {
|
||||||
AdLogger.d("Admob使用缓存中的激励广告,广告位ID: %s", finalAdUnitId)
|
AdLogger.d("Admob使用缓存中的激励广告,广告位ID: %s", finalAdUnitId)
|
||||||
|
|
||||||
// 3. 显示广告
|
// 3. 显示广告
|
||||||
val result = showAdInternal(activity, cachedAd.ad, finalAdUnitId, onRewardEarned)
|
val result = showAdInternal(activity, cachedAd.ad, finalAdUnitId, onRewardEarned, closeCallback)
|
||||||
|
|
||||||
result
|
result
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -380,7 +379,8 @@ class RewardedAdController private constructor() {
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
rewardedAd: RewardedAd,
|
rewardedAd: RewardedAd,
|
||||||
adUnitId: String,
|
adUnitId: String,
|
||||||
onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)?
|
onRewardEarned: ((RewardItem, CommonRewardedData) -> Unit)?,
|
||||||
|
closeCallback: () -> Unit
|
||||||
): AdResult<Unit> {
|
): AdResult<Unit> {
|
||||||
return suspendCancellableCoroutine { continuation ->
|
return suspendCancellableCoroutine { continuation ->
|
||||||
var hasRewarded = false
|
var hasRewarded = false
|
||||||
|
|
@ -411,6 +411,8 @@ class RewardedAdController private constructor() {
|
||||||
if (continuation.isActive) {
|
if (continuation.isActive) {
|
||||||
continuation.resume(result)
|
continuation.resume(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeCallback.invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
|
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
|
||||||
|
|
|
||||||
|
|
@ -294,7 +294,8 @@ object AdShowExt {
|
||||||
*/
|
*/
|
||||||
suspend fun showRewardedVideoAd(
|
suspend fun showRewardedVideoAd(
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
rewardCallback: ((CommonRewardedData) -> Unit)? = null
|
rewardCallback: ((CommonRewardedData) -> Unit)? = null,
|
||||||
|
closeCallback: ()->Unit
|
||||||
): AdResult<Unit> {
|
): AdResult<Unit> {
|
||||||
AdLogger.d("激励视频广告竞价开始")
|
AdLogger.d("激励视频广告竞价开始")
|
||||||
val winner = RewardedBiddingManager.bidding(activity)
|
val winner = RewardedBiddingManager.bidding(activity)
|
||||||
|
|
@ -311,7 +312,7 @@ object AdShowExt {
|
||||||
{ rewardItem, commonRewardedData ->
|
{ rewardItem, commonRewardedData ->
|
||||||
rewardCallback?.invoke(commonRewardedData)
|
rewardCallback?.invoke(commonRewardedData)
|
||||||
AdLogger.e("AdMob激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
|
AdLogger.e("AdMob激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
|
||||||
}
|
}, closeCallback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
BiddingWinner.PANGLE -> {
|
BiddingWinner.PANGLE -> {
|
||||||
|
|
@ -322,7 +323,7 @@ object AdShowExt {
|
||||||
{ pagRewardItem, commonRewardedData ->
|
{ pagRewardItem, commonRewardedData ->
|
||||||
rewardCallback?.invoke(commonRewardedData)
|
rewardCallback?.invoke(commonRewardedData)
|
||||||
AdLogger.e("Pangle激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
|
AdLogger.e("Pangle激励视频奖励回调, 奖励值:${commonRewardedData.rewardNum}")
|
||||||
}
|
}, closeCallback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
BiddingWinner.TOPON -> {
|
BiddingWinner.TOPON -> {
|
||||||
|
|
@ -334,7 +335,7 @@ object AdShowExt {
|
||||||
val rewardedData = CommonRewardedData(revenueValue.toFloat())
|
val rewardedData = CommonRewardedData(revenueValue.toFloat())
|
||||||
rewardCallback?.invoke(rewardedData)
|
rewardCallback?.invoke(rewardedData)
|
||||||
AdLogger.e("TopOn激励视频奖励回调, 奖励值:$revenueValue")
|
AdLogger.e("TopOn激励视频奖励回调, 奖励值:$revenueValue")
|
||||||
}
|
}, closeCallback
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.roundToLong
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pangle激励视频广告控制器
|
* Pangle激励视频广告控制器
|
||||||
|
|
@ -102,7 +101,8 @@ class PangleRewardedAdController private constructor() {
|
||||||
suspend fun showAd(
|
suspend fun showAd(
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
adUnitId: String? = null,
|
adUnitId: String? = null,
|
||||||
onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)? = null
|
onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)? = null,
|
||||||
|
closeCallback: () -> Unit
|
||||||
): AdResult<Unit> {
|
): AdResult<Unit> {
|
||||||
val finalAdUnitId = adUnitId ?: BuildConfig.PANGLE_REWARDED_ID
|
val finalAdUnitId = adUnitId ?: BuildConfig.PANGLE_REWARDED_ID
|
||||||
|
|
||||||
|
|
@ -149,7 +149,7 @@ class PangleRewardedAdController private constructor() {
|
||||||
ADLoadingDialog.hide()
|
ADLoadingDialog.hide()
|
||||||
currentRewardedAd = null
|
currentRewardedAd = null
|
||||||
currentAdUnitId = null
|
currentAdUnitId = null
|
||||||
showAdInternal(activity, ad, finalAdUnitId, onRewardEarned)
|
showAdInternal(activity, ad, finalAdUnitId, onRewardEarned, closeCallback)
|
||||||
} else {
|
} else {
|
||||||
ADLoadingDialog.hide()
|
ADLoadingDialog.hide()
|
||||||
totalShowFailCount++
|
totalShowFailCount++
|
||||||
|
|
@ -249,7 +249,8 @@ class PangleRewardedAdController private constructor() {
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
rewardedAd: PAGRewardedAd,
|
rewardedAd: PAGRewardedAd,
|
||||||
adUnitId: String,
|
adUnitId: String,
|
||||||
onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)?
|
onRewardEarned: ((PAGRewardItem, CommonRewardedData) -> Unit)?,
|
||||||
|
closeCallback: () -> Unit
|
||||||
): AdResult<Unit> {
|
): AdResult<Unit> {
|
||||||
val applicationContext = activity.applicationContext
|
val applicationContext = activity.applicationContext
|
||||||
return suspendCancellableCoroutine { continuation ->
|
return suspendCancellableCoroutine { continuation ->
|
||||||
|
|
@ -351,6 +352,8 @@ class PangleRewardedAdController private constructor() {
|
||||||
if (continuation.isActive) {
|
if (continuation.isActive) {
|
||||||
continuation.resume(AdResult.Success(Unit))
|
continuation.resume(AdResult.Success(Unit))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeCallback.invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUserEarnedReward(rewardItem: PAGRewardItem) {
|
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.ads.RevenueInfo
|
||||||
import com.remax.base.ext.KvIntDelegate
|
import com.remax.base.ext.KvIntDelegate
|
||||||
import com.remax.base.report.DataReportManager
|
import com.remax.base.report.DataReportManager
|
||||||
import com.remax.bill.ads.PreloadController
|
|
||||||
import com.thinkup.core.api.AdError
|
import com.thinkup.core.api.AdError
|
||||||
import com.thinkup.core.api.TUAdInfo
|
import com.thinkup.core.api.TUAdInfo
|
||||||
import com.thinkup.core.api.TUAdRevenueListener
|
import com.thinkup.core.api.TUAdRevenueListener
|
||||||
|
|
@ -131,7 +130,8 @@ class TopOnRewardedAdController private constructor() {
|
||||||
suspend fun showAd(
|
suspend fun showAd(
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
placementId: String? = null,
|
placementId: String? = null,
|
||||||
onRewardEarned: ((String, Int, Double) -> Unit)? = null
|
onRewardEarned: ((String, Int, Double) -> Unit)? = null,
|
||||||
|
closeCallback: ()->Unit
|
||||||
): AdResult<Unit> {
|
): AdResult<Unit> {
|
||||||
val finalPlacementId = resolvePlacementId(placementId)
|
val finalPlacementId = resolvePlacementId(placementId)
|
||||||
if (finalPlacementId.isBlank()) {
|
if (finalPlacementId.isBlank()) {
|
||||||
|
|
@ -185,7 +185,7 @@ class TopOnRewardedAdController private constructor() {
|
||||||
if (entry != null && entry.ad.isAdReady) {
|
if (entry != null && entry.ad.isAdReady) {
|
||||||
ADLoadingDialog.hide()
|
ADLoadingDialog.hide()
|
||||||
AdLogger.d("TopOn使用缓存激励广告展示,广告位ID: %s", finalPlacementId)
|
AdLogger.d("TopOn使用缓存激励广告展示,广告位ID: %s", finalPlacementId)
|
||||||
entry.listener.awaitShow(activity, onRewardEarned)
|
entry.listener.awaitShow(activity, onRewardEarned, closeCallback)
|
||||||
} else {
|
} else {
|
||||||
ADLoadingDialog.hide()
|
ADLoadingDialog.hide()
|
||||||
AdResult.Failure(createAdException("广告加载失败"))
|
AdResult.Failure(createAdException("广告加载失败"))
|
||||||
|
|
@ -297,6 +297,7 @@ class TopOnRewardedAdController private constructor() {
|
||||||
private var cacheTime: Long = System.currentTimeMillis()
|
private var cacheTime: Long = System.currentTimeMillis()
|
||||||
private var hasRewarded: Boolean = false
|
private var hasRewarded: Boolean = false
|
||||||
private var rewardCallback: ((String, Int, Double) -> Unit)? = null
|
private var rewardCallback: ((String, Int, Double) -> Unit)? = null
|
||||||
|
private var closeCallback: (()->Unit)? = null
|
||||||
|
|
||||||
fun attachLoadContinuation(continuation: kotlinx.coroutines.CancellableContinuation<TopOnRewardedAdEntry?>) {
|
fun attachLoadContinuation(continuation: kotlinx.coroutines.CancellableContinuation<TopOnRewardedAdEntry?>) {
|
||||||
loadContinuation = continuation
|
loadContinuation = continuation
|
||||||
|
|
@ -324,13 +325,18 @@ class TopOnRewardedAdController private constructor() {
|
||||||
showContinuation = null
|
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) {
|
if (!rewardedVideoAd.isAdReady) {
|
||||||
AdLogger.w("TopOn激励广告未准备好,展示终止,广告位ID: %s", placementId)
|
AdLogger.w("TopOn激励广告未准备好,展示终止,广告位ID: %s", placementId)
|
||||||
return AdResult.Failure(createAdException("广告未准备好"))
|
return AdResult.Failure(createAdException("广告未准备好"))
|
||||||
}
|
}
|
||||||
|
|
||||||
rewardCallback = onRewardEarned
|
rewardCallback = onRewardEarned
|
||||||
|
this.closeCallback = closeCallback
|
||||||
hasRewarded = false
|
hasRewarded = false
|
||||||
|
|
||||||
return suspendCancellableCoroutine { continuation ->
|
return suspendCancellableCoroutine { continuation ->
|
||||||
|
|
@ -483,6 +489,7 @@ class TopOnRewardedAdController private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeCallback?.invoke()
|
||||||
resumeShow(AdResult.Success(Unit))
|
resumeShow(AdResult.Success(Unit))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue