Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewarded Ad Unit Enhancements #803

Merged
merged 15 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class AdMobVideoRewardedActivity : BaseAdActivity() {
override fun onAdLoaded(ad: RewardedAd) {
Log.d("AdMobRewarded", "Ad was loaded.")
rewardedAd = ad
rewardedAd?.show(this@AdMobVideoRewardedActivity) {}
rewardedAd?.show(this@AdMobVideoRewardedActivity) {
Log.d("AdExample", "User earned reward: ${it.amount} ${it.type}")
}
}

override fun onAdFailedToLoad(adError: LoadAdError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.prebid.mobile.prebidkotlindemo.activities.ads.applovin

import android.os.Bundle
import android.util.Log
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxError
import com.applovin.mediation.MaxReward
Expand Down Expand Up @@ -56,7 +57,9 @@ class AppLovinMaxVideoRewardedActivity : BaseAdActivity() {
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) {}
override fun onRewardedVideoStarted(ad: MaxAd?) {}
override fun onRewardedVideoCompleted(ad: MaxAd?) {}
override fun onUserRewarded(ad: MaxAd?, reward: MaxReward?) {}
override fun onUserRewarded(ad: MaxAd?, reward: MaxReward?) {
Log.d("AdExample", "User earned reward: $reward")
}
})

val mediationUtils = MaxMediationRewardedUtils(maxRewardedAd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package org.prebid.mobile.prebidkotlindemo.activities.ads.gam.rendering

import android.os.Bundle
import android.util.Log
import org.prebid.mobile.api.exceptions.AdException
import org.prebid.mobile.api.rendering.RewardedAdUnit
import org.prebid.mobile.api.rendering.listeners.RewardedAdUnitListener
import org.prebid.mobile.eventhandlers.GamRewardedEventHandler
import org.prebid.mobile.prebidkotlindemo.activities.BaseAdActivity
import org.prebid.mobile.rendering.interstitial.rewarded.Reward

class GamRenderingApiVideoRewardedActivity : BaseAdActivity() {

Expand All @@ -32,7 +34,7 @@ class GamRenderingApiVideoRewardedActivity : BaseAdActivity() {
private var adUnit: RewardedAdUnit? = null


override fun onCreate(savedInstanceState: Bundle?) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

createAd()
Expand All @@ -50,7 +52,9 @@ class GamRenderingApiVideoRewardedActivity : BaseAdActivity() {
override fun onAdFailed(rewardedAdUnit: RewardedAdUnit?, exception: AdException?) {}
override fun onAdClicked(rewardedAdUnit: RewardedAdUnit?) {}
override fun onAdClosed(rewardedAdUnit: RewardedAdUnit?) {}
override fun onUserEarnedReward(rewardedAdUnit: RewardedAdUnit?) {}
override fun onUserEarnedReward(rewardedAdUnit: RewardedAdUnit?, reward: Reward?) {
Log.d("AdExample", "User earned reward: $reward")
}
})
adUnit?.loadAd()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
package org.prebid.mobile.prebidkotlindemo.activities.ads.inapp

import android.os.Bundle
import android.util.Log
import org.prebid.mobile.api.exceptions.AdException
import org.prebid.mobile.api.rendering.RewardedAdUnit
import org.prebid.mobile.api.rendering.listeners.RewardedAdUnitListener
import org.prebid.mobile.prebidkotlindemo.activities.BaseAdActivity
import org.prebid.mobile.rendering.interstitial.rewarded.Reward

class InAppVideoRewardedActivity : BaseAdActivity() {

Expand Down Expand Up @@ -47,7 +49,9 @@ class InAppVideoRewardedActivity : BaseAdActivity() {
override fun onAdFailed(rewardedAdUnit: RewardedAdUnit?, exception: AdException?) {}
override fun onAdClicked(rewardedAdUnit: RewardedAdUnit?) {}
override fun onAdClosed(rewardedAdUnit: RewardedAdUnit?) {}
override fun onUserEarnedReward(rewardedAdUnit: RewardedAdUnit?) {}
override fun onUserEarnedReward(rewardedAdUnit: RewardedAdUnit?, reward: Reward?) {
Log.d("InAppVideoRewarded", "User earned reward: $reward")
}
})
adUnit?.loadAd()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class InternalTestApplication : MultiDexApplication() {
}

fun clearAdConfigSettings() {
PreferenceManager.getDefaultSharedPreferences(this).edit().clear().apply()
PreferenceManager.getDefaultSharedPreferences(this).edit().remove(getString(R.string.key_keep_settings)).apply()
}

private fun checkKeepConsentSettingsFlag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package org.prebid.mobile.renderingtestapp.plugplay.bidding.admob
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.google.android.gms.ads.AdError
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.FullScreenContentCallback
Expand All @@ -19,7 +17,6 @@ import org.prebid.mobile.renderingtestapp.R
import org.prebid.mobile.renderingtestapp.databinding.FragmentAdmobRewardedBinding
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment
import org.prebid.mobile.renderingtestapp.utils.BaseEvents
import org.prebid.mobile.renderingtestapp.widgets.EventCounterView

open class AdMobRewardedFragment : AdFragment() {

Expand Down Expand Up @@ -76,6 +73,9 @@ open class AdMobRewardedFragment : AdFragment() {

rewardedAd = ad
rewardedAd?.fullScreenContentCallback = createFullScreenContentCallback()
rewardedAd?.setOnPaidEventListener {
Log.d(TAG, "User earned reward: $it")
}
}

override fun onAdFailedToLoad(adError: LoadAdError) {
Expand Down Expand Up @@ -115,6 +115,7 @@ open class AdMobRewardedFragment : AdFragment() {
val rewardAmount = rewardItem.amount
val rewardType = rewardItem.type
Log.d(TAG, "User earned the reward ($rewardAmount, $rewardType)")
events.rewarded(true)
}
binding.btnLoad.text = getString(R.string.text_retry)
} else if (binding.btnLoad.text == getString(R.string.text_retry)) {
Expand Down Expand Up @@ -155,6 +156,7 @@ open class AdMobRewardedFragment : AdFragment() {
fun impression(b: Boolean) = enable(R.id.btnAdImpression, b)
fun clicked(b: Boolean) = enable(R.id.btnAdClicked, b)
fun failed(b: Boolean) = enable(R.id.btnAdFailed, b)
fun rewarded(b: Boolean) = enable(R.id.btnUserRewarded, b)

fun showed(b: Boolean) = enable(R.id.btnAdShowed, b)
fun dismissed(b: Boolean) = enable(R.id.btnAdDismissed, b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@ package org.prebid.mobile.renderingtestapp.plugplay.bidding.base
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import org.prebid.mobile.api.exceptions.AdException
import org.prebid.mobile.api.rendering.RewardedAdUnit
import org.prebid.mobile.api.rendering.listeners.RewardedAdUnitListener
import org.prebid.mobile.rendering.interstitial.rewarded.Reward
import org.prebid.mobile.renderingtestapp.AdFragment
import org.prebid.mobile.renderingtestapp.R
import org.prebid.mobile.renderingtestapp.databinding.FragmentBiddingInterstitialBinding
import org.prebid.mobile.renderingtestapp.databinding.FragmentBiddingRewardedBinding
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment
import org.prebid.mobile.renderingtestapp.utils.BaseEvents
import org.prebid.mobile.renderingtestapp.widgets.EventCounterView

abstract class BaseBidRewardedFragment : AdFragment() {

private val TAG = BaseBidRewardedFragment::class.java.simpleName

override val layoutRes = R.layout.fragment_bidding_interstitial
override val layoutRes = R.layout.fragment_bidding_rewarded
protected var rewardedAdUnit: RewardedAdUnit? = null

protected val binding: FragmentBiddingInterstitialBinding
protected val binding: FragmentBiddingRewardedBinding
get() = getBinding()
protected lateinit var events: Events

Expand Down Expand Up @@ -84,11 +83,10 @@ abstract class BaseBidRewardedFragment : AdFragment() {
}
}

protected fun createRewardedAdUnitListener() = object :
RewardedAdUnitListener {
protected fun createRewardedAdUnitListener() = object : RewardedAdUnitListener {

override fun onAdLoaded(rewardedAdUnit: RewardedAdUnit?) {
Log.d(TAG, "onAdLoaded() called with: reward = [${rewardedAdUnit?.userReward}]")
Log.d(TAG, "onAdLoaded() called")
events.loaded(true)
binding.btnLoad.setText(R.string.text_show)
binding.btnLoad.isEnabled = true
Expand All @@ -115,8 +113,9 @@ abstract class BaseBidRewardedFragment : AdFragment() {
events.closed(true)
}

override fun onUserEarnedReward(rewardedAdUnit: RewardedAdUnit?) {
Log.d(TAG, "onUserEarnedReward() called with: reward = [${rewardedAdUnit?.userReward}]")
override fun onUserEarnedReward(rewardedAdUnit: RewardedAdUnit?, reward: Reward?) {
Log.d(TAG, "User earned reward: $reward")
events.reward(true)
}

}
Expand All @@ -128,6 +127,7 @@ abstract class BaseBidRewardedFragment : AdFragment() {
fun clicked(b: Boolean) = enable(R.id.btnAdClicked, b)
fun closed(b: Boolean) = enable(R.id.btnAdClosed, b)
fun failed(b: Boolean) = enable(R.id.btnAdFailed, b)
fun reward(b: Boolean) = enable(R.id.btnReward, b)

fun displayed(b: Boolean) = enable(R.id.btnAdDisplayed, b)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package org.prebid.mobile.renderingtestapp.plugplay.bidding.max
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.TextView
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxError
import com.applovin.mediation.MaxReward
Expand All @@ -17,7 +15,6 @@ import org.prebid.mobile.renderingtestapp.R
import org.prebid.mobile.renderingtestapp.databinding.FragmentBiddingRewardedApplovinMaxBinding
import org.prebid.mobile.renderingtestapp.plugplay.config.AdConfiguratorDialogFragment
import org.prebid.mobile.renderingtestapp.utils.BaseEvents
import org.prebid.mobile.renderingtestapp.widgets.EventCounterView

open class MaxRewardedFragment : AdFragment() {

Expand Down Expand Up @@ -139,6 +136,7 @@ open class MaxRewardedFragment : AdFragment() {
}

override fun onUserRewarded(ad: MaxAd?, reward: MaxReward?) {
Log.d(TAG, "User earned reward: ${reward?.label} ${reward?.amount}")
events.userRewarded(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,125 @@ class DemoItemProvider private constructor() {
)
)

// Rewarded
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_display_rewarded_time),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_display_rewarded_time,
null,
320,
480
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_display_rewarded_event),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_display_rewarded_event,
null,
320,
480
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_display_rewarded_default),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_display_rewarded_default,
null,
320,
480
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_video_rewarded_time),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_video_rewarded_time,
null,
320,
480
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_video_rewarded_event),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_video_rewarded_event,
null,
320,
480
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_video_rewarded_default),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_video_rewarded_default,
null,
320,
480
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_video_rewarded_endcard_time),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_video_rewarded_endcard_time,
null,
320,
480
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_video_rewarded_endcard_event),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_video_rewarded_endcard_event,
null,
320,
480
)
)
)
demoList.add(
DemoItem(
getString(R.string.demo_bidding_in_app_video_rewarded_endcard_default),
ppmRewardedAction,
ppmVideoTagList,
createBannerBundle(
R.string.imp_prebid_id_video_rewarded_endcard_default,
null,
320,
480
)
)
)

// Native
demoList.add(
DemoItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@
android:text="@string/event_admob_failed"
android:layout_marginTop="@dimen/event_top_margin"/>

<org.prebid.mobile.renderingtestapp.widgets.EventCounterView
android:id="@+id/btnUserRewarded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/onUserRewarded"
android:layout_marginTop="@dimen/event_top_margin" />

</LinearLayout>
Loading