激励视频广告
This commit is contained in:
parent
867c075794
commit
c981ffe950
|
|
@ -4,7 +4,6 @@ import android.app.Activity
|
|||
import android.content.Intent
|
||||
import android.os.CountDownTimer
|
||||
import android.view.LayoutInflater
|
||||
import androidx.activity.addCallback
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.updatePadding
|
||||
|
|
@ -17,7 +16,6 @@ import com.gamedog.vididin.VididinEvents
|
|||
import com.gamedog.vididin.beans.WatchAdNotifyBean
|
||||
import com.gamedog.vididin.main.interfaces.OnTabStyleListener
|
||||
import com.gamedog.vididin.manager.WithdrawItemBean
|
||||
import com.remax.bill.ads.AdResult
|
||||
import com.remax.bill.ads.ext.AdShowExt
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -51,11 +49,13 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
|||
}
|
||||
|
||||
override fun ViewBinding.initListeners() {
|
||||
onBackPressedDispatcher.addCallback(this@WatchAdActivity) {
|
||||
/*onBackPressedDispatcher.addCallback(this@WatchAdActivity) {
|
||||
AndroidUtil.showToast("Can't exit while watching video")
|
||||
}
|
||||
}*/
|
||||
|
||||
stateCounter()
|
||||
|
||||
showVideoAd()
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
|||
}
|
||||
|
||||
private fun stateCounter() {
|
||||
mCountDownTimer = object : CountDownTimer(3000, 1000) {
|
||||
mCountDownTimer = object : CountDownTimer(50* 1000, 1000) {
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
val secondsRemaining = millisUntilFinished / 1000
|
||||
binding.tvAdCounter.text = "${secondsRemaining}"
|
||||
|
|
@ -156,16 +156,22 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
|||
}
|
||||
|
||||
|
||||
private fun showVideoAd(callback: () -> Unit) {
|
||||
private fun showVideoAd() {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
AdShowExt.showRewardedVideoAd(this@WatchAdActivity, null)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
/*try {
|
||||
when (val result = AdShowExt.showInterstitialAd(this@WatchAdActivity)) {
|
||||
is AdResult.Success -> {
|
||||
callback.invoke()
|
||||
//callback.invoke()
|
||||
}
|
||||
|
||||
is AdResult.Failure -> {
|
||||
callback.invoke()
|
||||
//callback.invoke()
|
||||
}
|
||||
|
||||
AdResult.Loading -> {
|
||||
|
|
@ -173,12 +179,13 @@ class WatchAdActivity : AppViewsEmptyViewModelActivity<ViewBinding>(), OnTabStyl
|
|||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
callback.invoke()
|
||||
}
|
||||
//callback.invoke()
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
private val KEY_TASK_TYPE = "KEY_TASK_TYPE"
|
||||
private val KEY_TASK_DATA = "KEY_TASK_DATA"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,13 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/ad_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/tv_ad_counter"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.remax.bill.ads.bidding
|
||||
|
||||
import android.app.Activity
|
||||
import com.blankj.utilcode.util.ToastUtils
|
||||
import android.content.Context
|
||||
import com.remax.base.report.DataReportManager
|
||||
import com.remax.bill.BuildConfig
|
||||
import com.remax.bill.ads.RewardedAdController
|
||||
|
|
@ -12,7 +12,6 @@ import com.remax.bill.ads.util.AdmobReflectionUtil
|
|||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import java.util.Locale
|
||||
import kotlin.text.toDouble
|
||||
|
||||
/**
|
||||
* 激励广告竞价控制器
|
||||
|
|
@ -20,7 +19,7 @@ import kotlin.text.toDouble
|
|||
object RewardedBiddingManager {
|
||||
|
||||
suspend fun bidding(
|
||||
activity: Activity,
|
||||
context: Context,
|
||||
admobAdUnitId: String = BuildConfig.ADMOB_REWARDED_ID,
|
||||
pangleAdUnitId: String = BuildConfig.PANGLE_REWARDED_ID,
|
||||
toponPlacementId: String = BuildConfig.TOPON_REWARDED_ID,
|
||||
|
|
@ -35,22 +34,22 @@ object RewardedBiddingManager {
|
|||
AdSourceController.AdSource.TOPON -> BiddingWinner.TOPON
|
||||
AdSourceController.AdSource.BIDDING -> {
|
||||
// 不会执行到这里,但为了完整性保留
|
||||
performBidding(activity, admobAdUnitId, pangleAdUnitId, toponPlacementId)
|
||||
performBidding(context, admobAdUnitId, pangleAdUnitId, toponPlacementId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用竞价逻辑
|
||||
return performBidding(activity, admobAdUnitId, pangleAdUnitId, toponPlacementId)
|
||||
return performBidding(context, admobAdUnitId, pangleAdUnitId, toponPlacementId)
|
||||
}
|
||||
|
||||
private suspend fun performBidding(
|
||||
activity: Activity,
|
||||
context: Context,
|
||||
admobAdUnitId: String,
|
||||
pangleAdUnitId: String,
|
||||
toponPlacementId: String,
|
||||
): BiddingWinner {
|
||||
val context = activity.applicationContext
|
||||
val context = context.applicationContext
|
||||
val admobController = RewardedAdController.getInstance()
|
||||
val pangleController = PangleRewardedAdController.getInstance()
|
||||
val toponController = TopOnRewardedAdController.getInstance()
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.app.Activity
|
|||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.gms.ads.rewarded.RewardItem
|
||||
import com.remax.bill.BuildConfig
|
||||
import com.remax.bill.ads.AdResult
|
||||
import com.remax.bill.ads.AppOpenAdController
|
||||
|
|
@ -11,23 +12,27 @@ import com.remax.bill.ads.BannerAdController
|
|||
import com.remax.bill.ads.FullScreenNativeAdController
|
||||
import com.remax.bill.ads.InterstitialAdController
|
||||
import com.remax.bill.ads.NativeAdController
|
||||
import com.remax.bill.ads.RewardedAdController
|
||||
import com.remax.bill.ads.bidding.AppOpenBiddingManager
|
||||
import com.remax.bill.ads.bidding.BannerBiddingManager
|
||||
import com.remax.bill.ads.bidding.BiddingWinner
|
||||
import com.remax.bill.ads.bidding.FullScreenNativeBiddingManager
|
||||
import com.remax.bill.ads.bidding.InterstitialBiddingManager
|
||||
import com.remax.bill.ads.bidding.NativeBiddingManager
|
||||
import com.remax.bill.ads.bidding.RewardedBiddingManager
|
||||
import com.remax.bill.ads.log.AdLogger
|
||||
import com.remax.bill.ads.pangle.PangleAppOpenAdController
|
||||
import com.remax.bill.ads.pangle.PangleBannerAdController
|
||||
import com.remax.bill.ads.pangle.PangleFullScreenNativeAdController
|
||||
import com.remax.bill.ads.pangle.PangleInterstitialAdController
|
||||
import com.remax.bill.ads.pangle.PangleNativeAdController
|
||||
import com.remax.bill.ads.pangle.PangleRewardedAdController
|
||||
import com.remax.bill.ads.topon.TopOnBannerAdController
|
||||
import com.remax.bill.ads.topon.TopOnFullScreenNativeAdController
|
||||
import com.remax.bill.ads.topon.TopOnInterstitialAdController
|
||||
import com.remax.bill.ads.topon.TopOnSplashAdController
|
||||
import com.remax.bill.ads.topon.TopOnNativeAdController
|
||||
import com.remax.bill.ads.topon.TopOnRewardedAdController
|
||||
import com.remax.bill.ui.FullScreenNativeAdActivity
|
||||
import com.remax.bill.ui.NativeAdStyle
|
||||
import com.remax.bill.ui.pangle.PangleFullScreenNativeAdActivity
|
||||
|
|
@ -275,4 +280,54 @@ object AdShowExt {
|
|||
TopOnInterstitialAdController.getInstance().isAdShowing() ||
|
||||
TopOnFullScreenNativeAdController.getInstance().isAdShowing()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ==================== 原生广告 ====================
|
||||
|
||||
/**
|
||||
* 在容器中展示原生激励视频广告(带竞价)
|
||||
* @param activity Context
|
||||
* @param container 广告容器
|
||||
* @param style 广告样式
|
||||
* @return Boolean 是否展示成功
|
||||
*/
|
||||
suspend fun showRewardedVideoAd(
|
||||
activity: Activity,
|
||||
rewardCallback: ((RewardItem) -> Unit)? = null
|
||||
): AdResult<Unit> {
|
||||
AdLogger.d("激励视频广告竞价开始")
|
||||
val winner = RewardedBiddingManager.bidding(activity)
|
||||
AdLogger.d("激励视频广告竞价结果: $winner")
|
||||
|
||||
return when (winner) {
|
||||
BiddingWinner.ADMOB -> {
|
||||
AdLogger.d("使用 AdMob 展示激励视频广告")
|
||||
RewardedAdController.getInstance().showAd(
|
||||
activity,
|
||||
"",
|
||||
rewardCallback
|
||||
)
|
||||
}
|
||||
BiddingWinner.PANGLE -> {
|
||||
AdLogger.d("使用 Pangle 展示激励视频广告")
|
||||
PangleRewardedAdController.getInstance().showAd(
|
||||
activity,
|
||||
"",
|
||||
null
|
||||
)
|
||||
}
|
||||
BiddingWinner.TOPON -> {
|
||||
AdLogger.d("使用 TopOn 展示激励视频广告")
|
||||
TopOnRewardedAdController.getInstance().showAd(
|
||||
activity,
|
||||
"",
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue