Skip to content

Commit

Permalink
Un-weakened PartnerAdListener and PartnerAd instances
Browse files Browse the repository at this point in the history
  • Loading branch information
chauduyphanvu committed Jan 25, 2024
1 parent e0a145b commit cb82528
Showing 1 changed file with 51 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ class AdMobAdapter : PartnerAdapter {

interstitial.fullScreenContentCallback =
InterstitialAdShowCallback(
WeakReference(listener),
WeakReference(partnerAd),
listener,
partnerAd,
WeakReference(continuation),
)
interstitial.show(context)
Expand Down Expand Up @@ -804,8 +804,8 @@ class AdMobAdapter : PartnerAdapter {

rewardedAd.fullScreenContentCallback =
RewardedAdShowCallback(
WeakReference(listener),
WeakReference(partnerAd),
listener,
partnerAd,
WeakReference(continuation),
)

Expand Down Expand Up @@ -863,8 +863,8 @@ class AdMobAdapter : PartnerAdapter {

rewardedInterstitialAd.fullScreenContentCallback =
RewardedInterstitialAdShowCallback(
WeakReference(listener),
WeakReference(partnerAd),
listener,
partnerAd,
WeakReference(continuation),
)

Expand Down Expand Up @@ -976,26 +976,20 @@ class AdMobAdapter : PartnerAdapter {
/**
* Callback class for interstitial ads.
*
* @param listenerRef A [WeakReference] to the [PartnerAdListener] to be notified of ad events.
* @param partnerAdRef A [WeakReference] to the [PartnerAd] object containing the AdMob ad to be shown.
* @param listener A [PartnerAdListener] to be notified of ad events.
* @param partnerAd A [PartnerAd] object containing the AdMob ad to be shown.
* @param continuationRef A [WeakReference] to the [CancellableContinuation] to be resumed once the ad is shown.
*/
private class InterstitialAdShowCallback(
private val listenerRef: WeakReference<PartnerAdListener?>,
private val partnerAdRef: WeakReference<PartnerAd>,
private val listener: PartnerAdListener?,
private val partnerAd: PartnerAd,
private val continuationRef: WeakReference<CancellableContinuation<Result<PartnerAd>>>,
) : FullScreenContentCallback() {
override fun onAdImpression() {
PartnerLogController.log(DID_TRACK_IMPRESSION)

partnerAdRef.get()?.let {
listenerRef.get()?.onPartnerAdImpression(it) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdImpression for AdMob adapter. Listener is null",
)
} ?: PartnerLogController.log(
listener?.onPartnerAdImpression(partnerAd) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdImpression for AdMob adapter. PartnerAd is null",
"Unable to fire onPartnerAdImpression for AdMob adapter. Listener is null",
)
}

Expand All @@ -1020,73 +1014,51 @@ private class InterstitialAdShowCallback(
override fun onAdShowedFullScreenContent() {
PartnerLogController.log(SHOW_SUCCEEDED)

partnerAdRef.get()?.let {
continuationRef.get()?.let { continuation ->
if (continuation.isActive) {
continuation.resume(Result.success(it))
}
} ?: PartnerLogController.log(
CUSTOM,
"Unable to resume continuation in onAdShowedFullScreenContent(). Continuation is null.",
)
continuationRef.get()?.let { continuation ->
if (continuation.isActive) {
continuation.resume(Result.success(partnerAd))
}
} ?: PartnerLogController.log(
CUSTOM,
"Unable to resume continuation in onAdShowedFullScreenContent(). PartnerAd is null.",
"Unable to resume continuation in onAdShowedFullScreenContent(). Continuation is null.",
)
}

override fun onAdClicked() {
PartnerLogController.log(DID_CLICK)

partnerAdRef.get()?.let {
listenerRef.get()?.onPartnerAdClicked(it) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdClicked for AdMob adapter. Listener is null",
)
} ?: PartnerLogController.log(
listener?.onPartnerAdClicked(partnerAd) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdClicked for AdMob adapter. PartnerAd is null",
"Unable to fire onPartnerAdClicked for AdMob adapter. Listener is null",
)
}

override fun onAdDismissedFullScreenContent() {
PartnerLogController.log(DID_DISMISS)

partnerAdRef.get()?.let {
listenerRef.get()?.onPartnerAdDismissed(it, null) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdDismissed for AdMob adapter. Listener is null",
)
} ?: PartnerLogController.log(
listener?.onPartnerAdDismissed(partnerAd, null) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdDismissed for AdMob adapter. PartnerAd is null",
"Unable to fire onPartnerAdDismissed for AdMob adapter. Listener is null",
)
}
}

/**
* Callback class for rewarded ads.
*
* @param listenerRef A [WeakReference] to the [PartnerAdListener] to be notified of ad events.
* @param partnerAdRef A [WeakReference] to the [PartnerAd] object containing the AdMob ad to be shown.
* @param listener A [PartnerAdListener] to be notified of ad events.
* @param partnerAd A [PartnerAd] object containing the AdMob ad to be shown.
* @param continuationRef A [WeakReference] to the [CancellableContinuation] to be resumed once the ad is shown.
*/
private class RewardedAdShowCallback(
private val listenerRef: WeakReference<PartnerAdListener?>,
private val partnerAdRef: WeakReference<PartnerAd>,
private val listener: PartnerAdListener?,
private val partnerAd: PartnerAd,
private val continuationRef: WeakReference<CancellableContinuation<Result<PartnerAd>>>,
) : FullScreenContentCallback() {
override fun onAdImpression() {
PartnerLogController.log(DID_TRACK_IMPRESSION)

partnerAdRef.get()?.let {
listenerRef.get()?.onPartnerAdImpression(it) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdImpression for AdMob adapter. Listener is null",
)
} ?: PartnerLogController.log(
listener?.onPartnerAdImpression(partnerAd) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdImpression for AdMob adapter. PartnerAd is null",
"Unable to fire onPartnerAdImpression for AdMob adapter. Listener is null",
)
}

Expand All @@ -1111,73 +1083,52 @@ private class RewardedAdShowCallback(
override fun onAdShowedFullScreenContent() {
PartnerLogController.log(SHOW_SUCCEEDED)

partnerAdRef.get()?.let {
continuationRef.get()?.let { continuation ->
if (continuation.isActive) {
continuation.resume(Result.success(it))
}
} ?: PartnerLogController.log(
CUSTOM,
"Unable to resume continuation in onAdShowedFullScreenContent(). Continuation is null.",
)
continuationRef.get()?.let { continuation ->
if (continuation.isActive) {
continuation.resume(Result.success(partnerAd))
}
} ?: PartnerLogController.log(
CUSTOM,
"Unable to resume continuation in onAdShowedFullScreenContent(). PartnerAd is null.",
"Unable to resume continuation in onAdShowedFullScreenContent(). Continuation is null.",
)
}

override fun onAdClicked() {
PartnerLogController.log(DID_CLICK)

partnerAdRef.get()?.let {
listenerRef.get()?.onPartnerAdClicked(it) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdClicked for AdMob adapter. Listener is null",
)
} ?: PartnerLogController.log(
listener?.onPartnerAdClicked(partnerAd) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdClicked for AdMob adapter. PartnerAd is null",
"Unable to fire onPartnerAdClicked for AdMob adapter. Listener is null",
)
}

override fun onAdDismissedFullScreenContent() {
PartnerLogController.log(DID_DISMISS)

partnerAdRef.get()?.let {
listenerRef.get()?.onPartnerAdDismissed(it, null) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdDismissed for AdMob adapter. Listener is null",
)
} ?: PartnerLogController.log(
listener?.onPartnerAdDismissed(partnerAd, null) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdDismissed for AdMob adapter. PartnerAd is null",
"Unable to fire onPartnerAdDismissed for AdMob adapter. Listener is null",
)
}
}

/**
* Callback class for rewarded interstitial ads.
*
* @param listenerRef A [WeakReference] to the [PartnerAdListener] to be notified of ad events.
* @param partnerAdRef A [WeakReference] to the [PartnerAd] object containing the AdMob ad to be shown.
* @param listener A [PartnerAdListener] to be notified of ad events.
* @param partnerAd A [PartnerAd] object containing the AdMob ad to be shown.
* @param continuationRef A [WeakReference] to the [CancellableContinuation] to be resumed once the ad is shown.
*/
private class RewardedInterstitialAdShowCallback(
private val listenerRef: WeakReference<PartnerAdListener?>,
private val partnerAdRef: WeakReference<PartnerAd>,
private val listener: PartnerAdListener?,
private val partnerAd: PartnerAd,
private val continuationRef: WeakReference<CancellableContinuation<Result<PartnerAd>>>,
) : FullScreenContentCallback() {
override fun onAdImpression() {
PartnerLogController.log(DID_TRACK_IMPRESSION)

partnerAdRef.get()?.let {
listenerRef.get()?.onPartnerAdImpression(it) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdImpression for AdMob adapter. Listener is null",
)
} ?: PartnerLogController.log(
listener?.onPartnerAdImpression(partnerAd) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdImpression for AdMob adapter. PartnerAd is null",
"Unable to fire onPartnerAdImpression for AdMob adapter. Listener is null",
)
}

Expand All @@ -1201,47 +1152,31 @@ private class RewardedInterstitialAdShowCallback(

override fun onAdShowedFullScreenContent() {
PartnerLogController.log(SHOW_SUCCEEDED)

partnerAdRef.get()?.let {
continuationRef.get()?.let { continuation ->
if (continuation.isActive) {
continuation.resume(Result.success(it))
}
} ?: PartnerLogController.log(
CUSTOM,
"Unable to resume continuation in onAdShowedFullScreenContent(). Continuation is null.",
)
continuationRef.get()?.let { continuation ->
if (continuation.isActive) {
continuation.resume(Result.success(partnerAd))
}
} ?: PartnerLogController.log(
CUSTOM,
"Unable to resume continuation in onAdShowedFullScreenContent(). PartnerAd is null.",
"Unable to resume continuation in onAdShowedFullScreenContent(). Continuation is null.",
)
}

override fun onAdClicked() {
PartnerLogController.log(DID_CLICK)

partnerAdRef.get()?.let {
listenerRef.get()?.onPartnerAdClicked(it) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdClicked for AdMob adapter. Listener is null",
)
} ?: PartnerLogController.log(
listener?.onPartnerAdClicked(partnerAd) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdClicked for AdMob adapter. PartnerAd is null",
"Unable to fire onPartnerAdClicked for AdMob adapter. Listener is null",
)
}

override fun onAdDismissedFullScreenContent() {
PartnerLogController.log(DID_DISMISS)

partnerAdRef.get()?.let {
listenerRef.get()?.onPartnerAdDismissed(it, null) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdDismissed for AdMob adapter. Listener is null",
)
} ?: PartnerLogController.log(
listener?.onPartnerAdDismissed(partnerAd, null) ?: PartnerLogController.log(
CUSTOM,
"Unable to fire onPartnerAdDismissed for AdMob adapter. PartnerAd is null",
"Unable to fire onPartnerAdDismissed for AdMob adapter. Listener is null",
)
}
}

0 comments on commit cb82528

Please sign in to comment.