Fixed banners

DreamingCodes committed Jul 25, 2024 at 18:48 UTC 56e715020bc2b2d97e331c48786f4261009a05bf
7 files changed +26 -13
android/src/main/java/AdmobPlugin.kt
+4 -7
@@ -21,7 +21,8 @@ import org.json.JSONObject
21
22 @InvokeArg
23 class InvokeArgs {
24 - var ctx: String? = null
24 + var cls: String? = null
25 + val id: Int? = null
26 var adUnitId: String? = null
27 var appMuted: Boolean? = null
28 var appVolume: Float? = null
@@ -86,13 +87,9 @@ class AdmobPlugin(var activity: Activity) : Plugin(activity) {
87 }
88
89 @Command
89 - fun adCreate(call: Invoke) {
90 - println("adCreate 1 ${call.parseArgs(InvokeArgs::class.java).ctx} ${call.parseArgs(JSObject::class.java).toString()}")
91 -
92 - val ctx = ExecuteContext(call)
90 + fun adCreate(invoke: Invoke) {
91 + val ctx = ExecuteContext(invoke)
92 android.os.Handler(activity.mainLooper).post {
94 - println("adCreate 2 ${call.parseArgs(InvokeArgs::class.java).ctx} ${call.parseArgs(JSObject::class.java).toString()}")
95 -
93 val adClass = ctx.optString("cls")
94 if (adClass == null) {
95 ctx.reject("ad cls is missing")
android/src/main/java/ExecuteContext.kt
+4 -1
@@ -42,7 +42,8 @@ class ExecuteContext internal constructor(private val call: Invoke) : Context {
42
43 private fun getProperty(args: InvokeArgs, name: String): Any? {
44 return when (name) {
45 - "ctx" -> args.ctx
45 + "id" -> args.id
46 + "cls" -> args.cls
47 "adUnitId" -> args.adUnitId
48 "appMuted" -> args.appMuted
49 "appVolume" -> args.appVolume
@@ -61,10 +62,12 @@ class ExecuteContext internal constructor(private val call: Invoke) : Context {
62 }
63
64 override fun has(name: String): Boolean {
65 + println("has: $name, ${getProperty(getData(), name)}")
66 return getProperty(getData(), name) != null
67 }
68
69 override fun opt(name: String): Any? {
70 + println("opt: $name, ${getProperty(getData(), name)}")
71 return getProperty(getData(), name)
72 }
73
android/src/main/java/ads/Banner.kt
+2 -2
@@ -36,7 +36,7 @@ class Banner(ctx: ExecuteContext) : AdBase(ctx), GenericAd {
36 if (adView == null) {
37 adView = AdView(activity)
38 adView!!.adUnitId = adUnitId
39 - // adView!!.adSize = adSize
39 + adView!!.setAdSize(adSize)
40 adView!!.adListener = object : AdListener() {
41 override fun onAdClicked() {
42 emit(Generated.Events.BANNER_CLICK)
@@ -64,7 +64,7 @@ class Banner(ctx: ExecuteContext) : AdBase(ctx), GenericAd {
64 }
65 }
66 adView!!.loadAd(ctx!!.optAdRequest())
67 - ctx.resolve()
67 + ctx?.resolve()
68 }
69
70 override fun show(ctx: Context?) {
android/src/main/java/core/Helper.kt
+1 -1
@@ -84,7 +84,7 @@ class Helper(private val plugin: AdmobPlugin) {
84
85 @JvmStatic
86 fun getParentView(view: View?): ViewGroup? {
87 - return if (view == null) null else view.parent as ViewGroup
87 + return if (view == null) null else view.parent as ViewGroup?
88 }
89
90 @JvmStatic
examples/tauri-app/src-tauri/gen/schemas/desktop-schema.json
+6
@@ -395,6 +395,12 @@
395 "app:deny-version"
396 ]
397 },
398 + {
399 + "type": "string",
400 + "enum": [
401 + "devtools:default"
402 + ]
403 + },
404 {
405 "description": "event:default -> Default permissions for the plugin.",
406 "type": "string",
examples/tauri-app/src-tauri/gen/schemas/linux-schema.json
+6
@@ -395,6 +395,12 @@
395 "app:deny-version"
396 ]
397 },
398 + {
399 + "type": "string",
400 + "enum": [
401 + "devtools:default"
402 + ]
403 + },
404 {
405 "description": "event:default -> Default permissions for the plugin.",
406 "type": "string",
examples/tauri-app/src/App.svelte
+3 -2
@@ -1,6 +1,6 @@
1 <script lang="ts">
2 import Greet from './lib/Greet.svelte'
3 - import {BannerAd} from "tauri-plugin-admob-api";
3 + import {BannerAd, InterstitialAd} from "tauri-plugin-admob-api";
4
5 let response = ''
6
@@ -10,8 +10,9 @@
10
11 async function _ping() {
12 const banner = new BannerAd({
13 - adUnitId: 'ca-app-pub-3940256099942544/6300978111',
13 + adUnitId: 'ca-app-pub-3940256099942544/9214589741',
14 });
15 + await banner.load();
16 await banner.show();
17 }
18 </script>