@capacitor-community/admob 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorCommunityAdmob.podspec +1 -1
- package/Package.swift +1 -1
- package/README.md +635 -169
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/getcapacitor/community/admob/AdMob.java +73 -23
- package/android/src/main/java/com/getcapacitor/community/admob/appopen/AppOpenAdManager.kt +92 -0
- package/android/src/main/java/com/getcapacitor/community/admob/appopen/AppOpenAdPlugin.kt +122 -0
- package/android/src/main/java/com/getcapacitor/community/admob/appopen/AppOpenAdPluginEvents.kt +10 -0
- package/android/src/main/java/com/getcapacitor/community/admob/banner/BannerAdPluginEvents.kt +2 -1
- package/android/src/main/java/com/getcapacitor/community/admob/banner/BannerExecutor.java +79 -29
- package/android/src/main/java/com/getcapacitor/community/admob/helpers/FullscreenPluginCallback.kt +7 -2
- package/android/src/main/java/com/getcapacitor/community/admob/interstitial/AdInterstitialExecutor.java +21 -3
- package/android/src/main/java/com/getcapacitor/community/admob/interstitial/InterstitialAdCallbackAndListeners.kt +12 -2
- package/android/src/main/java/com/getcapacitor/community/admob/interstitial/InterstitialAdPluginPluginEvent.kt +1 -0
- package/android/src/main/java/com/getcapacitor/community/admob/models/AdMobRevenueData.kt +15 -0
- package/android/src/main/java/com/getcapacitor/community/admob/models/AdOptions.java +10 -0
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/AdRewardExecutor.java +20 -3
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/RewardAdPluginEvents.kt +1 -0
- package/android/src/main/java/com/getcapacitor/community/admob/rewarded/RewardedAdCallbackAndListeners.kt +14 -4
- package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/AdRewardInterstitialExecutor.java +20 -3
- package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/RewardInterstitialAdPluginEvents.kt +1 -0
- package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/RewardedInterstitialAdCallbackAndListeners.kt +14 -3
- package/dist/docs.json +740 -193
- package/dist/esm/app-open/app-open-ad-options.interface.d.ts +9 -0
- package/dist/esm/app-open/app-open-ad-options.interface.js +2 -0
- package/dist/esm/app-open/app-open-ad-options.interface.js.map +1 -0
- package/dist/esm/app-open/app-open-ad-plugin-events.enum.d.ts +26 -0
- package/dist/esm/app-open/app-open-ad-plugin-events.enum.js +28 -0
- package/dist/esm/app-open/app-open-ad-plugin-events.enum.js.map +1 -0
- package/dist/esm/app-open/app-open-definitions.interface.d.ts +50 -0
- package/dist/esm/app-open/app-open-definitions.interface.js +2 -0
- package/dist/esm/app-open/app-open-definitions.interface.js.map +1 -0
- package/dist/esm/app-open/index.d.ts +3 -0
- package/dist/esm/app-open/index.js +4 -0
- package/dist/esm/app-open/index.js.map +1 -0
- package/dist/esm/banner/banner-ad-options.interface.d.ts +5 -6
- package/dist/esm/banner/banner-ad-plugin-events.enum.d.ts +17 -4
- package/dist/esm/banner/banner-ad-plugin-events.enum.js +16 -3
- package/dist/esm/banner/banner-ad-plugin-events.enum.js.map +1 -1
- package/dist/esm/banner/banner-ad-position.enum.d.ts +3 -3
- package/dist/esm/banner/banner-ad-position.enum.js +3 -3
- package/dist/esm/banner/banner-ad-size.enum.d.ts +4 -3
- package/dist/esm/banner/banner-ad-size.enum.js +4 -3
- package/dist/esm/banner/banner-ad-size.enum.js.map +1 -1
- package/dist/esm/banner/banner-definitions.interface.d.ts +17 -10
- package/dist/esm/banner/banner-size.interface.d.ts +8 -1
- package/dist/esm/definitions.d.ts +19 -17
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interstitial/interstitial-ad-plugin-events.enum.d.ts +10 -6
- package/dist/esm/interstitial/interstitial-ad-plugin-events.enum.js +9 -5
- package/dist/esm/interstitial/interstitial-ad-plugin-events.enum.js.map +1 -1
- package/dist/esm/interstitial/interstitial-definitions.interface.d.ts +24 -4
- package/dist/esm/reward/reward-ad-options.interface.d.ts +7 -6
- package/dist/esm/reward/reward-ad-plugin-events.enum.d.ts +13 -12
- package/dist/esm/reward/reward-ad-plugin-events.enum.js +12 -11
- package/dist/esm/reward/reward-ad-plugin-events.enum.js.map +1 -1
- package/dist/esm/reward/reward-definitions.interface.d.ts +27 -4
- package/dist/esm/reward/reward-item.interface.d.ts +3 -4
- package/dist/esm/reward-interstitial/reward-interstitial-ad-options.interface.d.ts +7 -6
- package/dist/esm/reward-interstitial/reward-interstitial-ad-plugin-events.enum.d.ts +13 -12
- package/dist/esm/reward-interstitial/reward-interstitial-ad-plugin-events.enum.js +12 -11
- package/dist/esm/reward-interstitial/reward-interstitial-ad-plugin-events.enum.js.map +1 -1
- package/dist/esm/reward-interstitial/reward-interstitial-definitions.interface.d.ts +30 -7
- package/dist/esm/reward-interstitial/reward-interstitial-item.interface.d.ts +3 -4
- package/dist/esm/shared/ad-load-info.interface.d.ts +6 -0
- package/dist/esm/shared/ad-mob-revenue-data.interface.d.ts +50 -0
- package/dist/esm/shared/ad-mob-revenue-data.interface.js +23 -0
- package/dist/esm/shared/ad-mob-revenue-data.interface.js.map +1 -0
- package/dist/esm/shared/ad-options.interface.d.ts +9 -11
- package/dist/esm/shared/ad-show-options.interface.d.ts +12 -0
- package/dist/esm/shared/ad-show-options.interface.js +2 -0
- package/dist/esm/shared/ad-show-options.interface.js.map +1 -0
- package/dist/esm/shared/admob-error.interface.d.ts +3 -2
- package/dist/esm/shared/index.d.ts +2 -0
- package/dist/esm/shared/index.js +2 -0
- package/dist/esm/shared/index.js.map +1 -1
- package/dist/esm/shared/tracking-authorization-status.interface.d.ts +6 -1
- package/dist/esm/web.d.ts +13 -4
- package/dist/esm/web.js +25 -9
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +131 -45
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +131 -45
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/AdMobPlugin/AdMobPlugin.swift +30 -4
- package/ios/Sources/AdMobPlugin/AppOpen/AppOpenAdManager.swift +112 -0
- package/ios/Sources/AdMobPlugin/AppOpen/AppOpenAdPlugin.swift +101 -0
- package/ios/Sources/AdMobPlugin/AppOpen/AppOpenAdPluginEvents.swift +8 -0
- package/ios/Sources/AdMobPlugin/Banner/BannerAdPluginEvents.swift +1 -0
- package/ios/Sources/AdMobPlugin/Banner/BannerExecutor.swift +20 -6
- package/ios/Sources/AdMobPlugin/Interstitial/AdInterstitialExecutor.swift +41 -5
- package/ios/Sources/AdMobPlugin/Interstitial/InterstitialAdPluginEvents.swift +1 -0
- package/ios/Sources/AdMobPlugin/Rewarded/AdRewardExecutor.swift +44 -5
- package/ios/Sources/AdMobPlugin/Rewarded/RewardAdPluginEvents.swift +1 -0
- package/ios/Sources/AdMobPlugin/RewardedInterstitial/AdRewardInterstitialExecutor.swift +45 -6
- package/ios/Sources/AdMobPlugin/RewardedInterstitial/RewardInterstitialAdPluginEvents.swift +1 -0
- package/package.json +2 -1
|
@@ -6,6 +6,7 @@ import androidx.core.util.Supplier;
|
|
|
6
6
|
import com.getcapacitor.JSObject;
|
|
7
7
|
import com.getcapacitor.PluginCall;
|
|
8
8
|
import com.getcapacitor.community.admob.helpers.AdViewIdHelper;
|
|
9
|
+
import com.getcapacitor.community.admob.helpers.FullscreenPluginCallback;
|
|
9
10
|
import com.getcapacitor.community.admob.helpers.RequestHelper;
|
|
10
11
|
import com.getcapacitor.community.admob.models.AdMobPluginError;
|
|
11
12
|
import com.getcapacitor.community.admob.models.AdOptions;
|
|
@@ -13,10 +14,13 @@ import com.getcapacitor.community.admob.models.Executor;
|
|
|
13
14
|
import com.google.android.gms.ads.AdRequest;
|
|
14
15
|
import com.google.android.gms.ads.interstitial.InterstitialAd;
|
|
15
16
|
import com.google.android.gms.common.util.BiConsumer;
|
|
17
|
+
import java.util.LinkedHashMap;
|
|
18
|
+
import java.util.Map;
|
|
16
19
|
|
|
17
20
|
public class AdInterstitialExecutor extends Executor {
|
|
18
21
|
|
|
19
|
-
public static InterstitialAd
|
|
22
|
+
public static final Map<String, InterstitialAd> preparedAds = new LinkedHashMap<>();
|
|
23
|
+
public static String lastPreparedAdId;
|
|
20
24
|
|
|
21
25
|
InterstitialAdCallbackAndListeners adCallbackAndListeners;
|
|
22
26
|
|
|
@@ -54,7 +58,11 @@ public class AdInterstitialExecutor extends Executor {
|
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
public void showInterstitial(final PluginCall call, BiConsumer<String, JSObject> notifyListenersFunction) {
|
|
57
|
-
|
|
61
|
+
String requestedAdId = call.getString("adId");
|
|
62
|
+
String adId = requestedAdId != null ? requestedAdId : lastPreparedAdId;
|
|
63
|
+
InterstitialAd ad = adId != null ? preparedAds.get(adId) : null;
|
|
64
|
+
|
|
65
|
+
if (ad == null) {
|
|
58
66
|
String errorMessage = "No Interstitial can be shown. It was not prepared or maybe it failed to be prepared.";
|
|
59
67
|
call.reject(errorMessage);
|
|
60
68
|
AdMobPluginError errorObject = new AdMobPluginError(-1, errorMessage);
|
|
@@ -62,11 +70,21 @@ public class AdInterstitialExecutor extends Executor {
|
|
|
62
70
|
return;
|
|
63
71
|
}
|
|
64
72
|
|
|
73
|
+
final InterstitialAd adToShow = ad;
|
|
65
74
|
activitySupplier
|
|
66
75
|
.get()
|
|
67
76
|
.runOnUiThread(() -> {
|
|
68
77
|
try {
|
|
69
|
-
|
|
78
|
+
adToShow.setFullScreenContentCallback(
|
|
79
|
+
new FullscreenPluginCallback(InterstitialAdPluginPluginEvent.INSTANCE, notifyListenersFunction, () -> {
|
|
80
|
+
preparedAds.remove(adId);
|
|
81
|
+
if (adId != null && adId.equals(lastPreparedAdId)) {
|
|
82
|
+
lastPreparedAdId = null;
|
|
83
|
+
for (String remainingAdId : preparedAds.keySet()) lastPreparedAdId = remainingAdId;
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
adToShow.show(activitySupplier.get());
|
|
70
88
|
call.resolve();
|
|
71
89
|
} catch (Exception ex) {
|
|
72
90
|
call.reject(ex.getLocalizedMessage(), ex);
|
|
@@ -4,6 +4,7 @@ import com.getcapacitor.JSObject
|
|
|
4
4
|
import com.getcapacitor.PluginCall
|
|
5
5
|
import com.getcapacitor.community.admob.helpers.FullscreenPluginCallback
|
|
6
6
|
import com.getcapacitor.community.admob.models.AdMobPluginError
|
|
7
|
+
import com.getcapacitor.community.admob.models.AdMobRevenueData
|
|
7
8
|
import com.google.android.gms.ads.LoadAdError
|
|
8
9
|
import com.google.android.gms.ads.interstitial.InterstitialAd
|
|
9
10
|
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
|
|
@@ -20,7 +21,16 @@ object InterstitialAdCallbackAndListeners {
|
|
|
20
21
|
ad.fullScreenContentCallback = FullscreenPluginCallback(InterstitialAdPluginPluginEvent, notifyListenersFunction)
|
|
21
22
|
ad.setImmersiveMode(immersiveMode ?: false)
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
ad.setOnPaidEventListener { adValue ->
|
|
25
|
+
val responseInfo = ad.responseInfo
|
|
26
|
+
val networkName = responseInfo?.mediationAdapterClassName ?: ""
|
|
27
|
+
val impressionId = responseInfo?.responseId ?: ""
|
|
28
|
+
val revenueData = AdMobRevenueData(adValue, ad.adUnitId, networkName, impressionId)
|
|
29
|
+
notifyListenersFunction.accept(InterstitialAdPluginPluginEvent.AdImpression, revenueData)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
AdInterstitialExecutor.preparedAds[ad.adUnitId] = ad
|
|
33
|
+
AdInterstitialExecutor.lastPreparedAdId = ad.adUnitId
|
|
24
34
|
|
|
25
35
|
val adInfo = JSObject()
|
|
26
36
|
adInfo.put("adUnitId", ad.adUnitId)
|
|
@@ -37,4 +47,4 @@ object InterstitialAdCallbackAndListeners {
|
|
|
37
47
|
}
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
|
-
}
|
|
50
|
+
}
|
|
@@ -8,4 +8,5 @@ object InterstitialAdPluginPluginEvent: LoadPluginEventNames {
|
|
|
8
8
|
override val Showed = "interstitialAdShowed"
|
|
9
9
|
override val FailedToShow = "interstitialAdFailedToShow"
|
|
10
10
|
override val Dismissed = "interstitialAdDismissed"
|
|
11
|
+
const val AdImpression = "interstitialAdImpression"
|
|
11
12
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.getcapacitor.community.admob.models
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject
|
|
4
|
+
import com.google.android.gms.ads.AdValue
|
|
5
|
+
|
|
6
|
+
class AdMobRevenueData(adValue: AdValue, adUnitId: String, networkName: String, impressionId: String) : JSObject() {
|
|
7
|
+
init {
|
|
8
|
+
put("adUnitId", adUnitId)
|
|
9
|
+
put("valueMicros", adValue.valueMicros)
|
|
10
|
+
put("currencyCode", adValue.currencyCode)
|
|
11
|
+
put("precision", adValue.precisionType)
|
|
12
|
+
put("networkName", networkName)
|
|
13
|
+
put("impressionId", impressionId)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -28,6 +28,7 @@ public abstract class AdOptions {
|
|
|
28
28
|
public static final String INTERSTITIAL_TESTER_ID = "ca-app-pub-3940256099942544/1033173712";
|
|
29
29
|
public static final String REWARD_VIDEO_TESTER_ID = "ca-app-pub-3940256099942544/5224354917";
|
|
30
30
|
public static final String REWARD_INTERSTITIAL_TESTER_ID = "ca-app-pub-3940256099942544/5354046379";
|
|
31
|
+
public static final String APP_OPEN_TESTER_ID = "ca-app-pub-3940256099942544/9257395921";
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* The position of the ad, it can be TOP_CENTER,
|
|
@@ -148,6 +149,15 @@ public abstract class AdOptions {
|
|
|
148
149
|
};
|
|
149
150
|
}
|
|
150
151
|
|
|
152
|
+
public AdOptions createAppOpenOptions(PluginCall call) {
|
|
153
|
+
return new AdOptions(call) {
|
|
154
|
+
@Override
|
|
155
|
+
public String getTestingId() {
|
|
156
|
+
return AdOptions.APP_OPEN_TESTER_ID;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
151
161
|
public AdOptions createGenericOptions(PluginCall call, final String testingID) {
|
|
152
162
|
return new AdOptions(call) {
|
|
153
163
|
@Override
|
package/android/src/main/java/com/getcapacitor/community/admob/rewarded/AdRewardExecutor.java
CHANGED
|
@@ -7,6 +7,7 @@ import com.getcapacitor.JSObject;
|
|
|
7
7
|
import com.getcapacitor.PluginCall;
|
|
8
8
|
import com.getcapacitor.PluginMethod;
|
|
9
9
|
import com.getcapacitor.community.admob.helpers.AdViewIdHelper;
|
|
10
|
+
import com.getcapacitor.community.admob.helpers.FullscreenPluginCallback;
|
|
10
11
|
import com.getcapacitor.community.admob.helpers.RequestHelper;
|
|
11
12
|
import com.getcapacitor.community.admob.models.AdMobPluginError;
|
|
12
13
|
import com.getcapacitor.community.admob.models.AdOptions;
|
|
@@ -14,10 +15,13 @@ import com.getcapacitor.community.admob.models.Executor;
|
|
|
14
15
|
import com.google.android.gms.ads.AdRequest;
|
|
15
16
|
import com.google.android.gms.ads.rewarded.RewardedAd;
|
|
16
17
|
import com.google.android.gms.common.util.BiConsumer;
|
|
18
|
+
import java.util.LinkedHashMap;
|
|
19
|
+
import java.util.Map;
|
|
17
20
|
|
|
18
21
|
public class AdRewardExecutor extends Executor {
|
|
19
22
|
|
|
20
|
-
public static RewardedAd
|
|
23
|
+
public static final Map<String, RewardedAd> preparedAds = new LinkedHashMap<>();
|
|
24
|
+
public static String lastPreparedAdId;
|
|
21
25
|
|
|
22
26
|
public AdRewardExecutor(
|
|
23
27
|
Supplier<Context> contextSupplier,
|
|
@@ -52,7 +56,11 @@ public class AdRewardExecutor extends Executor {
|
|
|
52
56
|
|
|
53
57
|
@PluginMethod
|
|
54
58
|
public void showRewardVideoAd(final PluginCall call, BiConsumer<String, JSObject> notifyListenersFunction) {
|
|
55
|
-
|
|
59
|
+
String requestedAdId = call.getString("adId");
|
|
60
|
+
String adId = requestedAdId != null ? requestedAdId : lastPreparedAdId;
|
|
61
|
+
RewardedAd ad = adId != null ? preparedAds.get(adId) : null;
|
|
62
|
+
|
|
63
|
+
if (ad == null) {
|
|
56
64
|
String errorMessage = "No Reward Video Ad can be shown. It was not prepared or maybe it failed to be prepared.";
|
|
57
65
|
call.reject(errorMessage);
|
|
58
66
|
AdMobPluginError errorObject = new AdMobPluginError(-1, errorMessage);
|
|
@@ -64,7 +72,16 @@ public class AdRewardExecutor extends Executor {
|
|
|
64
72
|
activitySupplier
|
|
65
73
|
.get()
|
|
66
74
|
.runOnUiThread(() -> {
|
|
67
|
-
|
|
75
|
+
ad.setFullScreenContentCallback(
|
|
76
|
+
new FullscreenPluginCallback(RewardAdPluginEvents.INSTANCE, notifyListenersFunction, () -> {
|
|
77
|
+
preparedAds.remove(adId);
|
|
78
|
+
if (adId != null && adId.equals(lastPreparedAdId)) {
|
|
79
|
+
lastPreparedAdId = null;
|
|
80
|
+
for (String remainingAdId : preparedAds.keySet()) lastPreparedAdId = remainingAdId;
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
ad.show(
|
|
68
85
|
activitySupplier.get(),
|
|
69
86
|
RewardedAdCallbackAndListeners.INSTANCE.getOnUserEarnedRewardListener(call, notifyListenersFunction)
|
|
70
87
|
);
|
package/android/src/main/java/com/getcapacitor/community/admob/rewarded/RewardAdPluginEvents.kt
CHANGED
|
@@ -9,4 +9,5 @@ object RewardAdPluginEvents: LoadPluginEventNames {
|
|
|
9
9
|
override val Showed = "onRewardedVideoAdShowed"
|
|
10
10
|
override val FailedToShow = "onRewardedVideoAdFailedToShow"
|
|
11
11
|
override val Dismissed = "onRewardedVideoAdDismissed"
|
|
12
|
+
const val AdImpression = "onRewardedVideoAdImpression"
|
|
12
13
|
}
|
|
@@ -4,6 +4,7 @@ import com.getcapacitor.JSObject
|
|
|
4
4
|
import com.getcapacitor.PluginCall
|
|
5
5
|
import com.getcapacitor.community.admob.helpers.FullscreenPluginCallback
|
|
6
6
|
import com.getcapacitor.community.admob.models.AdMobPluginError
|
|
7
|
+
import com.getcapacitor.community.admob.models.AdMobRevenueData
|
|
7
8
|
import com.getcapacitor.community.admob.models.AdOptions
|
|
8
9
|
import com.google.android.gms.ads.LoadAdError
|
|
9
10
|
import com.google.android.gms.ads.OnUserEarnedRewardListener
|
|
@@ -30,11 +31,17 @@ object RewardedAdCallbackAndListeners {
|
|
|
30
31
|
override fun onAdLoaded(ad: RewardedAd) {
|
|
31
32
|
val immersiveMode = call.getBoolean("immersiveMode")
|
|
32
33
|
ad.setImmersiveMode(immersiveMode ?: false)
|
|
33
|
-
|
|
34
|
-
AdRewardExecutor.mRewardedAd = ad
|
|
35
|
-
AdRewardExecutor.mRewardedAd.fullScreenContentCallback = FullscreenPluginCallback(
|
|
34
|
+
ad.fullScreenContentCallback = FullscreenPluginCallback(
|
|
36
35
|
RewardAdPluginEvents, notifyListenersFunction)
|
|
37
36
|
|
|
37
|
+
ad.setOnPaidEventListener { adValue ->
|
|
38
|
+
val responseInfo = ad.responseInfo
|
|
39
|
+
val networkName = responseInfo?.mediationAdapterClassName ?: ""
|
|
40
|
+
val impressionId = responseInfo?.responseId ?: ""
|
|
41
|
+
val revenueData = AdMobRevenueData(adValue, ad.adUnitId, networkName, impressionId)
|
|
42
|
+
notifyListenersFunction.accept(RewardAdPluginEvents.AdImpression, revenueData)
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
if(adOptions.ssvInfo.hasInfo){
|
|
39
46
|
val ssvOptions = ServerSideVerificationOptions.Builder()
|
|
40
47
|
adOptions.ssvInfo.customData?.let {
|
|
@@ -44,9 +51,12 @@ object RewardedAdCallbackAndListeners {
|
|
|
44
51
|
adOptions.ssvInfo.userId?.let {
|
|
45
52
|
ssvOptions.setUserId(it)
|
|
46
53
|
}
|
|
47
|
-
|
|
54
|
+
ad.setServerSideVerificationOptions(ssvOptions.build())
|
|
48
55
|
}
|
|
49
56
|
|
|
57
|
+
AdRewardExecutor.preparedAds[ad.adUnitId] = ad
|
|
58
|
+
AdRewardExecutor.lastPreparedAdId = ad.adUnitId
|
|
59
|
+
|
|
50
60
|
val adInfo = JSObject()
|
|
51
61
|
adInfo.put("adUnitId", ad.adUnitId)
|
|
52
62
|
call.resolve(adInfo)
|
|
@@ -7,6 +7,7 @@ import com.getcapacitor.JSObject;
|
|
|
7
7
|
import com.getcapacitor.PluginCall;
|
|
8
8
|
import com.getcapacitor.PluginMethod;
|
|
9
9
|
import com.getcapacitor.community.admob.helpers.AdViewIdHelper;
|
|
10
|
+
import com.getcapacitor.community.admob.helpers.FullscreenPluginCallback;
|
|
10
11
|
import com.getcapacitor.community.admob.helpers.RequestHelper;
|
|
11
12
|
import com.getcapacitor.community.admob.models.AdMobPluginError;
|
|
12
13
|
import com.getcapacitor.community.admob.models.AdOptions;
|
|
@@ -14,10 +15,13 @@ import com.getcapacitor.community.admob.models.Executor;
|
|
|
14
15
|
import com.google.android.gms.ads.AdRequest;
|
|
15
16
|
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;
|
|
16
17
|
import com.google.android.gms.common.util.BiConsumer;
|
|
18
|
+
import java.util.LinkedHashMap;
|
|
19
|
+
import java.util.Map;
|
|
17
20
|
|
|
18
21
|
public class AdRewardInterstitialExecutor extends Executor {
|
|
19
22
|
|
|
20
|
-
public static RewardedInterstitialAd
|
|
23
|
+
public static final Map<String, RewardedInterstitialAd> preparedAds = new LinkedHashMap<>();
|
|
24
|
+
public static String lastPreparedAdId;
|
|
21
25
|
|
|
22
26
|
public AdRewardInterstitialExecutor(
|
|
23
27
|
Supplier<Context> contextSupplier,
|
|
@@ -56,7 +60,11 @@ public class AdRewardInterstitialExecutor extends Executor {
|
|
|
56
60
|
|
|
57
61
|
@PluginMethod
|
|
58
62
|
public void showRewardInterstitialAd(final PluginCall call, BiConsumer<String, JSObject> notifyListenersFunction) {
|
|
59
|
-
|
|
63
|
+
String requestedAdId = call.getString("adId");
|
|
64
|
+
String adId = requestedAdId != null ? requestedAdId : lastPreparedAdId;
|
|
65
|
+
RewardedInterstitialAd ad = adId != null ? preparedAds.get(adId) : null;
|
|
66
|
+
|
|
67
|
+
if (ad == null) {
|
|
60
68
|
String errorMessage = "No Reward Interstitial Video Ad can be shown. It was not prepared or maybe it failed to be prepared.";
|
|
61
69
|
call.reject(errorMessage);
|
|
62
70
|
AdMobPluginError errorObject = new AdMobPluginError(-1, errorMessage);
|
|
@@ -68,7 +76,16 @@ public class AdRewardInterstitialExecutor extends Executor {
|
|
|
68
76
|
activitySupplier
|
|
69
77
|
.get()
|
|
70
78
|
.runOnUiThread(() -> {
|
|
71
|
-
|
|
79
|
+
ad.setFullScreenContentCallback(
|
|
80
|
+
new FullscreenPluginCallback(RewardInterstitialAdPluginEvents.INSTANCE, notifyListenersFunction, () -> {
|
|
81
|
+
preparedAds.remove(adId);
|
|
82
|
+
if (adId != null && adId.equals(lastPreparedAdId)) {
|
|
83
|
+
lastPreparedAdId = null;
|
|
84
|
+
for (String remainingAdId : preparedAds.keySet()) lastPreparedAdId = remainingAdId;
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
ad.show(
|
|
72
89
|
activitySupplier.get(),
|
|
73
90
|
RewardedInterstitialAdCallbackAndListeners.INSTANCE.getOnUserEarnedRewardListener(call, notifyListenersFunction)
|
|
74
91
|
);
|
|
@@ -9,4 +9,5 @@ object RewardInterstitialAdPluginEvents: LoadPluginEventNames {
|
|
|
9
9
|
override val Showed = "onRewardedInterstitialAdShowed"
|
|
10
10
|
override val FailedToShow = "onRewardedInterstitialAdFailedToShow"
|
|
11
11
|
override val Dismissed = "onRewardedInterstitialAdDismissed"
|
|
12
|
+
const val AdImpression = "onRewardedInterstitialAdImpression"
|
|
12
13
|
}
|
|
@@ -4,6 +4,7 @@ import com.getcapacitor.JSObject
|
|
|
4
4
|
import com.getcapacitor.PluginCall
|
|
5
5
|
import com.getcapacitor.community.admob.helpers.FullscreenPluginCallback
|
|
6
6
|
import com.getcapacitor.community.admob.models.AdMobPluginError
|
|
7
|
+
import com.getcapacitor.community.admob.models.AdMobRevenueData
|
|
7
8
|
import com.getcapacitor.community.admob.models.AdOptions
|
|
8
9
|
import com.google.android.gms.ads.LoadAdError
|
|
9
10
|
import com.google.android.gms.ads.OnUserEarnedRewardListener
|
|
@@ -27,10 +28,20 @@ object RewardedInterstitialAdCallbackAndListeners {
|
|
|
27
28
|
fun getRewardedAdLoadCallback(call: PluginCall, notifyListenersFunction: BiConsumer<String, JSObject>, adOptions: AdOptions): RewardedInterstitialAdLoadCallback {
|
|
28
29
|
return object : RewardedInterstitialAdLoadCallback() {
|
|
29
30
|
override fun onAdLoaded(ad: RewardedInterstitialAd) {
|
|
30
|
-
|
|
31
|
-
AdRewardInterstitialExecutor.mRewardedInterstitialAd.fullScreenContentCallback = FullscreenPluginCallback(
|
|
31
|
+
ad.fullScreenContentCallback = FullscreenPluginCallback(
|
|
32
32
|
RewardInterstitialAdPluginEvents, notifyListenersFunction)
|
|
33
33
|
|
|
34
|
+
ad.setOnPaidEventListener { adValue ->
|
|
35
|
+
val responseInfo = ad.responseInfo
|
|
36
|
+
val networkName = responseInfo?.mediationAdapterClassName ?: ""
|
|
37
|
+
val impressionId = responseInfo?.responseId ?: ""
|
|
38
|
+
val revenueData = AdMobRevenueData(adValue, ad.adUnitId, networkName, impressionId)
|
|
39
|
+
notifyListenersFunction.accept(RewardInterstitialAdPluginEvents.AdImpression, revenueData)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
AdRewardInterstitialExecutor.preparedAds[ad.adUnitId] = ad
|
|
43
|
+
AdRewardInterstitialExecutor.lastPreparedAdId = ad.adUnitId
|
|
44
|
+
|
|
34
45
|
val adInfo = JSObject()
|
|
35
46
|
adInfo.put("adUnitId", ad.adUnitId)
|
|
36
47
|
call.resolve(adInfo)
|
|
@@ -47,4 +58,4 @@ object RewardedInterstitialAdCallbackAndListeners {
|
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
60
|
|
|
50
|
-
}
|
|
61
|
+
}
|