emi-indo-cordova-plugin-admob 1.5.3 → 1.5.5

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.
@@ -1,5 +1,4 @@
1
1
  package emi.indo.cordova.plugin.admob
2
- import android.R
3
2
  import android.annotation.SuppressLint
4
3
  import android.app.Activity
5
4
  import android.content.Context
@@ -154,34 +153,37 @@ class emiAdmobPlugin : CordovaPlugin() {
154
153
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.screen.rotated');")
155
154
  isOrientation = orientation
156
155
  if (this.isAutoResize) {
157
- mActivity!!.runOnUiThread {
158
- try {
159
- if (bannerViewLayout != null && bannerView != null) {
160
- val parentView = bannerViewLayout!!.parent as ViewGroup
161
- parentView.removeView(bannerViewLayout)
162
- bannerViewLayout = FrameLayout(mActivity!!)
163
- val params = FrameLayout.LayoutParams(
164
- FrameLayout.LayoutParams.MATCH_PARENT,
165
- FrameLayout.LayoutParams.WRAP_CONTENT
166
- )
167
- val rootView = mActivity!!.window.decorView.findViewById<View>(View.generateViewId())
168
- if (rootView is ViewGroup) {
169
- rootView.addView(bannerViewLayout, params)
170
- } else {
171
- mActivity!!.addContentView(bannerViewLayout, params)
156
+ if(mActivity != null) {
157
+ mActivity!!.runOnUiThread {
158
+ try {
159
+ if (bannerViewLayout != null && bannerView != null) {
160
+ val parentView = bannerViewLayout!!.parent as ViewGroup
161
+ parentView.removeView(bannerViewLayout)
162
+ bannerViewLayout = FrameLayout(mActivity!!)
163
+ val params = FrameLayout.LayoutParams(
164
+ FrameLayout.LayoutParams.MATCH_PARENT,
165
+ FrameLayout.LayoutParams.WRAP_CONTENT
166
+ )
167
+ val rootView =
168
+ mActivity!!.window.decorView.findViewById<View>(View.generateViewId())
169
+ if (rootView is ViewGroup) {
170
+ rootView.addView(bannerViewLayout, params)
171
+ } else {
172
+ mActivity!!.addContentView(bannerViewLayout, params)
173
+ }
174
+ bannerView = AdView(mContext!!)
175
+ setBannerPosition(this.isPosition)
176
+ setBannerSiz(this.isSize)
177
+ bannerView!!.adUnitId = bannerAdUnitId!!
178
+ bannerView!!.adListener = bannerAdListener
179
+ bannerView!!.loadAd(buildAdRequest())
180
+ adjustWebViewForBanner(this.isPosition)
181
+ bannerViewLayout!!.addView(bannerView)
182
+ bannerViewLayout!!.bringToFront()
172
183
  }
173
- bannerView = AdView(mContext!!)
174
- setBannerPosition(this.isPosition)
175
- setBannerSiz(this.isSize)
176
- bannerView!!.adUnitId = bannerAdUnitId!!
177
- bannerView!!.adListener = bannerAdListener
178
- bannerView!!.loadAd(buildAdRequest())
179
- adjustWebViewForBanner(this.isPosition)
180
- bannerViewLayout!!.addView(bannerView)
181
- bannerViewLayout!!.bringToFront()
184
+ } catch (e: Exception) {
185
+ PUBLIC_CALLBACKS!!.error("Error adjusting banner size: " + e.message)
182
186
  }
183
- } catch (e: Exception) {
184
- PUBLIC_CALLBACKS!!.error("Error adjusting banner size: " + e.message)
185
187
  }
186
188
  }
187
189
  }
@@ -214,456 +216,535 @@ class emiAdmobPlugin : CordovaPlugin() {
214
216
 
215
217
  if (action == "initialize") {
216
218
  val options = args.getJSONObject(0)
217
- mActivity!!.runOnUiThread {
218
- val setAdRequest = options.optBoolean("isUsingAdManagerRequest")
219
- val responseInfo = options.optBoolean("isResponseInfo")
220
- val setDebugGeography = options.optBoolean("isConsentDebug")
221
- setUsingAdManagerRequest(setAdRequest)
222
- this.isResponseInfo = responseInfo
223
- this.setDebugGeography = setDebugGeography
224
- val params: ConsentRequestParameters
225
- if (this.setDebugGeography) {
226
- val debugSettings = mActivity?.let {
227
- deviceId?.let { it1 ->
228
- ConsentDebugSettings.Builder(it)
229
- .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
230
- .addTestDeviceHashedId(it1).build()
219
+ if(mActivity != null) {
220
+ mActivity!!.runOnUiThread {
221
+ val setAdRequest = options.optBoolean("isUsingAdManagerRequest")
222
+ val responseInfo = options.optBoolean("isResponseInfo")
223
+ val setDebugGeography = options.optBoolean("isConsentDebug")
224
+ setUsingAdManagerRequest(setAdRequest)
225
+ this.isResponseInfo = responseInfo
226
+ this.setDebugGeography = setDebugGeography
227
+ val params: ConsentRequestParameters
228
+ if (this.setDebugGeography) {
229
+ val debugSettings = mActivity?.let {
230
+ deviceId?.let { it1 ->
231
+ ConsentDebugSettings.Builder(it)
232
+ .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
233
+ .addTestDeviceHashedId(it1).build()
234
+ }
231
235
  }
236
+ params = ConsentRequestParameters.Builder()
237
+ .setConsentDebugSettings(debugSettings).build()
238
+ } else {
239
+ params = ConsentRequestParameters.Builder()
240
+ .setTagForUnderAgeOfConsent(this.isSetTagForUnderAgeOfConsent).build()
232
241
  }
233
- params = ConsentRequestParameters.Builder()
234
- .setConsentDebugSettings(debugSettings).build()
235
- } else {
236
- params = ConsentRequestParameters.Builder()
237
- .setTagForUnderAgeOfConsent(this.isSetTagForUnderAgeOfConsent).build()
238
- }
239
242
 
240
- consentInformation = mContext?.let { UserMessagingPlatform.getConsentInformation(it) }
241
- mActivity?.let {
242
- consentInformation?.requestConsentInfoUpdate(
243
- it,
244
- params,
245
- {
246
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update');")
247
- when (consentInformation!!.getConsentStatus()) {
248
- ConsentInformation.ConsentStatus.NOT_REQUIRED -> cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.not_required');")
249
- ConsentInformation.ConsentStatus.OBTAINED -> cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.obtained');")
250
- ConsentInformation.ConsentStatus.REQUIRED -> {
251
- handleConsentForm()
252
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.required');")
253
- }
243
+ consentInformation =
244
+ mContext?.let { UserMessagingPlatform.getConsentInformation(it) }
245
+ mActivity?.let {
246
+ consentInformation?.requestConsentInfoUpdate(
247
+ it,
248
+ params,
249
+ {
250
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update');")
251
+ when (consentInformation!!.getConsentStatus()) {
252
+ ConsentInformation.ConsentStatus.NOT_REQUIRED -> cWebView!!.loadUrl(
253
+ "javascript:cordova.fireDocumentEvent('on.consent.status.not_required');"
254
+ )
255
+
256
+ ConsentInformation.ConsentStatus.OBTAINED -> cWebView!!.loadUrl(
257
+ "javascript:cordova.fireDocumentEvent('on.consent.status.obtained');"
258
+ )
259
+
260
+ ConsentInformation.ConsentStatus.REQUIRED -> {
261
+ handleConsentForm()
262
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.required');")
263
+ }
254
264
 
255
- ConsentInformation.ConsentStatus.UNKNOWN -> cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.unknown');")
256
- }
257
- },
258
- { formError: FormError ->
259
- if (consentInformation!!.canRequestAds()) {
260
- initializeMobileAdsSdk()
261
- }
262
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed', { message: '" + formError.message + "' });")
263
- })
264
- }
265
- if (consentInformation?.canRequestAds()!!) {
266
- initializeMobileAdsSdk()
265
+ ConsentInformation.ConsentStatus.UNKNOWN -> cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.unknown');")
266
+ }
267
+ },
268
+ { formError: FormError ->
269
+ if (consentInformation!!.canRequestAds()) {
270
+ initializeMobileAdsSdk()
271
+ }
272
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed', { message: '" + formError.message + "' });")
273
+ })
274
+ }
275
+ if (consentInformation?.canRequestAds()!!) {
276
+ initializeMobileAdsSdk()
277
+ }
267
278
  }
268
279
  }
269
280
 
270
281
  return true
271
282
  } else if (action == "targeting") {
272
283
  val options = args.getJSONObject(0)
273
- mActivity!!.runOnUiThread {
274
- try {
275
- val childDirectedTreatment = options.optBoolean("childDirectedTreatment")
276
- val underAgeOfConsent = options.optBoolean("underAgeOfConsent")
277
- val contentRating = options.optString("contentRating")
278
- this.isSetTagForChildDirectedTreatment = childDirectedTreatment
279
- this.isSetTagForUnderAgeOfConsent = underAgeOfConsent
280
- this.isSetMaxAdContentRating = contentRating
281
- Targeting(childDirectedTreatment, underAgeOfConsent, contentRating)
282
- // callbackContext.success();
283
- } catch (e: Exception) {
284
- callbackContext.error("Error: " + e.message)
284
+ if(mActivity != null) {
285
+ mActivity!!.runOnUiThread {
286
+ try {
287
+ val childDirectedTreatment = options.optBoolean("childDirectedTreatment")
288
+ val underAgeOfConsent = options.optBoolean("underAgeOfConsent")
289
+ val contentRating = options.optString("contentRating")
290
+ this.isSetTagForChildDirectedTreatment = childDirectedTreatment
291
+ this.isSetTagForUnderAgeOfConsent = underAgeOfConsent
292
+ this.isSetMaxAdContentRating = contentRating
293
+ targeting(childDirectedTreatment, underAgeOfConsent, contentRating)
294
+ callbackContext.success();
295
+ } catch (e: Exception) {
296
+ callbackContext.error("Error: " + e.message)
297
+ }
285
298
  }
286
299
  }
287
300
  return true
288
301
  } else if (action == "targetingAdRequest") {
289
302
  val options = args.getJSONObject(0)
290
- mActivity!!.runOnUiThread {
291
- val customTargetingEnabled = options.optBoolean("customTargetingEnabled")
292
- val categoryExclusionsEnabled = options.optBoolean("categoryExclusionsEnabled")
293
- val ppIdEnabled = options.optBoolean("ppIdEnabled")
294
- val contentURLEnabled = options.optBoolean("contentURLEnabled")
295
- val brandSafetyEnabled = options.optBoolean("brandSafetyEnabled")
296
-
297
- val customTargeting = options.optJSONArray("customTargetingValue")
298
- val categoryExclusions = options.optString("categoryExclusionsValue")
299
- val ppId = options.optString("ppIdValue")
300
- val ctURL = options.optString("contentURLValue")
301
- val brandSafetyArr = options.optJSONArray("brandSafetyArr")
302
- try {
303
- this.customTargetingEnabled = customTargetingEnabled
304
- this.categoryExclusionsEnabled = categoryExclusionsEnabled
305
- this.ppIdEnabled = ppIdEnabled
306
- this.contentURLEnabled = contentURLEnabled
307
- this.brandSafetyEnabled = brandSafetyEnabled
308
- this.cExclusionsValue = categoryExclusions
309
- this.ppIdVl = ppId
310
- this.cURLVl = ctURL
311
- targetingAdRequest(
312
- customTargeting,
313
- categoryExclusions,
314
- ppId,
315
- ctURL,
316
- brandSafetyArr
317
- )
318
- callbackContext.success()
319
- } catch (e: Exception) {
320
- callbackContext.error(e.toString())
303
+ if(mActivity != null) {
304
+ mActivity!!.runOnUiThread {
305
+ val customTargetingEnabled = options.optBoolean("customTargetingEnabled")
306
+ val categoryExclusionsEnabled = options.optBoolean("categoryExclusionsEnabled")
307
+ val ppIdEnabled = options.optBoolean("ppIdEnabled")
308
+ val contentURLEnabled = options.optBoolean("contentURLEnabled")
309
+ val brandSafetyEnabled = options.optBoolean("brandSafetyEnabled")
310
+
311
+ val customTargeting = options.optJSONArray("customTargetingValue")
312
+ val categoryExclusions = options.optString("categoryExclusionsValue")
313
+ val ppId = options.optString("ppIdValue")
314
+ val ctURL = options.optString("contentURLValue")
315
+ val brandSafetyArr = options.optJSONArray("brandSafetyArr")
316
+ try {
317
+ this.customTargetingEnabled = customTargetingEnabled
318
+ this.categoryExclusionsEnabled = categoryExclusionsEnabled
319
+ this.ppIdEnabled = ppIdEnabled
320
+ this.contentURLEnabled = contentURLEnabled
321
+ this.brandSafetyEnabled = brandSafetyEnabled
322
+ this.cExclusionsValue = categoryExclusions
323
+ this.ppIdVl = ppId
324
+ this.cURLVl = ctURL
325
+ targetingAdRequest(
326
+ customTargeting,
327
+ categoryExclusions,
328
+ ppId,
329
+ ctURL,
330
+ brandSafetyArr
331
+ )
332
+ callbackContext.success()
333
+ } catch (e: Exception) {
334
+ callbackContext.error(e.toString())
335
+ }
321
336
  }
322
337
  }
323
338
  return true
324
339
  } else if (action == "setPersonalizationState") {
325
340
  val options = args.getJSONObject(0)
326
- mActivity!!.runOnUiThread {
327
- val setPPT = options.optString("setPersonalizationState")
328
- try {
329
- setPersonalizationState(setPPT)
330
- callbackContext.success()
331
- } catch (e: Exception) {
332
- callbackContext.error(e.toString())
341
+ if(mActivity != null) {
342
+ mActivity!!.runOnUiThread {
343
+ val setPPT = options.optString("setPersonalizationState")
344
+ try {
345
+ setPersonalizationState(setPPT)
346
+ callbackContext.success()
347
+ } catch (e: Exception) {
348
+ callbackContext.error(e.toString())
349
+ }
333
350
  }
334
351
  }
335
352
  return true
336
353
  } else if (action == "setPPS") {
337
354
  val options = args.getJSONObject(0)
338
- mActivity!!.runOnUiThread {
339
- val ppsEnabled = options.optBoolean("ppsEnabled")
340
- val iabContent = options.optString("iabContent")
341
- val ppsArrValue = options.optJSONArray("ppsArrValue")
342
- try {
343
- this.ppsEnabled = ppsEnabled
344
- this.ppsVl = iabContent
345
- setPublisherProvidedSignals(ppsArrValue)
346
- callbackContext.success()
347
- } catch (e: Exception) {
348
- callbackContext.error(e.toString())
355
+ if(mActivity != null) {
356
+ mActivity!!.runOnUiThread {
357
+ val ppsEnabled = options.optBoolean("ppsEnabled")
358
+ val iabContent = options.optString("iabContent")
359
+ val ppsArrValue = options.optJSONArray("ppsArrValue")
360
+ try {
361
+ this.ppsEnabled = ppsEnabled
362
+ this.ppsVl = iabContent
363
+ setPublisherProvidedSignals(ppsArrValue)
364
+ callbackContext.success()
365
+ } catch (e: Exception) {
366
+ callbackContext.error(e.toString())
367
+ }
349
368
  }
350
369
  }
351
370
  return true
352
371
  } else if (action == "globalSettings") {
353
372
  val options = args.getJSONObject(0)
354
- mActivity!!.runOnUiThread {
355
- val setAppMuted = options.optBoolean("setAppMuted")
356
- val setAppVolume = options.optInt("setAppVolume").toFloat()
357
- val pubIdEnabled = options.optBoolean("pubIdEnabled")
358
- try {
359
- globalSettings(setAppMuted, setAppVolume, pubIdEnabled)
360
- // callbackContext.success();
361
- } catch (e: Exception) {
362
- callbackContext.error(e.toString())
373
+ if(mActivity != null) {
374
+ mActivity!!.runOnUiThread {
375
+ val setAppMuted = options.optBoolean("setAppMuted")
376
+ val setAppVolume = options.optInt("setAppVolume").toFloat()
377
+ val pubIdEnabled = options.optBoolean("pubIdEnabled")
378
+ try {
379
+ globalSettings(setAppMuted, setAppVolume, pubIdEnabled)
380
+ } catch (e: Exception) {
381
+ callbackContext.error(e.toString())
382
+ }
363
383
  }
364
384
  }
365
385
  return true
366
386
  } else if (action == "loadAppOpenAd") {
367
387
  val options = args.getJSONObject(0)
368
- mActivity!!.runOnUiThread {
369
- val adUnitId = options.optString("adUnitId")
370
- val autoShow = options.optBoolean("autoShow")
371
- try {
372
- this.appOpenAutoShow = autoShow
373
- AppOpenAd.load(
374
- mActivity!!, adUnitId, buildAdRequest(),
375
- object : AppOpenAdLoadCallback() {
376
- @SuppressLint("DefaultLocale")
377
- override fun onAdLoaded(ad: AppOpenAd) {
378
- appOpenAd = ad
379
- isAppOpenAdShow = true
380
-
381
- if (appOpenAutoShow) {
382
- openAutoShow()
383
- }
388
+ if(mActivity != null) {
389
+ mActivity!!.runOnUiThread {
390
+ val adUnitId = options.optString("adUnitId")
391
+ val autoShow = options.optBoolean("autoShow")
392
+ try {
393
+ this.appOpenAutoShow = autoShow
394
+ AppOpenAd.load(
395
+ mActivity!!, adUnitId, buildAdRequest(),
396
+ object : AppOpenAdLoadCallback() {
397
+ @SuppressLint("DefaultLocale")
398
+ override fun onAdLoaded(ad: AppOpenAd) {
399
+ appOpenAd = ad
400
+ isAppOpenAdShow = true
401
+
402
+ if (appOpenAutoShow) {
403
+ openAutoShow()
404
+ }
405
+
406
+ cWebView!!.loadUrl(
407
+ "javascript:cordova.fireDocumentEvent('on.appOpenAd.loaded');"
408
+ )
384
409
 
385
- appOpenAdLoadCallback(callbackContext)
410
+ appOpenAdLoadCallback()
386
411
 
387
- appOpenAd!!.onPaidEventListener =
388
- OnPaidEventListener { adValue: AdValue ->
389
- val valueMicros = adValue.valueMicros
390
- val currencyCode = adValue.currencyCode
391
- val precision = adValue.precisionType
392
- val appOpenAdAdUnitId = appOpenAd!!.adUnitId
412
+ appOpenAd!!.onPaidEventListener =
413
+ OnPaidEventListener { adValue: AdValue ->
414
+ val valueMicros = adValue.valueMicros
415
+ val currencyCode = adValue.currencyCode
416
+ val precision = adValue.precisionType
417
+ val appOpenAdAdUnitId = appOpenAd!!.adUnitId
393
418
 
419
+ val result = JSONObject()
420
+ try {
421
+ result.put("micros", valueMicros)
422
+ result.put("currency", currencyCode)
423
+ result.put("precision", precision)
424
+ result.put("adUnitId", appOpenAdAdUnitId)
425
+
426
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.revenue', ${result})")
427
+
428
+ } catch (e: JSONException) {
429
+ callbackContext.error(e.message)
430
+ }
431
+ }
432
+
433
+ if (isResponseInfo) {
394
434
  val result = JSONObject()
435
+ val responseInfo = ad.responseInfo
395
436
  try {
396
- result.put("micros", valueMicros)
397
- result.put("currency", currencyCode)
398
- result.put("precision", precision)
399
- result.put("adUnitId", appOpenAdAdUnitId)
400
- callbackContext.success(result)
401
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.revenue')")
402
-
437
+ result.put("getResponseId", responseInfo.responseId)
438
+ result.put(
439
+ "getAdapterResponses",
440
+ responseInfo.adapterResponses
441
+ )
442
+ result.put(
443
+ "getResponseExtras",
444
+ responseInfo.responseExtras
445
+ )
446
+ result.put(
447
+ "getMediationAdapterClassName",
448
+ responseInfo.mediationAdapterClassName
449
+ )
450
+ result.put("getBundleExtra", mBundleExtra.toString())
451
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.responseInfo', ${result})")
403
452
  } catch (e: JSONException) {
404
453
  callbackContext.error(e.message)
405
454
  }
406
455
  }
407
456
 
408
- if (isResponseInfo) {
409
- val result = JSONObject()
410
- val responseInfo = ad.responseInfo
411
- try {
412
- result.put("getResponseId", responseInfo.responseId)
413
- result.put(
414
- "getAdapterResponses",
415
- responseInfo.adapterResponses
416
- )
417
- result.put("getResponseExtras", responseInfo.responseExtras)
418
- result.put(
419
- "getMediationAdapterClassName",
420
- responseInfo.mediationAdapterClassName
421
- )
422
- result.put("getBundleExtra", mBundleExtra.toString())
423
- callbackContext.success(result)
424
- } catch (e: JSONException) {
425
- callbackContext.error(e.message)
426
- }
427
- }
428
457
 
429
- cWebView!!.loadUrl(
430
- "javascript:cordova.fireDocumentEvent('on.appOpenAd.loaded');"
431
- )
432
458
 
433
- }
459
+ }
434
460
 
435
- private fun openAutoShow() {
436
- try {
437
- if (isAppOpenAdShow && appOpenAd != null) {
438
- mActivity!!.runOnUiThread { appOpenAd!!.show(mActivity!!) }
439
- }
440
- } catch (e: Exception) {
441
- PUBLIC_CALLBACKS!!.error(e.toString())
461
+ private fun openAutoShow() {
462
+ try {
463
+ if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
464
+ mActivity!!.runOnUiThread {
465
+ appOpenAd!!.show(
466
+ mActivity!!
467
+ )
468
+ }
469
+ }
470
+ } catch (e: Exception) {
471
+ PUBLIC_CALLBACKS!!.error(e.toString())
472
+ }
442
473
  }
443
- }
444
474
 
445
- override fun onAdFailedToLoad(loadAdError: LoadAdError) {
446
- isAppOpenAdShow = false
447
- callbackContext.error(loadAdError.toString())
448
- cWebView!!.loadUrl(
449
- "javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.loaded');"
450
- )
451
- }
452
- })
453
- } catch (e: Exception) {
454
- callbackContext.error(e.toString())
475
+ override fun onAdFailedToLoad(loadAdError: LoadAdError) {
476
+ isAppOpenAdShow = false
477
+ val errorData = JSONObject().apply {
478
+ put("responseInfo", loadAdError.responseInfo)
479
+ put("code", loadAdError.code)
480
+ put("message", loadAdError.message)
481
+ put("domain", loadAdError.domain)
482
+ put("cause", loadAdError.cause?.toString() ?: "null")
483
+ }
484
+ cWebView!!.loadUrl(
485
+ "javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.loaded, ${errorData}');"
486
+ )
487
+ }
488
+ })
489
+ } catch (e: Exception) {
490
+ callbackContext.error(e.toString())
491
+ }
455
492
  }
456
493
  }
457
494
  return true
458
495
  } else if (action == "showAppOpenAd") {
459
- try {
460
- if (isAppOpenAdShow && appOpenAd != null) {
461
- mActivity!!.runOnUiThread { appOpenAd!!.show(mActivity!!) }
462
- appOpenAdLoadCallback(callbackContext)
463
- } else {
464
- callbackContext.error("The App Open Ad wasn't ready yet")
496
+
497
+ try {
498
+ if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
499
+ mActivity!!.runOnUiThread { appOpenAd!!.show(mActivity!!) }
500
+ appOpenAdLoadCallback()
501
+ } else {
502
+ callbackContext.error("The App Open Ad wasn't ready yet")
503
+ }
504
+ } catch (e: Exception) {
505
+ PUBLIC_CALLBACKS!!.error(e.toString())
465
506
  }
466
- } catch (e: Exception) {
467
- PUBLIC_CALLBACKS!!.error(e.toString())
468
- }
469
507
 
470
508
  return true
471
509
  } else if (action == "loadInterstitialAd") {
472
510
  val options = args.getJSONObject(0)
473
- mActivity!!.runOnUiThread {
474
- val adUnitId = options.optString("adUnitId")
475
- val autoShow = options.optBoolean("autoShow")
476
- try {
477
- this.intAutoShow = autoShow
478
- InterstitialAd.load(
479
- mActivity!!, adUnitId, buildAdRequest(),
480
- object : InterstitialAdLoadCallback() {
481
- override fun onAdLoaded(interstitialAd: InterstitialAd) {
482
- isInterstitialLoad = true
483
- mInterstitialAd = interstitialAd
484
-
485
- if (intAutoShow) {
486
- isIntAutoShow
487
- }
511
+ if(mActivity != null) {
512
+ mActivity!!.runOnUiThread {
513
+ val adUnitId = options.optString("adUnitId")
514
+ val autoShow = options.optBoolean("autoShow")
515
+ try {
516
+ this.intAutoShow = autoShow
517
+ InterstitialAd.load(
518
+ mActivity!!, adUnitId, buildAdRequest(),
519
+ object : InterstitialAdLoadCallback() {
520
+ override fun onAdLoaded(interstitialAd: InterstitialAd) {
521
+ isInterstitialLoad = true
522
+ mInterstitialAd = interstitialAd
523
+
524
+ if (intAutoShow) {
525
+ isIntAutoShow
526
+ }
488
527
 
489
- interstitialAdLoadCallback(callbackContext)
528
+ cWebView!!.loadUrl(
529
+ "javascript:cordova.fireDocumentEvent('on.interstitial.loaded');"
530
+ )
490
531
 
491
- cWebView!!.loadUrl(
492
- "javascript:cordova.fireDocumentEvent('on.interstitial.loaded');"
493
- )
494
- if (isResponseInfo) {
495
- val result = JSONObject()
496
- val responseInfo = mInterstitialAd!!.responseInfo
497
- try {
498
- result.put("getResponseId", responseInfo.responseId)
499
- result.put(
500
- "getAdapterResponses",
501
- responseInfo.adapterResponses
502
- )
503
- result.put("getResponseExtras", responseInfo.responseExtras)
504
- result.put(
505
- "getMediationAdapterClassName",
506
- responseInfo.mediationAdapterClassName
507
- )
508
- result.put("getBundleExtra", mBundleExtra.toString())
509
- callbackContext.success(result)
510
- } catch (e: JSONException) {
511
- callbackContext.error(e.message)
512
- }
513
- }
514
- mInterstitialAd!!.onPaidEventListener =
515
- OnPaidEventListener { adValue: AdValue ->
516
- val valueMicros = adValue.valueMicros
517
- val currencyCode = adValue.currencyCode
518
- val precision = adValue.precisionType
519
- val interstitialAdUnitId = mInterstitialAd!!.adUnitId
532
+ interstitialAdLoadCallback()
533
+
534
+ if (isResponseInfo) {
520
535
  val result = JSONObject()
536
+ val responseInfo = mInterstitialAd!!.responseInfo
521
537
  try {
522
- result.put("micros", valueMicros)
523
- result.put("currency", currencyCode)
524
- result.put("precision", precision)
525
- result.put("adUnitId", interstitialAdUnitId)
526
- callbackContext.success(result)
538
+ result.put("getResponseId", responseInfo.responseId)
539
+ result.put(
540
+ "getAdapterResponses",
541
+ responseInfo.adapterResponses
542
+ )
543
+ result.put("getResponseExtras", responseInfo.responseExtras)
544
+ result.put(
545
+ "getMediationAdapterClassName",
546
+ responseInfo.mediationAdapterClassName
547
+ )
548
+ result.put("getBundleExtra", mBundleExtra.toString())
549
+ cWebView!!.loadUrl(
550
+ "javascript:cordova.fireDocumentEvent('on.interstitialAd.responseInfo', ${result});"
551
+ )
552
+
527
553
  } catch (e: JSONException) {
528
554
  callbackContext.error(e.message)
529
555
  }
530
- cWebView!!.loadUrl(
531
- "javascript:cordova.fireDocumentEvent('on.interstitial.revenue');"
532
- )
533
556
  }
534
- }
557
+ mInterstitialAd!!.onPaidEventListener =
558
+ OnPaidEventListener { adValue: AdValue ->
559
+ val valueMicros = adValue.valueMicros
560
+ val currencyCode = adValue.currencyCode
561
+ val precision = adValue.precisionType
562
+ val interstitialAdUnitId = mInterstitialAd!!.adUnitId
563
+ val result = JSONObject()
564
+ try {
565
+ result.put("micros", valueMicros)
566
+ result.put("currency", currencyCode)
567
+ result.put("precision", precision)
568
+ result.put("adUnitId", interstitialAdUnitId)
569
+ cWebView!!.loadUrl(
570
+ "javascript:cordova.fireDocumentEvent('on.interstitial.revenue', ${result});"
571
+ )
535
572
 
536
- private val isIntAutoShow: Unit
537
- get() {
538
- if (isInterstitialLoad && mInterstitialAd != null) {
539
- mActivity!!.runOnUiThread { mInterstitialAd!!.show(mActivity!!) }
540
- }
573
+ } catch (e: JSONException) {
574
+ callbackContext.error(e.message)
575
+ }
576
+
577
+ }
541
578
  }
542
579
 
543
- override fun onAdFailedToLoad(loadAdError: LoadAdError) {
544
- mInterstitialAd = null
545
- isInterstitialLoad = false
546
- cWebView!!.loadUrl(
547
- "javascript:cordova.fireDocumentEvent('on.interstitial.failed.load');"
548
- )
549
- callbackContext.error(loadAdError.toString())
550
- }
551
- })
552
- } catch (e: Exception) {
553
- callbackContext.error(e.toString())
580
+ private val isIntAutoShow: Unit
581
+ get() {
582
+ if (mActivity != null && isInterstitialLoad && mInterstitialAd != null) {
583
+ mActivity!!.runOnUiThread { mInterstitialAd!!.show(mActivity!!) }
584
+ }
585
+ }
586
+
587
+ override fun onAdFailedToLoad(loadAdError: LoadAdError) {
588
+ mInterstitialAd = null
589
+ isInterstitialLoad = false
590
+ val errorData = JSONObject().apply {
591
+ put("responseInfo", loadAdError.responseInfo)
592
+ put("code", loadAdError.code)
593
+ put("message", loadAdError.message)
594
+ put("domain", loadAdError.domain)
595
+ put("cause", loadAdError.cause?.toString() ?: "null")
596
+ }
597
+ cWebView!!.loadUrl(
598
+ "javascript:cordova.fireDocumentEvent('on.interstitial.failed.load', ${errorData});"
599
+ )
600
+
601
+ }
602
+ })
603
+ } catch (e: Exception) {
604
+ callbackContext.error(e.toString())
605
+ }
554
606
  }
555
607
  }
556
608
  return true
557
609
  } else if (action == "showInterstitialAd") {
558
- if (isInterstitialLoad && mInterstitialAd != null) {
559
- mActivity!!.runOnUiThread { mInterstitialAd!!.show(mActivity!!) }
560
- interstitialAdLoadCallback(callbackContext)
561
- } else {
562
- callbackContext.error("The Interstitial ad wasn't ready yet")
563
- }
610
+
611
+ if (mActivity != null && isInterstitialLoad && mInterstitialAd != null) {
612
+ mActivity!!.runOnUiThread { mInterstitialAd!!.show(mActivity!!) }
613
+ interstitialAdLoadCallback()
614
+ } else {
615
+ callbackContext.error("The Interstitial ad wasn't ready yet")
616
+ }
564
617
  return true
565
618
  } else if (action == "loadRewardedAd") {
566
619
  val options = args.getJSONObject(0)
567
- mActivity!!.runOnUiThread {
568
- val adUnitId = options.optString("adUnitId")
569
- val autoShow = options.optBoolean("autoShow")
570
- try {
571
- this.rewardedAutoShow = autoShow
572
- RewardedAd.load(
573
- mActivity!!, adUnitId, buildAdRequest(),
574
- object : RewardedAdLoadCallback() {
575
- override fun onAdFailedToLoad(loadAdError: LoadAdError) {
576
- rewardedAd = null
577
- isRewardedLoad = false
578
- cWebView!!.loadUrl(
579
- "javascript:cordova.fireDocumentEvent('on.rewarded.failed.load');"
580
- )
581
- callbackContext.error(loadAdError.toString())
582
- }
583
-
584
- override fun onAdLoaded(ad: RewardedAd) {
585
- rewardedAd = ad
586
- isRewardedLoad = true
587
- isAdSkip = 0
588
- if (rewardedAutoShow) {
589
- isRewardedAutoShow
590
- }
591
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.loaded');")
592
- rewardedAdLoadCallback(callbackContext)
593
- if (isResponseInfo) {
594
- val result = JSONObject()
595
- val responseInfo = ad.responseInfo
596
- try {
597
- result.put("getResponseId", responseInfo.responseId)
598
- result.put(
599
- "getAdapterResponses",
600
- responseInfo.adapterResponses
601
- )
602
- result.put("getResponseExtras", responseInfo.responseExtras)
603
- result.put(
604
- "getMediationAdapterClassName",
605
- responseInfo.mediationAdapterClassName
606
- )
607
- result.put("getBundleExtra", mBundleExtra.toString())
608
- callbackContext.success(result)
609
- } catch (e: JSONException) {
610
- callbackContext.error(e.message)
620
+ if(mActivity != null) {
621
+ mActivity!!.runOnUiThread {
622
+ val adUnitId = options.optString("adUnitId")
623
+ val autoShow = options.optBoolean("autoShow")
624
+ try {
625
+ this.rewardedAutoShow = autoShow
626
+ RewardedAd.load(
627
+ mActivity!!, adUnitId, buildAdRequest(),
628
+ object : RewardedAdLoadCallback() {
629
+ override fun onAdFailedToLoad(loadAdError: LoadAdError) {
630
+ rewardedAd = null
631
+ isRewardedLoad = false
632
+
633
+ val errorData = JSONObject().apply {
634
+ put("responseInfo", loadAdError.responseInfo)
635
+ put("code", loadAdError.code)
636
+ put("message", loadAdError.message)
637
+ put("domain", loadAdError.domain)
638
+ put("cause", loadAdError.cause?.toString() ?: "null")
611
639
  }
640
+
641
+ cWebView!!.loadUrl(
642
+ "javascript:cordova.fireDocumentEvent('on.rewarded.failed.load', ${errorData});"
643
+ )
644
+
612
645
  }
613
646
 
614
- rewardedAd!!.onPaidEventListener =
615
- OnPaidEventListener { adValue: AdValue ->
616
- val valueMicros = adValue.valueMicros
617
- val currencyCode = adValue.currencyCode
618
- val precision = adValue.precisionType
619
- val rewardedAdAdUnitId = rewardedAd!!.adUnitId
620
- val result = JSONObject()
621
- try {
622
- result.put("micros", valueMicros)
623
- result.put("currency", currencyCode)
624
- result.put("precision", precision)
625
- result.put("adUnitId", rewardedAdAdUnitId)
626
- callbackContext.success(result)
627
- } catch (e: JSONException) {
628
- callbackContext.error(e.message)
629
- }
630
- cWebView!!.loadUrl(
631
- "javascript:cordova.fireDocumentEvent('on.rewarded.revenue');"
632
- )
647
+ override fun onAdLoaded(ad: RewardedAd) {
648
+ rewardedAd = ad
649
+ isRewardedLoad = true
650
+ isAdSkip = 0
651
+ if (rewardedAutoShow) {
652
+ isRewardedAutoShow
633
653
  }
634
- }
635
654
 
636
- private val isRewardedAutoShow: Unit
637
- get() {
638
- if (isRewardedLoad && rewardedAd != null) {
639
- isAdSkip = 1
640
- rewardedAd!!.show(mActivity!!) { rewardItem: RewardItem ->
641
- isAdSkip = 2
642
- val rewardAmount = rewardItem.amount
643
- val rewardType = rewardItem.type
655
+
656
+ rewardedAdLoadCallback()
657
+
658
+ cWebView!!.loadUrl(
659
+ "javascript:cordova.fireDocumentEvent('on.rewarded.loaded');"
660
+ )
661
+
662
+ rewardedAd!!.onPaidEventListener =
663
+ OnPaidEventListener { adValue: AdValue ->
664
+ val valueMicros = adValue.valueMicros
665
+ val currencyCode = adValue.currencyCode
666
+ val precision = adValue.precisionType
667
+ val rewardedAdAdUnitId = rewardedAd!!.adUnitId
644
668
  val result = JSONObject()
645
669
  try {
646
- result.put("rewardAmount", rewardAmount)
647
- result.put("rewardType", rewardType)
648
- callbackContext.success(result)
670
+ result.put("micros", valueMicros)
671
+ result.put("currency", currencyCode)
672
+ result.put("precision", precision)
673
+ result.put("adUnitId", rewardedAdAdUnitId)
674
+ cWebView!!.loadUrl(
675
+ "javascript:cordova.fireDocumentEvent('on.rewarded.revenue', ${result});"
676
+ )
649
677
  } catch (e: JSONException) {
650
678
  callbackContext.error(e.message)
651
679
  }
652
- cWebView!!.loadUrl(
653
- "javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward');"
680
+
681
+ }
682
+
683
+
684
+
685
+ if (isResponseInfo) {
686
+ val result = JSONObject()
687
+ val responseInfo = ad.responseInfo
688
+ try {
689
+ result.put("getResponseId", responseInfo.responseId)
690
+ result.put(
691
+ "getAdapterResponses",
692
+ responseInfo.adapterResponses
693
+ )
694
+ result.put(
695
+ "getResponseExtras",
696
+ responseInfo.responseExtras
654
697
  )
698
+ result.put(
699
+ "getMediationAdapterClassName",
700
+ responseInfo.mediationAdapterClassName
701
+ )
702
+ result.put("getBundleExtra", mBundleExtra.toString())
703
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAd.responseInfo', ${result})")
704
+ } catch (e: JSONException) {
705
+ callbackContext.error(e.message)
655
706
  }
656
707
  }
708
+
709
+
657
710
  }
658
- })
659
- } catch (e: Exception) {
660
- callbackContext.error(e.toString())
711
+
712
+ private val isRewardedAutoShow: Unit
713
+ get() {
714
+ if (mActivity != null){
715
+ mActivity!!.runOnUiThread {
716
+ if (isRewardedLoad && rewardedAd != null) {
717
+ isAdSkip = 1
718
+ rewardedAd!!.show(mActivity!!) { rewardItem: RewardItem ->
719
+ isAdSkip = 2
720
+ val rewardAmount = rewardItem.amount
721
+ val rewardType = rewardItem.type
722
+ val result = JSONObject()
723
+ try {
724
+ result.put("rewardType", rewardType)
725
+ result.put("rewardAmount", rewardAmount)
726
+ cWebView!!.loadUrl(
727
+ "javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});"
728
+ )
729
+ } catch (e: JSONException) {
730
+ callbackContext.error(e.message)
731
+ }
732
+
733
+ }
734
+ }
735
+ }
736
+ }
737
+ }
738
+ })
739
+ } catch (e: Exception) {
740
+ callbackContext.error(e.toString())
741
+ }
661
742
  }
662
743
  }
663
744
  return true
664
745
  } else if (action == "showRewardedAd") {
665
- mActivity!!.runOnUiThread {
666
- if (isRewardedLoad && rewardedAd != null) {
746
+ if(mActivity != null && isRewardedLoad && rewardedAd != null) {
747
+ mActivity!!.runOnUiThread {
667
748
  isAdSkip = 1
668
749
  rewardedAd!!.show(mActivity!!) { rewardItem: RewardItem ->
669
750
  isAdSkip = 2
@@ -671,354 +752,394 @@ class emiAdmobPlugin : CordovaPlugin() {
671
752
  val rewardType = rewardItem.type
672
753
  val result = JSONObject()
673
754
  try {
674
- result.put("rewardAmount", rewardAmount)
675
755
  result.put("rewardType", rewardType)
676
- callbackContext.success(result)
756
+ result.put("rewardAmount", rewardAmount)
757
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});")
677
758
  } catch (e: JSONException) {
678
759
  callbackContext.error(e.message)
679
760
  }
680
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward');")
761
+
681
762
  }
682
- rewardedAdLoadCallback(callbackContext)
683
- } else {
684
- callbackContext.error("The rewarded ad wasn't ready yet")
763
+ rewardedAdLoadCallback()
764
+
685
765
  }
766
+
767
+ } else {
768
+ callbackContext.error("The rewarded ad wasn't ready yet")
686
769
  }
687
770
  return true
688
771
  } else if (action == "loadRewardedInterstitialAd") {
689
772
  val options = args.getJSONObject(0)
690
- mActivity!!.runOnUiThread {
691
- val adUnitId = options.optString("adUnitId")
692
- val autoShow = options.optBoolean("autoShow")
693
- try {
694
- this.rIntAutoShow = autoShow
695
- RewardedInterstitialAd.load(
696
- mActivity!!, adUnitId, buildAdRequest(),
697
- object : RewardedInterstitialAdLoadCallback() {
698
- override fun onAdLoaded(ad: RewardedInterstitialAd) {
699
- rewardedInterstitialAd = ad
700
- isRewardedInterstitialLoad = true
701
- isAdSkip = 0
702
-
703
- if (rIntAutoShow) {
704
- isRIntAutoShow
705
- }
706
- rewardedInterstitialAdLoadCallback(callbackContext)
707
- responseAdLoad()
708
- revenueAd()
773
+ if(mActivity != null) {
774
+ mActivity!!.runOnUiThread {
775
+ val adUnitId = options.optString("adUnitId")
776
+ val autoShow = options.optBoolean("autoShow")
777
+ try {
778
+ this.rIntAutoShow = autoShow
779
+ RewardedInterstitialAd.load(
780
+ mActivity!!, adUnitId, buildAdRequest(),
781
+ object : RewardedInterstitialAdLoadCallback() {
782
+ override fun onAdLoaded(ad: RewardedInterstitialAd) {
783
+ rewardedInterstitialAd = ad
784
+ isRewardedInterstitialLoad = true
785
+ isAdSkip = 0
786
+
787
+ cWebView!!.loadUrl(
788
+ "javascript:cordova.fireDocumentEvent('on.rewardedInt.loaded');"
789
+ )
790
+
791
+ if (rIntAutoShow) {
792
+ isRIntAutoShow
793
+ }
709
794
 
795
+ rewardedInterstitialAdLoadCallback()
796
+
797
+ rewardedInterstitialAd!!.onPaidEventListener =
798
+ OnPaidEventListener { adValue: AdValue ->
799
+ val valueMicros = adValue.valueMicros
800
+ val currencyCode = adValue.currencyCode
801
+ val precision = adValue.precisionType
802
+ val rewardedIntAdUnitId =
803
+ rewardedInterstitialAd!!.adUnitId
804
+ val result = JSONObject()
805
+ try {
806
+ result.put("micros", valueMicros)
807
+ result.put("currency", currencyCode)
808
+ result.put("precision", precision)
809
+ result.put("adUnitId", rewardedIntAdUnitId)
810
+ cWebView!!.loadUrl(
811
+ "javascript:cordova.fireDocumentEvent('on.rewardedInt.revenue', ${result});"
812
+ )
813
+ } catch (e: JSONException) {
814
+ callbackContext.error(e.message)
815
+ }
816
+
817
+ }
710
818
 
711
- cWebView!!.loadUrl(
712
- "javascript:cordova.fireDocumentEvent('on.rewardedInt.loaded');"
713
- )
714
- }
715
819
 
716
- private fun revenueAd() {
717
- rewardedInterstitialAd!!.onPaidEventListener =
718
- OnPaidEventListener { adValue: AdValue ->
719
- val valueMicros = adValue.valueMicros
720
- val currencyCode = adValue.currencyCode
721
- val precision = adValue.precisionType
722
- val rewardedIntAdUnitId = rewardedInterstitialAd!!.adUnitId
820
+ if (isResponseInfo) {
723
821
  val result = JSONObject()
822
+ val responseInfo = rewardedInterstitialAd!!.responseInfo
724
823
  try {
725
- result.put("micros", valueMicros)
726
- result.put("currency", currencyCode)
727
- result.put("precision", precision)
728
- result.put("adUnitId", rewardedIntAdUnitId)
729
- callbackContext.success(result)
824
+ result.put("getResponseId", responseInfo.responseId)
825
+ result.put(
826
+ "getAdapterResponses",
827
+ responseInfo.adapterResponses
828
+ )
829
+ result.put(
830
+ "getResponseExtras",
831
+ responseInfo.responseExtras
832
+ )
833
+ result.put(
834
+ "getMediationAdapterClassName",
835
+ responseInfo.mediationAdapterClassName
836
+ )
837
+ result.put("getBundleExtra", mBundleExtra.toString())
838
+ cWebView!!.loadUrl(
839
+ "javascript:cordova.fireDocumentEvent('on.rewardedIntAd.responseInfo', ${result});"
840
+ )
730
841
  } catch (e: JSONException) {
731
842
  callbackContext.error(e.message)
732
843
  }
733
- cWebView!!.loadUrl(
734
- "javascript:cordova.fireDocumentEvent('on.rewardedInt.revenue');"
735
- )
736
844
  }
737
- }
738
845
 
739
- private fun responseAdLoad() {
740
- if (isResponseInfo) {
741
- val result = JSONObject()
742
- val responseInfo = rewardedInterstitialAd!!.responseInfo
743
- try {
744
- result.put("getResponseId", responseInfo.responseId)
745
- result.put(
746
- "getAdapterResponses",
747
- responseInfo.adapterResponses
748
- )
749
- result.put("getResponseExtras", responseInfo.responseExtras)
750
- result.put(
751
- "getMediationAdapterClassName",
752
- responseInfo.mediationAdapterClassName
753
- )
754
- result.put("getBundleExtra", mBundleExtra.toString())
755
- callbackContext.success(result)
756
- } catch (e: JSONException) {
757
- callbackContext.error(e.message)
758
- }
846
+
847
+
848
+
759
849
  }
760
- }
761
850
 
762
- private val isRIntAutoShow: Unit
763
- get() {
764
- if (isRewardedInterstitialLoad && rewardedInterstitialAd != null) {
765
- isAdSkip = 1
766
- rewardedInterstitialAd!!.show(mActivity!!) { rewardItem: RewardItem ->
767
- isAdSkip = 2
768
- val rewardAmount = rewardItem.amount
769
- val rewardType = rewardItem.type
770
- val result = JSONObject()
771
- try {
772
- result.put("rewardAmount", rewardAmount)
773
- result.put("rewardType", rewardType)
774
- callbackContext.success(result)
775
- } catch (e: JSONException) {
776
- callbackContext.error(e.message)
851
+
852
+
853
+ private val isRIntAutoShow: Unit
854
+ get() {
855
+ if (mActivity !== null) {
856
+ mActivity!!.runOnUiThread {
857
+ if (isRewardedInterstitialLoad && rewardedInterstitialAd != null) {
858
+ isAdSkip = 1
859
+ rewardedInterstitialAd!!.show(mActivity!!) { rewardItem: RewardItem ->
860
+ isAdSkip = 2
861
+ val rewardAmount = rewardItem.amount
862
+ val rewardType = rewardItem.type
863
+ val result = JSONObject()
864
+ try {
865
+ result.put("rewardType", rewardType)
866
+ result.put("rewardAmount", rewardAmount)
867
+ cWebView!!.loadUrl(
868
+ "javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});"
869
+ )
870
+ } catch (e: JSONException) {
871
+ callbackContext.error(e.message)
872
+ }
873
+
874
+ }
875
+ }
777
876
  }
778
- cWebView!!.loadUrl(
779
- "javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward');"
780
- )
781
877
  }
782
878
  }
783
- }
784
879
 
785
- override fun onAdFailedToLoad(loadAdError: LoadAdError) {
786
- rewardedInterstitialAd = null
787
- isRewardedInterstitialLoad = false
788
- cWebView!!.loadUrl(
789
- "javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.load');"
790
- )
791
- callbackContext.error(loadAdError.toString())
792
- }
793
- })
794
- } catch (e: Exception) {
795
- callbackContext.error(e.toString())
880
+ override fun onAdFailedToLoad(loadAdError: LoadAdError) {
881
+ rewardedInterstitialAd = null
882
+ isRewardedInterstitialLoad = false
883
+ val errorData = JSONObject().apply {
884
+ put("responseInfo", loadAdError.responseInfo)
885
+ put("code", loadAdError.code)
886
+ put("message", loadAdError.message)
887
+ put("domain", loadAdError.domain)
888
+ put("cause", loadAdError.cause?.toString() ?: "null")
889
+ }
890
+ cWebView!!.loadUrl(
891
+ "javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.load', ${errorData});"
892
+ )
893
+
894
+ }
895
+ })
896
+ } catch (e: Exception) {
897
+ callbackContext.error(e.toString())
898
+ }
796
899
  }
797
900
  }
798
901
  return true
799
902
  } else if (action == "showRewardedInterstitialAd") {
800
- mActivity!!.runOnUiThread {
801
- if (isRewardedInterstitialLoad && rewardedInterstitialAd != null) {
802
- isAdSkip = 1
803
- rewardedInterstitialAd!!.show(mActivity!!) { rewardItem: RewardItem ->
804
- isAdSkip = 2
805
- val rewardAmount = rewardItem.amount
806
- val rewardType = rewardItem.type
807
- val result = JSONObject()
808
- try {
809
- result.put("rewardAmount", rewardAmount)
810
- result.put("rewardType", rewardType)
811
- callbackContext.success(result)
812
- } catch (e: JSONException) {
813
- callbackContext.error(e.message)
903
+ if(mActivity != null) {
904
+ mActivity!!.runOnUiThread {
905
+ if (isRewardedInterstitialLoad && rewardedInterstitialAd != null) {
906
+ isAdSkip = 1
907
+ rewardedInterstitialAd!!.show(mActivity!!) { rewardItem: RewardItem ->
908
+ isAdSkip = 2
909
+ val rewardAmount = rewardItem.amount
910
+ val rewardType = rewardItem.type
911
+ val result = JSONObject()
912
+ try {
913
+ result.put("rewardType", rewardType)
914
+ result.put("rewardAmount", rewardAmount)
915
+ cWebView!!.loadUrl(
916
+ "javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});"
917
+ )
918
+ } catch (e: JSONException) {
919
+ callbackContext.error(e.message)
920
+ }
921
+
814
922
  }
815
- cWebView!!.loadUrl(
816
- "javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward');"
817
- )
923
+ rewardedInterstitialAdLoadCallback()
924
+ } else {
925
+ callbackContext.error("The rewarded ad wasn't ready yet")
818
926
  }
819
-
820
- rewardedInterstitialAdLoadCallback(callbackContext)
821
- } else {
822
- callbackContext.error("The rewarded ad wasn't ready yet")
823
927
  }
824
928
  }
825
929
  return true
826
930
  } else if (action == "showPrivacyOptionsForm") {
827
- mActivity!!.runOnUiThread {
828
- try {
829
- val params: ConsentRequestParameters
830
- if (this.setDebugGeography) {
831
- val debugSettings = deviceId?.let {
832
- mActivity?.let { it1 ->
833
- ConsentDebugSettings.Builder(it1)
834
- .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
835
- .addTestDeviceHashedId(it).build()
931
+ if(mActivity != null) {
932
+ mActivity!!.runOnUiThread {
933
+ try {
934
+ val params: ConsentRequestParameters
935
+ if (this.setDebugGeography) {
936
+ val debugSettings = deviceId?.let {
937
+ mActivity?.let { it1 ->
938
+ ConsentDebugSettings.Builder(it1)
939
+ .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
940
+ .addTestDeviceHashedId(it).build()
941
+ }
836
942
  }
943
+ params = ConsentRequestParameters.Builder()
944
+ .setConsentDebugSettings(debugSettings).build()
945
+ } else {
946
+ params = ConsentRequestParameters.Builder()
947
+ .setTagForUnderAgeOfConsent(this.isSetTagForUnderAgeOfConsent)
948
+ .build()
837
949
  }
838
- params = ConsentRequestParameters.Builder()
839
- .setConsentDebugSettings(debugSettings).build()
840
- } else {
841
- params = ConsentRequestParameters.Builder()
842
- .setTagForUnderAgeOfConsent(this.isSetTagForUnderAgeOfConsent).build()
843
- }
844
- consentInformation = mContext?.let {
845
- UserMessagingPlatform.getConsentInformation(
846
- it
847
- )
848
- }
849
- mActivity?.let {
850
- consentInformation?.requestConsentInfoUpdate(
851
- it,
852
- params,
853
- {
854
- mActivity?.let { it1 ->
855
- UserMessagingPlatform.loadAndShowConsentFormIfRequired(
856
- it1
857
- ) { loadAndShowError: FormError? ->
858
- if (loadAndShowError != null) {
859
- cordova.activity.runOnUiThread {
860
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + loadAndShowError.message + "' });")
950
+ consentInformation = mContext?.let {
951
+ UserMessagingPlatform.getConsentInformation(
952
+ it
953
+ )
954
+ }
955
+ mActivity?.let {
956
+ consentInformation?.requestConsentInfoUpdate(
957
+ it,
958
+ params,
959
+ {
960
+ mActivity?.let { it1 ->
961
+ UserMessagingPlatform.loadAndShowConsentFormIfRequired(
962
+ it1
963
+ ) { loadAndShowError: FormError? ->
964
+ if (loadAndShowError != null) {
965
+ mActivity!!.runOnUiThread {
966
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + loadAndShowError.message + "' });")
967
+ }
861
968
  }
862
- }
863
- if (isPrivacyOptionsRequired == ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED) {
864
- mActivity?.let { it2 ->
865
- UserMessagingPlatform.showPrivacyOptionsForm(
866
- it2
867
- ) { formError: FormError? ->
868
- if (formError != null) {
869
- cordova.activity.runOnUiThread {
870
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show.options', { message: '" + formError.message + "' });")
969
+ if (isPrivacyOptionsRequired == ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED) {
970
+ mActivity?.let { it2 ->
971
+ UserMessagingPlatform.showPrivacyOptionsForm(
972
+ it2
973
+ ) { formError: FormError? ->
974
+ if (formError != null) {
975
+ mActivity!!.runOnUiThread {
976
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show.options', { message: '" + formError.message + "' });")
977
+ }
871
978
  }
872
979
  }
873
980
  }
874
981
  }
875
982
  }
876
983
  }
877
- }
878
- },
879
- { requestConsentError: FormError ->
880
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed', { message: '" + requestConsentError.message + "' });")
881
- })
984
+ },
985
+ { requestConsentError: FormError ->
986
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed', { message: '" + requestConsentError.message + "' });")
987
+ })
988
+ }
989
+ } catch (e: Exception) {
990
+ callbackContext.error(e.toString())
882
991
  }
883
- } catch (e: Exception) {
884
- callbackContext.error(e.toString())
885
992
  }
886
993
  }
887
994
  return true
888
995
  } else if (action == "consentReset") {
889
- mActivity!!.runOnUiThread {
890
- try {
891
- consentInformation!!.reset()
892
- } catch (e: Exception) {
893
- callbackContext.error(e.toString())
996
+ if(mActivity != null) {
997
+ mActivity!!.runOnUiThread {
998
+ try {
999
+ consentInformation!!.reset()
1000
+ } catch (e: Exception) {
1001
+ callbackContext.error(e.toString())
1002
+ }
894
1003
  }
895
1004
  }
896
1005
  return true
897
1006
  } else if (action == "getIabTfc") {
898
- mActivity!!.runOnUiThread {
899
- val gdprApplies = mPreferences!!.getInt("IABTCF_gdprApplies", 0)
900
- val purposeConsents = mPreferences!!.getString("IABTCF_PurposeConsents", "")
901
- val vendorConsents = mPreferences!!.getString("IABTCF_VendorConsents", "")
902
- val consentString = mPreferences!!.getString("IABTCF_TCString", "")
903
- val userInfoJson = JSONObject()
904
- try {
905
- userInfoJson.put("IABTCF_gdprApplies", gdprApplies)
906
- userInfoJson.put("IABTCF_PurposeConsents", purposeConsents)
907
- userInfoJson.put("IABTCF_VendorConsents", vendorConsents)
908
- userInfoJson.put("IABTCF_TCString", consentString)
909
- val editor = mPreferences!!.edit()
910
- editor.putString("IABTCF_TCString", consentString)
911
- editor.putLong(LAST_ACCESS_SUFFIX, System.currentTimeMillis())
912
- editor.apply()
913
- val key = "IABTCF_TCString"
914
- getString(key)
915
- callbackContext.success(userInfoJson)
916
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc');")
917
- } catch (e: Exception) {
918
- callbackContext.error(e.toString())
919
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc.error');")
1007
+ if(mActivity != null) {
1008
+ mActivity!!.runOnUiThread {
1009
+ val gdprApplies = mPreferences!!.getInt("IABTCF_gdprApplies", 0)
1010
+ val purposeConsents = mPreferences!!.getString("IABTCF_PurposeConsents", "")
1011
+ val vendorConsents = mPreferences!!.getString("IABTCF_VendorConsents", "")
1012
+ val consentString = mPreferences!!.getString("IABTCF_TCString", "")
1013
+ val userInfoJson = JSONObject()
1014
+ try {
1015
+ userInfoJson.put("IABTCF_gdprApplies", gdprApplies)
1016
+ userInfoJson.put("IABTCF_PurposeConsents", purposeConsents)
1017
+ userInfoJson.put("IABTCF_VendorConsents", vendorConsents)
1018
+ userInfoJson.put("IABTCF_TCString", consentString)
1019
+ val editor = mPreferences!!.edit()
1020
+ editor.putString("IABTCF_TCString", consentString)
1021
+ editor.putLong(LAST_ACCESS_SUFFIX, System.currentTimeMillis())
1022
+ editor.apply()
1023
+ val key = "IABTCF_TCString"
1024
+ getString(key)
1025
+ callbackContext.success(userInfoJson)
1026
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc');")
1027
+ } catch (e: Exception) {
1028
+ callbackContext.error(e.toString())
1029
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc.error');")
1030
+ }
920
1031
  }
921
1032
  }
922
1033
  return true
923
1034
  } else if (action == "loadBannerAd") {
924
- val options = args.getJSONObject(0)
925
- mActivity!!.runOnUiThread {
926
- val adUnitId = options.optString("adUnitId")
927
- val position = options.optString("position")
928
- val collapsible = options.optString("collapsible")
929
- val size = options.optString("size")
930
- val autoResize = options.optBoolean("autoResize")
931
- val autoShow = options.optBoolean("autoShow")
932
- this.bannerAdUnitId = adUnitId
933
- this.isPosition = position
934
- this.isSize = size
935
- this.bannerAutoShow = autoShow
936
- this.isAutoResize = autoResize
937
- this.collapsiblePos = collapsible
938
-
939
- isCollapsible = collapsible.isNotEmpty()
940
- try {
941
- loadBannerAd(adUnitId, position, size)
942
- } catch (e: Exception) {
943
- callbackContext.error(e.toString())
1035
+ if(mActivity != null) {
1036
+ val options = args.getJSONObject(0)
1037
+ mActivity!!.runOnUiThread {
1038
+ val adUnitId = options.optString("adUnitId")
1039
+ val position = options.optString("position")
1040
+ val collapsible = options.optString("collapsible")
1041
+ val size = options.optString("size")
1042
+ val autoResize = options.optBoolean("autoResize")
1043
+ val autoShow = options.optBoolean("autoShow")
1044
+ this.bannerAdUnitId = adUnitId
1045
+ this.isPosition = position
1046
+ this.isSize = size
1047
+ this.bannerAutoShow = autoShow
1048
+ this.isAutoResize = autoResize
1049
+ this.collapsiblePos = collapsible
1050
+
1051
+ isCollapsible = collapsible.isNotEmpty()
1052
+ try {
1053
+ loadBannerAd(adUnitId, position, size)
1054
+ } catch (e: Exception) {
1055
+ callbackContext.error(e.toString())
1056
+ }
944
1057
  }
945
1058
  }
946
1059
  return true
947
1060
  } else if (action == "showBannerAd") {
948
- mActivity!!.runOnUiThread {
949
- if (isBannerPause == 0) {
950
- isShowBannerAds
951
- } else if (isBannerPause == 1) {
952
- try {
953
- bannerView!!.visibility = View.VISIBLE
954
- bannerView!!.resume()
955
- } catch (e: Exception) {
956
- callbackContext.error(e.toString())
1061
+ if(mActivity != null) {
1062
+ mActivity!!.runOnUiThread {
1063
+ if (isBannerPause == 0) {
1064
+ isShowBannerAds
1065
+ } else if (isBannerPause == 1) {
1066
+ try {
1067
+ bannerView!!.visibility = View.VISIBLE
1068
+ bannerView!!.resume()
1069
+ } catch (e: Exception) {
1070
+ callbackContext.error(e.toString())
1071
+ }
957
1072
  }
958
1073
  }
959
1074
  }
960
1075
  return true
961
1076
  } else if (action == "styleBannerAd") {
962
1077
  val options = args.getJSONObject(0)
963
- mActivity!!.runOnUiThread {
964
- val paddingPx = options.optInt("padding")
965
- val marginsPx = options.optInt("margins")
966
- // final boolean autoResize = options.optBoolean("autoResize");
967
- try {
968
- this.paddingInPx = paddingPx
969
- this.marginsInPx = marginsPx
970
- // this.isAutoResize = autoResize;
971
- } catch (e: Exception) {
972
- callbackContext.error(e.toString())
1078
+ if(mActivity != null) {
1079
+ mActivity!!.runOnUiThread {
1080
+ val paddingPx = options.optInt("padding")
1081
+ val marginsPx = options.optInt("margins")
1082
+ // final boolean autoResize = options.optBoolean("autoResize");
1083
+ try {
1084
+ this.paddingInPx = paddingPx
1085
+ this.marginsInPx = marginsPx
1086
+ // this.isAutoResize = autoResize;
1087
+ } catch (e: Exception) {
1088
+ callbackContext.error(e.toString())
1089
+ }
973
1090
  }
974
1091
  }
975
1092
  return true
976
1093
  } else if (action == "collapsibleBannerAd") {
977
1094
  val options = args.getJSONObject(0)
978
-
979
- mActivity!!.runOnUiThread {
980
- val enableCollapsible = options.optBoolean("enabledBannerCollapsible")
981
- val collapsible = options.optString("collapsiblePosition")
982
- try {
983
- this.isCollapsible = enableCollapsible
984
- this.collapsiblePos = collapsible
985
- } catch (e: Exception) {
986
- callbackContext.error(e.toString())
1095
+ if(mActivity != null) {
1096
+ mActivity!!.runOnUiThread {
1097
+ val enableCollapsible = options.optBoolean("enabledBannerCollapsible")
1098
+ val collapsible = options.optString("collapsiblePosition")
1099
+ try {
1100
+ this.isCollapsible = enableCollapsible
1101
+ this.collapsiblePos = collapsible
1102
+ } catch (e: Exception) {
1103
+ callbackContext.error(e.toString())
1104
+ }
987
1105
  }
988
1106
  }
989
1107
  return true
990
1108
  } else if (action == "hideBannerAd") {
991
- cordova.activity.runOnUiThread {
992
- if (isBannerShow) {
993
- try {
994
- bannerView!!.visibility = View.GONE
995
- bannerView!!.pause()
996
- isBannerLoad = false
997
- isBannerPause = 1
998
- } catch (e: Exception) {
999
- callbackContext.error(e.toString())
1109
+ if(mActivity != null) {
1110
+ mActivity!!.runOnUiThread {
1111
+ if (isBannerShow) {
1112
+ try {
1113
+ bannerView!!.visibility = View.GONE
1114
+ bannerView!!.pause()
1115
+ isBannerLoad = false
1116
+ isBannerPause = 1
1117
+ } catch (e: Exception) {
1118
+ callbackContext.error(e.toString())
1119
+ }
1000
1120
  }
1001
1121
  }
1002
1122
  }
1003
1123
  return true
1004
1124
  } else if (action == "removeBannerAd") {
1005
- mActivity!!.runOnUiThread {
1006
- try {
1007
- if (bannerViewLayout != null && bannerView != null) {
1008
- bannerViewLayout!!.removeView(bannerView)
1009
- bannerView!!.destroy()
1010
- bannerView = null
1011
- bannerViewLayout = null
1012
- isBannerLoad = false
1013
- isBannerShow = false
1014
- isBannerPause = 2
1015
- lock = true
1125
+ if(mActivity != null) {
1126
+ mActivity!!.runOnUiThread {
1127
+ try {
1128
+ if (bannerViewLayout != null && bannerView != null) {
1129
+ bannerViewLayout!!.removeView(bannerView)
1130
+ bannerView!!.destroy()
1131
+ bannerView = null
1132
+ bannerViewLayout = null
1133
+ isBannerLoad = false
1134
+ isBannerShow = false
1135
+ isBannerPause = 2
1136
+ lock = true
1137
+ }
1138
+ } catch (e: Exception) {
1139
+ PUBLIC_CALLBACKS!!.error("Error removing banner: " + e.message)
1016
1140
  }
1017
- } catch (e: Exception) {
1018
- PUBLIC_CALLBACKS!!.error("Error removing banner: " + e.message)
1019
1141
  }
1020
1142
  }
1021
-
1022
1143
  return true
1023
1144
  }
1024
1145
  return false
@@ -1026,26 +1147,28 @@ class emiAdmobPlugin : CordovaPlugin() {
1026
1147
 
1027
1148
 
1028
1149
  private fun handleConsentForm() {
1029
- if (consentInformation!!.isConsentFormAvailable) {
1030
- mContext?.let {
1031
- UserMessagingPlatform.loadConsentForm(it,
1032
- { consentForm: ConsentForm ->
1033
- mActivity?.let { it1 ->
1034
- consentForm.show(
1035
- it1
1036
- ) { formError: FormError? ->
1037
- if (formError != null) {
1038
- cordova.activity.runOnUiThread {
1039
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + formError.message + "' });")
1150
+ if(mActivity != null) {
1151
+ if (consentInformation!!.isConsentFormAvailable) {
1152
+ mContext?.let {
1153
+ UserMessagingPlatform.loadConsentForm(it,
1154
+ { consentForm: ConsentForm ->
1155
+ mActivity?.let { it1 ->
1156
+ consentForm.show(
1157
+ it1
1158
+ ) { formError: FormError? ->
1159
+ if (formError != null) {
1160
+ mActivity!!.runOnUiThread {
1161
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + formError.message + "' });")
1162
+ }
1040
1163
  }
1041
1164
  }
1042
1165
  }
1166
+ },
1167
+ { formError: FormError ->
1168
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.load.from', { message: '" + formError.message + "' });")
1043
1169
  }
1044
- },
1045
- { formError: FormError ->
1046
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.load.from', { message: '" + formError.message + "' });")
1047
- }
1048
- )
1170
+ )
1171
+ }
1049
1172
  }
1050
1173
  }
1051
1174
  }
@@ -1170,12 +1293,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1170
1293
  isBannerLoad = true
1171
1294
  } else {
1172
1295
  val errorMessage = "Error showing banner: bannerView or bannerViewLayout is null."
1173
- // Log.e("isBannerAutoShow", errorMessage)
1296
+ // Log.e("isBannerAutoShow", errorMessage)
1174
1297
  PUBLIC_CALLBACKS!!.error(errorMessage)
1175
1298
  }
1176
1299
  } catch (e: Exception) {
1177
1300
  val errorMessage = "Error showing banner: " + e.message
1178
- // Log.e("isBannerAutoShow", errorMessage, e)
1301
+ // Log.e("isBannerAutoShow", errorMessage, e)
1179
1302
  PUBLIC_CALLBACKS!!.error(errorMessage)
1180
1303
  }
1181
1304
  }
@@ -1209,8 +1332,15 @@ class emiAdmobPlugin : CordovaPlugin() {
1209
1332
  }
1210
1333
 
1211
1334
  override fun onAdFailedToLoad(adError: LoadAdError) {
1212
- mActivity!!.runOnUiThread {
1213
- try {
1335
+
1336
+ val errorData = JSONObject().apply {
1337
+ put("responseInfo", adError.responseInfo)
1338
+ put("code", adError.code)
1339
+ put("message", adError.message)
1340
+ put("domain", adError.domain)
1341
+ put("cause", adError.cause?.toString() ?: "null")
1342
+ }
1343
+
1214
1344
  if (bannerViewLayout != null && bannerView != null) {
1215
1345
  bannerViewLayout!!.removeView(bannerView)
1216
1346
  bannerView!!.destroy()
@@ -1221,13 +1351,9 @@ class emiAdmobPlugin : CordovaPlugin() {
1221
1351
  isBannerPause = 2
1222
1352
  lock = true
1223
1353
  }
1224
- } catch (e: Exception) {
1225
- PUBLIC_CALLBACKS!!.error("Error removing banner: " + e.message)
1226
- }
1227
- }
1228
1354
 
1229
- PUBLIC_CALLBACKS!!.error(adError.toString())
1230
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.failed.load');")
1355
+
1356
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.failed.load', ${errorData});")
1231
1357
  }
1232
1358
 
1233
1359
  override fun onAdImpression() {
@@ -1245,7 +1371,6 @@ class emiAdmobPlugin : CordovaPlugin() {
1245
1371
  }
1246
1372
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.load');")
1247
1373
 
1248
-
1249
1374
  val eventData = String.format(
1250
1375
  "{\"collapsible\": \"%s\"}",
1251
1376
  if (bannerView!!.isCollapsible) "collapsible" else "not collapsible"
@@ -1253,7 +1378,6 @@ class emiAdmobPlugin : CordovaPlugin() {
1253
1378
 
1254
1379
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.is.collapsible', $eventData)")
1255
1380
 
1256
-
1257
1381
  bannerView!!.onPaidEventListener = bannerPaidAdListener
1258
1382
 
1259
1383
  if (isResponseInfo) {
@@ -1268,14 +1392,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1268
1392
  "getMediationAdapterClassName",
1269
1393
  responseInfo.mediationAdapterClassName
1270
1394
  )
1271
-
1272
1395
  if (mBundleExtra != null) {
1273
1396
  result.put("getBundleExtra", mBundleExtra.toString())
1274
1397
  } else {
1275
1398
  result.put("getBundleExtra", JSONObject.NULL)
1276
1399
  }
1277
-
1278
- PUBLIC_CALLBACKS!!.success(result)
1400
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAd.responseInfo', ${result});")
1279
1401
  } catch (e: JSONException) {
1280
1402
  PUBLIC_CALLBACKS!!.error(e.toString())
1281
1403
  }
@@ -1303,8 +1425,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1303
1425
  result.put("adUnitId", adUnitId)
1304
1426
  isBannerLoad = false
1305
1427
  isBannerShow = true
1306
- PUBLIC_CALLBACKS!!.success(result)
1307
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.revenue');")
1428
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.revenue', ${result});")
1308
1429
  } catch (e: JSONException) {
1309
1430
  PUBLIC_CALLBACKS!!.error(e.message)
1310
1431
  }
@@ -1322,7 +1443,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1322
1443
 
1323
1444
  "full_width_adaptive" -> bannerView!!.setAdSize(
1324
1445
  AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
1325
- mContext!!, AdSize.FULL_WIDTH
1446
+ mContext!!, adWidth
1326
1447
  )
1327
1448
  )
1328
1449
 
@@ -1393,7 +1514,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1393
1514
 
1394
1515
 
1395
1516
 
1396
- private fun setUsingAdManagerRequest(isUsingAdManagerRequest: Boolean) {
1517
+ private fun setUsingAdManagerRequest(isUsingAdManagerRequest: Boolean) {
1397
1518
  this.isUsingAdManagerRequest = isUsingAdManagerRequest
1398
1519
  }
1399
1520
 
@@ -1597,7 +1718,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1597
1718
  }
1598
1719
 
1599
1720
 
1600
- private val deviceId: String?
1721
+ private val deviceId: String?
1601
1722
  get() {
1602
1723
  var algorithm = "SHA-256"
1603
1724
  try {
@@ -1667,7 +1788,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1667
1788
 
1668
1789
 
1669
1790
 
1670
- private fun appOpenAdLoadCallback(callbackContext: CallbackContext) {
1791
+ private fun appOpenAdLoadCallback() {
1671
1792
  appOpenAd!!.fullScreenContentCallback = object : FullScreenContentCallback() {
1672
1793
  override fun onAdDismissedFullScreenContent() {
1673
1794
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.dismissed');")
@@ -1676,9 +1797,15 @@ class emiAdmobPlugin : CordovaPlugin() {
1676
1797
  }
1677
1798
 
1678
1799
  override fun onAdFailedToShowFullScreenContent(adError: AdError) {
1679
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.show');")
1680
- callbackContext.error(adError.toString())
1681
1800
  appOpenAd = null
1801
+ isAppOpenAdShow = false
1802
+ val errorData = JSONObject().apply {
1803
+ put("code", adError.code)
1804
+ put("message", adError.message)
1805
+ put("domain", adError.domain)
1806
+ put("cause", adError.cause?.toString() ?: "null")
1807
+ }
1808
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.show', ${errorData});")
1682
1809
  }
1683
1810
 
1684
1811
  override fun onAdShowedFullScreenContent() {
@@ -1688,7 +1815,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1688
1815
  }
1689
1816
 
1690
1817
 
1691
- private fun interstitialAdLoadCallback(callbackContext: CallbackContext) {
1818
+ private fun interstitialAdLoadCallback() {
1692
1819
  mInterstitialAd!!.fullScreenContentCallback = object : FullScreenContentCallback() {
1693
1820
  override fun onAdClicked() {
1694
1821
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.click');")
@@ -1705,8 +1832,13 @@ class emiAdmobPlugin : CordovaPlugin() {
1705
1832
  override fun onAdFailedToShowFullScreenContent(adError: AdError) {
1706
1833
  mInterstitialAd = null
1707
1834
  isInterstitialLoad = false
1708
- callbackContext.error(adError.toString())
1709
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.show');")
1835
+ val errorData = JSONObject().apply {
1836
+ put("code", adError.code)
1837
+ put("message", adError.message)
1838
+ put("domain", adError.domain)
1839
+ put("cause", adError.cause?.toString() ?: "null")
1840
+ }
1841
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.show', ${errorData});")
1710
1842
  }
1711
1843
 
1712
1844
  override fun onAdImpression() {
@@ -1719,7 +1851,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1719
1851
  }
1720
1852
  }
1721
1853
 
1722
- private fun rewardedAdLoadCallback(callbackContext: CallbackContext) {
1854
+ private fun rewardedAdLoadCallback() {
1723
1855
  rewardedAd!!.fullScreenContentCallback = object : FullScreenContentCallback() {
1724
1856
  override fun onAdClicked() {
1725
1857
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.click');")
@@ -1741,8 +1873,13 @@ class emiAdmobPlugin : CordovaPlugin() {
1741
1873
  override fun onAdFailedToShowFullScreenContent(adError: AdError) {
1742
1874
  rewardedAd = null
1743
1875
  isRewardedLoad = false
1744
- callbackContext.error(adError.toString())
1745
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.failed.show');")
1876
+ val errorData = JSONObject().apply {
1877
+ put("code", adError.code)
1878
+ put("message", adError.message)
1879
+ put("domain", adError.domain)
1880
+ put("cause", adError.cause?.toString() ?: "null")
1881
+ }
1882
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.failed.show', ${errorData});")
1746
1883
  }
1747
1884
 
1748
1885
  override fun onAdImpression() {
@@ -1756,7 +1893,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1756
1893
  }
1757
1894
  }
1758
1895
 
1759
- private fun rewardedInterstitialAdLoadCallback(callbackContext: CallbackContext) {
1896
+ private fun rewardedInterstitialAdLoadCallback() {
1760
1897
  rewardedInterstitialAd!!.fullScreenContentCallback = object : FullScreenContentCallback() {
1761
1898
  override fun onAdClicked() {
1762
1899
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.click');")
@@ -1778,8 +1915,13 @@ class emiAdmobPlugin : CordovaPlugin() {
1778
1915
  override fun onAdFailedToShowFullScreenContent(adError: AdError) {
1779
1916
  rewardedInterstitialAd = null
1780
1917
  isRewardedInterstitialLoad = false
1781
- callbackContext.error(adError.toString())
1782
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.show');")
1918
+ val errorData = JSONObject().apply {
1919
+ put("code", adError.code)
1920
+ put("message", adError.message)
1921
+ put("domain", adError.domain)
1922
+ put("cause", adError.cause?.toString() ?: "null")
1923
+ }
1924
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.show', ${errorData});")
1783
1925
  }
1784
1926
 
1785
1927
  override fun onAdImpression() {
@@ -1800,7 +1942,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1800
1942
  MobileAds.putPublisherFirstPartyIdEnabled(pubIdEnabled)
1801
1943
  }
1802
1944
 
1803
- private fun Targeting(
1945
+ private fun targeting(
1804
1946
  childDirectedTreatment: Boolean,
1805
1947
  underAgeOfConsent: Boolean,
1806
1948
  contentRating: String?
@@ -1843,7 +1985,9 @@ class emiAdmobPlugin : CordovaPlugin() {
1843
1985
  if (View::class.java.isAssignableFrom(CordovaWebView::class.java)) {
1844
1986
  return cWebView as View?
1845
1987
  }
1846
- return mActivity!!.window.decorView.findViewById(R.id.content)
1988
+
1989
+ return mActivity!!.window.decorView.findViewById(View.generateViewId())
1990
+ // return mActivity!!.window.decorView.findViewById(R.id.content)
1847
1991
  }
1848
1992
 
1849
1993
  override fun onPause(multitasking: Boolean) {