@ququplay/admob 6.0.0 → 7.0.2

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.
Files changed (60) hide show
  1. package/Package.swift +30 -0
  2. package/QuquplayAdmob.podspec +2 -2
  3. package/README.md +343 -115
  4. package/android/build.gradle +11 -11
  5. package/android/src/main/java/com/getcapacitor/community/admob/AdMob.java +17 -0
  6. package/android/src/main/java/com/getcapacitor/community/admob/banner/BannerExecutor.java +81 -91
  7. package/android/src/main/java/com/getcapacitor/community/admob/consent/AdConsentExecutor.java +17 -21
  8. package/android/src/main/java/com/getcapacitor/community/admob/interstitial/AdInterstitialExecutor.java +17 -21
  9. package/android/src/main/java/com/getcapacitor/community/admob/models/AdOptions.java +10 -0
  10. package/android/src/main/java/com/getcapacitor/community/admob/rewarded/AdRewardExecutor.java +19 -23
  11. package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/AdRewardInterstitialExecutor.java +80 -0
  12. package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/RewardInterstitialAdPluginEvents.kt +12 -0
  13. package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/RewardedInterstitialAdCallbackAndListeners.kt +50 -0
  14. package/android/src/main/java/com/getcapacitor/community/admob/rewardedinterstitial/models/SsvInfo.kt +20 -0
  15. package/dist/docs.json +399 -749
  16. package/dist/esm/definitions.d.ts +2 -1
  17. package/dist/esm/definitions.js.map +1 -1
  18. package/dist/esm/index.d.ts +1 -0
  19. package/dist/esm/index.js +2 -1
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/reward-interstitial/index.d.ts +4 -0
  22. package/dist/esm/reward-interstitial/index.js +5 -0
  23. package/dist/esm/reward-interstitial/index.js.map +1 -0
  24. package/dist/esm/reward-interstitial/reward-interstitial-ad-options.interface.d.ts +25 -0
  25. package/dist/esm/reward-interstitial/reward-interstitial-ad-options.interface.js +2 -0
  26. package/dist/esm/reward-interstitial/reward-interstitial-ad-options.interface.js.map +1 -0
  27. package/dist/esm/reward-interstitial/reward-interstitial-ad-plugin-events.enum.d.ts +32 -0
  28. package/dist/esm/reward-interstitial/reward-interstitial-ad-plugin-events.enum.js +35 -0
  29. package/dist/esm/reward-interstitial/reward-interstitial-ad-plugin-events.enum.js.map +1 -0
  30. package/dist/esm/reward-interstitial/reward-interstitial-definitions.interface.d.ts +30 -0
  31. package/dist/esm/reward-interstitial/reward-interstitial-definitions.interface.js +2 -0
  32. package/dist/esm/reward-interstitial/reward-interstitial-definitions.interface.js.map +1 -0
  33. package/dist/esm/reward-interstitial/reward-interstitial-item.interface.d.ts +14 -0
  34. package/dist/esm/reward-interstitial/reward-interstitial-item.interface.js +2 -0
  35. package/dist/esm/reward-interstitial/reward-interstitial-item.interface.js.map +1 -0
  36. package/dist/esm/web.d.ts +2 -0
  37. package/dist/esm/web.js +12 -0
  38. package/dist/esm/web.js.map +1 -1
  39. package/dist/plugin.cjs.js +48 -3
  40. package/dist/plugin.cjs.js.map +1 -1
  41. package/dist/plugin.js +49 -4
  42. package/dist/plugin.js.map +1 -1
  43. package/ios/{Plugin/Plugin.swift → Sources/AdMobPlugin/AdMobPlugin.swift} +46 -4
  44. package/ios/{Plugin → Sources/AdMobPlugin}/Banner/BannerExecutor.swift +7 -7
  45. package/ios/{Plugin → Sources/AdMobPlugin}/Consent/ConsentExecutor.swift +1 -1
  46. package/ios/{Plugin → Sources/AdMobPlugin}/Interstitial/AdInterstitialExecutor.swift +4 -4
  47. package/ios/{Plugin → Sources/AdMobPlugin}/Rewarded/AdRewardExecutor.swift +4 -4
  48. package/ios/Sources/AdMobPlugin/RewardedInterstitial/AdRewardInterstitialExecutor.swift +86 -0
  49. package/ios/Sources/AdMobPlugin/RewardedInterstitial/RewardInterstitialAdPluginEvents.swift +8 -0
  50. package/ios/Tests/AdMobPluginTests/AdMobPluginTests.swift +15 -0
  51. package/package.json +30 -34
  52. package/ios/Plugin/Info.plist +0 -24
  53. package/ios/Plugin/Plugin.h +0 -10
  54. package/ios/Plugin/Plugin.m +0 -23
  55. /package/ios/{Plugin → Sources/AdMobPlugin}/Banner/BannerAdPluginEvents.swift +0 -0
  56. /package/ios/{Plugin → Sources/AdMobPlugin}/Banner/BannerAdSizeEnum.swift +0 -0
  57. /package/ios/{Plugin → Sources/AdMobPlugin}/Helper/AuthorizationStatusEnum.swift +0 -0
  58. /package/ios/{Plugin → Sources/AdMobPlugin}/Interstitial/InterstitialAdPluginEvents.swift +0 -0
  59. /package/ios/{Plugin → Sources/AdMobPlugin}/Models/FullScreenAdEventName.swift +0 -0
  60. /package/ios/{Plugin → Sources/AdMobPlugin}/Rewarded/RewardAdPluginEvents.swift +0 -0
@@ -1,21 +1,21 @@
1
1
  ext {
2
2
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
4
  androidxCoordinatorLayoutVersion = project.hasProperty('androidxCoordinatorLayoutVersion') ? rootProject.ext.androidxCoordinatorLayoutVersion : '1.2.0'
5
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
6
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
5
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
6
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
7
7
  playServicesAdsVersion = project.hasProperty('playServicesAdsVersion') ? rootProject.ext.playServicesAdsVersion : '23.0.0'
8
8
  androidxCoreKTXVersion = project.hasProperty('androidxCoreKTXVersion') ? rootProject.ext.androidxCoreKTXVersion : '1.13.0'
9
9
  }
10
10
 
11
11
  buildscript {
12
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.10'
12
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.25'
13
13
  repositories {
14
14
  google()
15
15
  mavenCentral()
16
16
  }
17
17
  dependencies {
18
- classpath 'com.android.tools.build:gradle:8.2.1'
18
+ classpath 'com.android.tools.build:gradle:8.7.2'
19
19
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
20
20
  }
21
21
  }
@@ -25,10 +25,10 @@ apply plugin: 'kotlin-android'
25
25
 
26
26
  android {
27
27
  namespace "com.getcapacitor.community.admob.admob"
28
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
28
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
29
29
  defaultConfig {
30
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
31
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
30
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
31
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
32
32
  versionCode 1
33
33
  versionName "1.0"
34
34
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -43,11 +43,11 @@ android {
43
43
  abortOnError false
44
44
  }
45
45
  compileOptions {
46
- sourceCompatibility JavaVersion.VERSION_17
47
- targetCompatibility JavaVersion.VERSION_17
46
+ sourceCompatibility JavaVersion.VERSION_21
47
+ targetCompatibility JavaVersion.VERSION_21
48
48
  }
49
49
  kotlinOptions {
50
- jvmTarget = JavaVersion.VERSION_17
50
+ jvmTarget = JavaVersion.VERSION_21
51
51
  }
52
52
  }
53
53
 
@@ -14,6 +14,7 @@ import com.getcapacitor.community.admob.helpers.AuthorizationStatusEnum;
14
14
  import com.getcapacitor.community.admob.interstitial.AdInterstitialExecutor;
15
15
  import com.getcapacitor.community.admob.interstitial.InterstitialAdCallbackAndListeners;
16
16
  import com.getcapacitor.community.admob.rewarded.AdRewardExecutor;
17
+ import com.getcapacitor.community.admob.rewardedinterstitial.AdRewardInterstitialExecutor;
17
18
  import com.google.android.gms.ads.MobileAds;
18
19
  import com.google.android.gms.ads.RequestConfiguration;
19
20
  import com.google.android.gms.ads.initialization.InitializationStatus;
@@ -39,6 +40,12 @@ public class AdMob extends Plugin {
39
40
  this::notifyListeners,
40
41
  getLogTag()
41
42
  );
43
+ private final AdRewardInterstitialExecutor adRewardInterstitialExecutor = new AdRewardInterstitialExecutor(
44
+ this::getContext,
45
+ this::getActivity,
46
+ this::notifyListeners,
47
+ getLogTag()
48
+ );
42
49
  private final AdInterstitialExecutor adInterstitialExecutor = new AdInterstitialExecutor(
43
50
  this::getContext,
44
51
  this::getActivity,
@@ -169,6 +176,16 @@ public class AdMob extends Plugin {
169
176
  adRewardExecutor.showRewardVideoAd(call, this::notifyListeners);
170
177
  }
171
178
 
179
+ @PluginMethod
180
+ public void prepareRewardInterstitialAd(final PluginCall call) {
181
+ adRewardInterstitialExecutor.prepareRewardInterstitialAd(call, this::notifyListeners);
182
+ }
183
+
184
+ @PluginMethod
185
+ public void showRewardInterstitialAd(final PluginCall call) {
186
+ adRewardInterstitialExecutor.showRewardInterstitialAd(call, this::notifyListeners);
187
+ }
188
+
172
189
  /**
173
190
  * @see <a href="https://developers.google.com/admob/android/test-ads#enable_test_devices">Test Devices</a>
174
191
  * @see <a href="https://developers.google.com/admob/android/targeting">Target Settings</a>
@@ -140,20 +140,18 @@ public class BannerExecutor extends Executor {
140
140
  try {
141
141
  activitySupplier
142
142
  .get()
143
- .runOnUiThread(
144
- () -> {
145
- if (mAdViewLayout != null) {
146
- mAdViewLayout.setVisibility(View.GONE);
147
- mAdView.pause();
143
+ .runOnUiThread(() -> {
144
+ if (mAdViewLayout != null) {
145
+ mAdViewLayout.setVisibility(View.GONE);
146
+ mAdView.pause();
148
147
 
149
- final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(0, 0);
148
+ final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(0, 0);
150
149
 
151
- notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
150
+ notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
152
151
 
153
- call.resolve();
154
- }
152
+ call.resolve();
155
153
  }
156
- );
154
+ });
157
155
  } catch (Exception ex) {
158
156
  call.reject(ex.getLocalizedMessage(), ex);
159
157
  }
@@ -163,19 +161,17 @@ public class BannerExecutor extends Executor {
163
161
  try {
164
162
  activitySupplier
165
163
  .get()
166
- .runOnUiThread(
167
- () -> {
168
- if (mAdViewLayout != null && mAdView != null) {
169
- mAdViewLayout.setVisibility(View.VISIBLE);
170
- mAdView.resume();
164
+ .runOnUiThread(() -> {
165
+ if (mAdViewLayout != null && mAdView != null) {
166
+ mAdViewLayout.setVisibility(View.VISIBLE);
167
+ mAdView.resume();
171
168
 
172
- final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(mAdView);
173
- notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
169
+ final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(mAdView);
170
+ notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
174
171
 
175
- Log.d(logTag, "Banner AD Resumed");
176
- }
172
+ Log.d(logTag, "Banner AD Resumed");
177
173
  }
178
- );
174
+ });
179
175
 
180
176
  call.resolve();
181
177
  } catch (Exception ex) {
@@ -188,19 +184,17 @@ public class BannerExecutor extends Executor {
188
184
  if (mAdView != null) {
189
185
  activitySupplier
190
186
  .get()
191
- .runOnUiThread(
192
- () -> {
193
- if (mAdView != null) {
194
- mViewGroup.removeView(mAdViewLayout);
195
- mAdViewLayout.removeView(mAdView);
196
- mAdView.destroy();
197
- mAdView = null;
198
- Log.d(logTag, "Banner AD Removed");
199
- final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(0, 0);
200
- notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
201
- }
187
+ .runOnUiThread(() -> {
188
+ if (mAdView != null) {
189
+ mViewGroup.removeView(mAdViewLayout);
190
+ mAdViewLayout.removeView(mAdView);
191
+ mAdView.destroy();
192
+ mAdView = null;
193
+ Log.d(logTag, "Banner AD Removed");
194
+ final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(0, 0);
195
+ notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
202
196
  }
203
- );
197
+ });
204
198
  }
205
199
 
206
200
  call.resolve();
@@ -212,12 +206,10 @@ public class BannerExecutor extends Executor {
212
206
  private void updateExistingAdView(AdOptions adOptions) {
213
207
  activitySupplier
214
208
  .get()
215
- .runOnUiThread(
216
- () -> {
217
- final AdRequest adRequest = RequestHelper.createRequest(adOptions);
218
- mAdView.loadAd(adRequest);
219
- }
220
- );
209
+ .runOnUiThread(() -> {
210
+ final AdRequest adRequest = RequestHelper.createRequest(adOptions);
211
+ mAdView.loadAd(adRequest);
212
+ });
221
213
  }
222
214
 
223
215
  /**
@@ -228,67 +220,65 @@ public class BannerExecutor extends Executor {
228
220
  // Run AdMob In Main UI Thread
229
221
  activitySupplier
230
222
  .get()
231
- .runOnUiThread(
232
- () -> {
233
- final AdRequest adRequest = RequestHelper.createRequest(adOptions);
234
- // Assign the correct id needed
235
- AdViewIdHelper.assignIdToAdView(mAdView, adOptions, adRequest, logTag, contextSupplier.get());
236
- // Add the AdView to the view hierarchy.
237
- mAdViewLayout.addView(mAdView);
238
- // Start loading the ad.
239
- mAdView.loadAd(adRequest);
240
- mAdView.setAdListener(
241
- new AdListener() {
242
- @Override
243
- public void onAdLoaded() {
244
- final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(mAdView);
245
-
246
- notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
247
- notifyListeners(BannerAdPluginEvents.Loaded.getWebEventName(), emptyObject);
248
- super.onAdLoaded();
249
- }
223
+ .runOnUiThread(() -> {
224
+ final AdRequest adRequest = RequestHelper.createRequest(adOptions);
225
+ // Assign the correct id needed
226
+ AdViewIdHelper.assignIdToAdView(mAdView, adOptions, adRequest, logTag, contextSupplier.get());
227
+ // Add the AdView to the view hierarchy.
228
+ mAdViewLayout.addView(mAdView);
229
+ // Start loading the ad.
230
+ mAdView.loadAd(adRequest);
231
+ mAdView.setAdListener(
232
+ new AdListener() {
233
+ @Override
234
+ public void onAdLoaded() {
235
+ final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(mAdView);
236
+
237
+ notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
238
+ notifyListeners(BannerAdPluginEvents.Loaded.getWebEventName(), emptyObject);
239
+ super.onAdLoaded();
240
+ }
250
241
 
251
- @Override
252
- public void onAdFailedToLoad(@NonNull LoadAdError adError) {
253
- if (mAdView != null) {
254
- mViewGroup.removeView(mAdViewLayout);
255
- mAdViewLayout.removeView(mAdView);
256
- mAdView.destroy();
257
- mAdView = null;
258
- }
242
+ @Override
243
+ public void onAdFailedToLoad(@NonNull LoadAdError adError) {
244
+ if (mAdView != null) {
245
+ mViewGroup.removeView(mAdViewLayout);
246
+ mAdViewLayout.removeView(mAdView);
247
+ mAdView.destroy();
248
+ mAdView = null;
249
+ }
259
250
 
260
- final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(0, 0);
261
- notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
251
+ final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(0, 0);
252
+ notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
262
253
 
263
- final AdMobPluginError adMobPluginError = new AdMobPluginError(adError);
264
- notifyListeners(BannerAdPluginEvents.FailedToLoad.getWebEventName(), adMobPluginError);
254
+ final AdMobPluginError adMobPluginError = new AdMobPluginError(adError);
255
+ notifyListeners(BannerAdPluginEvents.FailedToLoad.getWebEventName(), adMobPluginError);
265
256
 
266
- super.onAdFailedToLoad(adError);
267
- }
257
+ super.onAdFailedToLoad(adError);
258
+ }
268
259
 
269
- @Override
270
- public void onAdOpened() {
271
- notifyListeners(BannerAdPluginEvents.Opened.getWebEventName(), emptyObject);
272
- super.onAdOpened();
273
- }
260
+ @Override
261
+ public void onAdOpened() {
262
+ notifyListeners(BannerAdPluginEvents.Opened.getWebEventName(), emptyObject);
263
+ super.onAdOpened();
264
+ }
274
265
 
275
- @Override
276
- public void onAdClosed() {
277
- notifyListeners(BannerAdPluginEvents.Closed.getWebEventName(), emptyObject);
278
- super.onAdClosed();
279
- }
266
+ @Override
267
+ public void onAdClosed() {
268
+ notifyListeners(BannerAdPluginEvents.Closed.getWebEventName(), emptyObject);
269
+ super.onAdClosed();
270
+ }
280
271
 
281
- @Override
282
- public void onAdImpression() {
283
- notifyListeners(BannerAdPluginEvents.AdImpression.getWebEventName(), emptyObject);
284
- super.onAdImpression();
285
- }
272
+ @Override
273
+ public void onAdImpression() {
274
+ notifyListeners(BannerAdPluginEvents.AdImpression.getWebEventName(), emptyObject);
275
+ super.onAdImpression();
286
276
  }
287
- );
277
+ }
278
+ );
288
279
 
289
- // Add AdViewLayout top of the WebView
290
- mViewGroup.addView(mAdViewLayout);
291
- }
292
- );
280
+ // Add AdViewLayout top of the WebView
281
+ mViewGroup.addView(mAdViewLayout);
282
+ });
293
283
  }
294
284
  }
@@ -151,27 +151,23 @@ public class AdConsentExecutor extends Executor {
151
151
  ensureConsentInfo();
152
152
  activitySupplier
153
153
  .get()
154
- .runOnUiThread(
155
- () ->
156
- UserMessagingPlatform.loadConsentForm(
157
- contextSupplier.get(),
158
- consentForm ->
159
- consentForm.show(
160
- activitySupplier.get(),
161
- formError -> {
162
- if (formError != null) {
163
- call.reject("Error when show consent form", formError.getMessage());
164
- } else {
165
- JSObject consentFormInfo = new JSObject();
166
- consentFormInfo.put("status", getConsentStatusString(consentInformation.getConsentStatus()));
167
- consentFormInfo.put("canShowAds", canShowAds());
168
- consentFormInfo.put("canShowPersonalizedAds", canShowPersonalizedAds());
169
- call.resolve(consentFormInfo);
170
- }
171
- }
172
- ),
173
- formError -> call.reject("Error when show consent form", formError.getMessage())
174
- )
154
+ .runOnUiThread(() ->
155
+ UserMessagingPlatform.loadConsentForm(
156
+ contextSupplier.get(),
157
+ consentForm ->
158
+ consentForm.show(activitySupplier.get(), formError -> {
159
+ if (formError != null) {
160
+ call.reject("Error when show consent form", formError.getMessage());
161
+ } else {
162
+ JSObject consentFormInfo = new JSObject();
163
+ consentFormInfo.put("status", getConsentStatusString(consentInformation.getConsentStatus()));
164
+ consentFormInfo.put("canShowAds", canShowAds());
165
+ consentFormInfo.put("canShowPersonalizedAds", canShowPersonalizedAds());
166
+ call.resolve(consentFormInfo);
167
+ }
168
+ }),
169
+ formError -> call.reject("Error when show consent form", formError.getMessage())
170
+ )
175
171
  );
176
172
  } catch (Exception ex) {
177
173
  call.reject(ex.getLocalizedMessage(), ex);
@@ -38,18 +38,16 @@ public class AdInterstitialExecutor extends Executor {
38
38
  try {
39
39
  activitySupplier
40
40
  .get()
41
- .runOnUiThread(
42
- () -> {
43
- final AdRequest adRequest = RequestHelper.createRequest(adOptions);
44
- final String id = AdViewIdHelper.getFinalAdId(adOptions, adRequest, logTag, contextSupplier.get());
45
- InterstitialAd.load(
46
- activitySupplier.get(),
47
- id,
48
- adRequest,
49
- adCallbackAndListeners.getInterstitialAdLoadCallback(call, notifyListenersFunction)
50
- );
51
- }
52
- );
41
+ .runOnUiThread(() -> {
42
+ final AdRequest adRequest = RequestHelper.createRequest(adOptions);
43
+ final String id = AdViewIdHelper.getFinalAdId(adOptions, adRequest, logTag, contextSupplier.get());
44
+ InterstitialAd.load(
45
+ activitySupplier.get(),
46
+ id,
47
+ adRequest,
48
+ adCallbackAndListeners.getInterstitialAdLoadCallback(call, notifyListenersFunction)
49
+ );
50
+ });
53
51
  } catch (Exception ex) {
54
52
  call.reject(ex.getLocalizedMessage(), ex);
55
53
  }
@@ -66,15 +64,13 @@ public class AdInterstitialExecutor extends Executor {
66
64
 
67
65
  activitySupplier
68
66
  .get()
69
- .runOnUiThread(
70
- () -> {
71
- try {
72
- interstitialAd.show(activitySupplier.get());
73
- call.resolve();
74
- } catch (Exception ex) {
75
- call.reject(ex.getLocalizedMessage(), ex);
76
- }
67
+ .runOnUiThread(() -> {
68
+ try {
69
+ interstitialAd.show(activitySupplier.get());
70
+ call.resolve();
71
+ } catch (Exception ex) {
72
+ call.reject(ex.getLocalizedMessage(), ex);
77
73
  }
78
- );
74
+ });
79
75
  }
80
76
  }
@@ -27,6 +27,7 @@ public abstract class AdOptions {
27
27
  public static final String BANNER_TESTER_ID = "ca-app-pub-3940256099942544/6300978111";
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
+ public static final String REWARD_INTERSTITIAL_TESTER_ID = "ca-app-pub-3940256099942544/5354046379";
30
31
 
31
32
  /**
32
33
  * The position of the ad, it can be TOP_CENTER,
@@ -138,6 +139,15 @@ public abstract class AdOptions {
138
139
  };
139
140
  }
140
141
 
142
+ public AdOptions createRewardInterstitialOptions(PluginCall call) {
143
+ return new AdOptions(call) {
144
+ @Override
145
+ public String getTestingId() {
146
+ return AdOptions.REWARD_INTERSTITIAL_TESTER_ID;
147
+ }
148
+ };
149
+ }
150
+
141
151
  public AdOptions createGenericOptions(PluginCall call, final String testingID) {
142
152
  return new AdOptions(call) {
143
153
  @Override
@@ -34,22 +34,20 @@ public class AdRewardExecutor extends Executor {
34
34
 
35
35
  activitySupplier
36
36
  .get()
37
- .runOnUiThread(
38
- () -> {
39
- try {
40
- final AdRequest adRequest = RequestHelper.createRequest(adOptions);
41
- final String id = AdViewIdHelper.getFinalAdId(adOptions, adRequest, logTag, contextSupplier.get());
42
- RewardedAd.load(
43
- contextSupplier.get(),
44
- id,
45
- adRequest,
46
- RewardedAdCallbackAndListeners.INSTANCE.getRewardedAdLoadCallback(call, notifyListenersFunction, adOptions)
47
- );
48
- } catch (Exception ex) {
49
- call.reject(ex.getLocalizedMessage(), ex);
50
- }
37
+ .runOnUiThread(() -> {
38
+ try {
39
+ final AdRequest adRequest = RequestHelper.createRequest(adOptions);
40
+ final String id = AdViewIdHelper.getFinalAdId(adOptions, adRequest, logTag, contextSupplier.get());
41
+ RewardedAd.load(
42
+ contextSupplier.get(),
43
+ id,
44
+ adRequest,
45
+ RewardedAdCallbackAndListeners.INSTANCE.getRewardedAdLoadCallback(call, notifyListenersFunction, adOptions)
46
+ );
47
+ } catch (Exception ex) {
48
+ call.reject(ex.getLocalizedMessage(), ex);
51
49
  }
52
- );
50
+ });
53
51
  }
54
52
 
55
53
  @PluginMethod
@@ -65,14 +63,12 @@ public class AdRewardExecutor extends Executor {
65
63
  try {
66
64
  activitySupplier
67
65
  .get()
68
- .runOnUiThread(
69
- () -> {
70
- mRewardedAd.show(
71
- activitySupplier.get(),
72
- RewardedAdCallbackAndListeners.INSTANCE.getOnUserEarnedRewardListener(call, notifyListenersFunction)
73
- );
74
- }
75
- );
66
+ .runOnUiThread(() -> {
67
+ mRewardedAd.show(
68
+ activitySupplier.get(),
69
+ RewardedAdCallbackAndListeners.INSTANCE.getOnUserEarnedRewardListener(call, notifyListenersFunction)
70
+ );
71
+ });
76
72
  } catch (Exception ex) {
77
73
  call.reject(ex.getLocalizedMessage(), ex);
78
74
  }
@@ -0,0 +1,80 @@
1
+ package com.getcapacitor.community.admob.rewardedinterstitial;
2
+
3
+ import android.app.Activity;
4
+ import android.content.Context;
5
+ import androidx.core.util.Supplier;
6
+ import com.getcapacitor.JSObject;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginMethod;
9
+ import com.getcapacitor.community.admob.helpers.AdViewIdHelper;
10
+ import com.getcapacitor.community.admob.helpers.RequestHelper;
11
+ import com.getcapacitor.community.admob.models.AdMobPluginError;
12
+ import com.getcapacitor.community.admob.models.AdOptions;
13
+ import com.getcapacitor.community.admob.models.Executor;
14
+ import com.google.android.gms.ads.AdRequest;
15
+ import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;
16
+ import com.google.android.gms.common.util.BiConsumer;
17
+
18
+ public class AdRewardInterstitialExecutor extends Executor {
19
+
20
+ public static RewardedInterstitialAd mRewardedInterstitialAd;
21
+
22
+ public AdRewardInterstitialExecutor(
23
+ Supplier<Context> contextSupplier,
24
+ Supplier<Activity> activitySupplier,
25
+ BiConsumer<String, JSObject> notifyListenersFunction,
26
+ String pluginLogTag
27
+ ) {
28
+ super(contextSupplier, activitySupplier, notifyListenersFunction, pluginLogTag, "AdRewardExecutor");
29
+ }
30
+
31
+ @PluginMethod
32
+ public void prepareRewardInterstitialAd(final PluginCall call, BiConsumer<String, JSObject> notifyListenersFunction) {
33
+ final AdOptions adOptions = AdOptions.getFactory().createRewardInterstitialOptions(call);
34
+
35
+ activitySupplier
36
+ .get()
37
+ .runOnUiThread(() -> {
38
+ try {
39
+ final AdRequest adRequest = RequestHelper.createRequest(adOptions);
40
+ final String id = AdViewIdHelper.getFinalAdId(adOptions, adRequest, logTag, contextSupplier.get());
41
+ RewardedInterstitialAd.load(
42
+ contextSupplier.get(),
43
+ id,
44
+ adRequest,
45
+ RewardedInterstitialAdCallbackAndListeners.INSTANCE.getRewardedAdLoadCallback(
46
+ call,
47
+ notifyListenersFunction,
48
+ adOptions
49
+ )
50
+ );
51
+ } catch (Exception ex) {
52
+ call.reject(ex.getLocalizedMessage(), ex);
53
+ }
54
+ });
55
+ }
56
+
57
+ @PluginMethod
58
+ public void showRewardInterstitialAd(final PluginCall call, BiConsumer<String, JSObject> notifyListenersFunction) {
59
+ if (mRewardedInterstitialAd == null) {
60
+ String errorMessage = "No Reward Video Ad can be show. It was not prepared or maybe it failed to be prepared.";
61
+ call.reject(errorMessage);
62
+ AdMobPluginError errorObject = new AdMobPluginError(-1, errorMessage);
63
+ notifyListenersFunction.accept(RewardInterstitialAdPluginEvents.FailedToLoad, errorObject);
64
+ return;
65
+ }
66
+
67
+ try {
68
+ activitySupplier
69
+ .get()
70
+ .runOnUiThread(() -> {
71
+ mRewardedInterstitialAd.show(
72
+ activitySupplier.get(),
73
+ RewardedInterstitialAdCallbackAndListeners.INSTANCE.getOnUserEarnedRewardListener(call, notifyListenersFunction)
74
+ );
75
+ });
76
+ } catch (Exception ex) {
77
+ call.reject(ex.getLocalizedMessage(), ex);
78
+ }
79
+ }
80
+ }
@@ -0,0 +1,12 @@
1
+ package com.getcapacitor.community.admob.rewardedinterstitial
2
+
3
+ import com.getcapacitor.community.admob.models.LoadPluginEventNames
4
+
5
+ object RewardInterstitialAdPluginEvents: LoadPluginEventNames {
6
+ const val Loaded = "onRewardedInterstitialAdLoaded"
7
+ const val FailedToLoad = "onRewardedInterstitialAdFailedToLoad"
8
+ const val Rewarded = "onRewardedInterstitialAdReward"
9
+ override val Showed = "onRewardedInterstitialAdShowed"
10
+ override val FailedToShow = "onRewardedInterstitialAdFailedToShow"
11
+ override val Dismissed = "onRewardedInterstitialAdDismissed"
12
+ }
@@ -0,0 +1,50 @@
1
+ package com.getcapacitor.community.admob.rewardedinterstitial
2
+
3
+ import com.getcapacitor.JSObject
4
+ import com.getcapacitor.PluginCall
5
+ import com.getcapacitor.community.admob.helpers.FullscreenPluginCallback
6
+ import com.getcapacitor.community.admob.models.AdMobPluginError
7
+ import com.getcapacitor.community.admob.models.AdOptions
8
+ import com.google.android.gms.ads.LoadAdError
9
+ import com.google.android.gms.ads.OnUserEarnedRewardListener
10
+ import com.google.android.gms.ads.rewarded.RewardItem
11
+ import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd
12
+ import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback
13
+ import com.google.android.gms.common.util.BiConsumer
14
+
15
+ object RewardedInterstitialAdCallbackAndListeners {
16
+
17
+ fun getOnUserEarnedRewardListener(call: PluginCall, notifyListenersFunction: BiConsumer<String, JSObject>): OnUserEarnedRewardListener {
18
+ return OnUserEarnedRewardListener { item: RewardItem ->
19
+ val response = JSObject()
20
+ response.put("type", item.type)
21
+ .put("amount", item.amount)
22
+ notifyListenersFunction.accept(RewardInterstitialAdPluginEvents.Rewarded, response)
23
+ call.resolve(response)
24
+ }
25
+ }
26
+
27
+ fun getRewardedAdLoadCallback(call: PluginCall, notifyListenersFunction: BiConsumer<String, JSObject>, adOptions: AdOptions): RewardedInterstitialAdLoadCallback {
28
+ return object : RewardedInterstitialAdLoadCallback() {
29
+ override fun onAdLoaded(ad: RewardedInterstitialAd) {
30
+ AdRewardInterstitialExecutor.mRewardedInterstitialAd = ad
31
+ AdRewardInterstitialExecutor.mRewardedInterstitialAd.fullScreenContentCallback = FullscreenPluginCallback(
32
+ RewardInterstitialAdPluginEvents, notifyListenersFunction)
33
+
34
+ val adInfo = JSObject()
35
+ adInfo.put("adUnitId", ad.adUnitId)
36
+ call.resolve(adInfo)
37
+
38
+ notifyListenersFunction.accept(RewardInterstitialAdPluginEvents.Loaded, adInfo)
39
+ }
40
+
41
+ override fun onAdFailedToLoad(adError: LoadAdError) {
42
+ val adMobError = AdMobPluginError(adError)
43
+
44
+ notifyListenersFunction.accept(RewardInterstitialAdPluginEvents.FailedToLoad, adMobError)
45
+ call.reject(adError.message)
46
+ }
47
+ }
48
+ }
49
+
50
+ }