@capgo/capacitor-admob 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapgoCapacitorAdmob.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +232 -0
- package/android/build.gradle +68 -0
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/kotlin/admob/plus/capacitor/AdMobPlusPlugin.kt +147 -0
- package/android/src/main/kotlin/admob/plus/capacitor/ExecuteContext.kt +95 -0
- package/android/src/main/kotlin/admob/plus/capacitor/Generated.kt +42 -0
- package/android/src/main/kotlin/admob/plus/capacitor/ads/AdBase.kt +10 -0
- package/android/src/main/kotlin/admob/plus/capacitor/ads/Banner.kt +148 -0
- package/android/src/main/kotlin/admob/plus/capacitor/ads/Interstitial.kt +73 -0
- package/android/src/main/kotlin/admob/plus/capacitor/ads/Rewarded.kt +83 -0
- package/android/src/main/kotlin/admob/plus/capacitor/ads/RewardedInterstitial.kt +83 -0
- package/android/src/main/kotlin/admob/plus/core/Ad.kt +60 -0
- package/android/src/main/kotlin/admob/plus/core/Context.kt +149 -0
- package/android/src/main/kotlin/admob/plus/core/GenericAd.kt +21 -0
- package/android/src/main/kotlin/admob/plus/core/Helper.kt +119 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +311 -0
- package/dist/esm/definitions.d.ts +53 -0
- package/dist/esm/definitions.js +16 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +50 -0
- package/dist/esm/index.js +138 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +16 -0
- package/dist/esm/web.js +40 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +205 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +208 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/AdmobPlusPlugin/AdmobPlus.swift +8 -0
- package/ios/Sources/AdmobPlusPlugin/AdmobPlusPlugin.swift +19 -0
- package/ios/Tests/AdmobPlusPluginTests/AdmobPlusPluginTests.swift +12 -0
- package/package.json +83 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapgoCapacitorAdmob'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapgoCapacitorAdmob",
|
|
6
|
+
platforms: [.iOS(.v14)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapgoCapacitorAdmob",
|
|
10
|
+
targets: ["AdmobPlusPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "AdmobPlusPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/AdmobPlusPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "AdmobPlusPluginTests",
|
|
25
|
+
dependencies: ["AdmobPlusPlugin"],
|
|
26
|
+
path: "ios/Tests/AdmobPlusPluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# @capgo/capacitor-admob
|
|
2
|
+
<a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
|
|
3
|
+
|
|
4
|
+
<div align="center">
|
|
5
|
+
<h2><a href="https://capgo.app/?ref=plugin"> ➡️ Get Instant updates for your App with Capgo</a></h2>
|
|
6
|
+
<h2><a href="https://capgo.app/consulting/?ref=plugin"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
|
|
7
|
+
</div>
|
|
8
|
+
AdMob SDK bridge for Capacitor apps
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @capgo/capacitor-admob
|
|
14
|
+
npx cap sync
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
<docgen-index>
|
|
20
|
+
|
|
21
|
+
* [`start()`](#start)
|
|
22
|
+
* [`configure(...)`](#configure)
|
|
23
|
+
* [`configRequest(...)`](#configrequest)
|
|
24
|
+
* [`adCreate(...)`](#adcreate)
|
|
25
|
+
* [`adIsLoaded(...)`](#adisloaded)
|
|
26
|
+
* [`adLoad(...)`](#adload)
|
|
27
|
+
* [`adShow(...)`](#adshow)
|
|
28
|
+
* [`adHide(...)`](#adhide)
|
|
29
|
+
* [`trackingAuthorizationStatus()`](#trackingauthorizationstatus)
|
|
30
|
+
* [`requestTrackingAuthorization()`](#requesttrackingauthorization)
|
|
31
|
+
* [`addListener(string, ...)`](#addlistenerstring-)
|
|
32
|
+
* [Interfaces](#interfaces)
|
|
33
|
+
* [Type Aliases](#type-aliases)
|
|
34
|
+
* [Enums](#enums)
|
|
35
|
+
|
|
36
|
+
</docgen-index>
|
|
37
|
+
|
|
38
|
+
<docgen-api>
|
|
39
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
40
|
+
|
|
41
|
+
### start()
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
start() => Promise<void>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
--------------------
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### configure(...)
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
configure(config: AdMobConfig) => Promise<void>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
| Param | Type |
|
|
57
|
+
| ------------ | --------------------------------------------------- |
|
|
58
|
+
| **`config`** | <code><a href="#admobconfig">AdMobConfig</a></code> |
|
|
59
|
+
|
|
60
|
+
--------------------
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### configRequest(...)
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
configRequest(requestConfig: RequestConfig) => Promise<void>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Param | Type |
|
|
70
|
+
| ------------------- | ------------------------------------------------------- |
|
|
71
|
+
| **`requestConfig`** | <code><a href="#requestconfig">RequestConfig</a></code> |
|
|
72
|
+
|
|
73
|
+
--------------------
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### adCreate(...)
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
adCreate<O extends MobileAdOptions>(opts: O) => Promise<void>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Param | Type |
|
|
83
|
+
| ---------- | -------------- |
|
|
84
|
+
| **`opts`** | <code>O</code> |
|
|
85
|
+
|
|
86
|
+
--------------------
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
### adIsLoaded(...)
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
adIsLoaded(opts: { id: number; }) => Promise<boolean>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
| Param | Type |
|
|
96
|
+
| ---------- | ---------------------------- |
|
|
97
|
+
| **`opts`** | <code>{ id: number; }</code> |
|
|
98
|
+
|
|
99
|
+
**Returns:** <code>Promise<boolean></code>
|
|
100
|
+
|
|
101
|
+
--------------------
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### adLoad(...)
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
adLoad(opts: { id: number; }) => Promise<void>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
| Param | Type |
|
|
111
|
+
| ---------- | ---------------------------- |
|
|
112
|
+
| **`opts`** | <code>{ id: number; }</code> |
|
|
113
|
+
|
|
114
|
+
--------------------
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
### adShow(...)
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
adShow(opts: { id: number; }) => Promise<void>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
| Param | Type |
|
|
124
|
+
| ---------- | ---------------------------- |
|
|
125
|
+
| **`opts`** | <code>{ id: number; }</code> |
|
|
126
|
+
|
|
127
|
+
--------------------
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
### adHide(...)
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
adHide(opts: { id: number; }) => Promise<void>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
| Param | Type |
|
|
137
|
+
| ---------- | ---------------------------- |
|
|
138
|
+
| **`opts`** | <code>{ id: number; }</code> |
|
|
139
|
+
|
|
140
|
+
--------------------
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### trackingAuthorizationStatus()
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
trackingAuthorizationStatus() => Promise<{ status: TrackingAuthorizationStatus | false; }>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Returns:** <code>Promise<{ status: false | <a href="#trackingauthorizationstatus">TrackingAuthorizationStatus</a>; }></code>
|
|
150
|
+
|
|
151
|
+
--------------------
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
### requestTrackingAuthorization()
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
requestTrackingAuthorization() => Promise<{ status: TrackingAuthorizationStatus | false; }>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Returns:** <code>Promise<{ status: false | <a href="#trackingauthorizationstatus">TrackingAuthorizationStatus</a>; }></code>
|
|
161
|
+
|
|
162
|
+
--------------------
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### addListener(string, ...)
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
addListener(eventName: string, listenerFunc: (event: any) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
| Param | Type |
|
|
172
|
+
| ------------------ | ------------------------------------ |
|
|
173
|
+
| **`eventName`** | <code>string</code> |
|
|
174
|
+
| **`listenerFunc`** | <code>(event: any) => void</code> |
|
|
175
|
+
|
|
176
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
|
177
|
+
|
|
178
|
+
--------------------
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
### Interfaces
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
#### PluginListenerHandle
|
|
185
|
+
|
|
186
|
+
| Prop | Type |
|
|
187
|
+
| ------------ | ----------------------------------------- |
|
|
188
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
### Type Aliases
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
#### AdMobConfig
|
|
195
|
+
|
|
196
|
+
<code>{ appMuted?: boolean; appVolume?: number; }</code>
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
#### RequestConfig
|
|
200
|
+
|
|
201
|
+
<code>{ maxAdContentRating?: <a href="#maxadcontentrating">MaxAdContentRating</a>; sameAppKey?: boolean; tagForChildDirectedTreatment?: boolean | null; tagForUnderAgeOfConsent?: boolean | null; testDeviceIds?: string[]; }</code>
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
#### MobileAdOptions
|
|
205
|
+
|
|
206
|
+
<code>{ adUnitId: string }</code>
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
### Enums
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
#### MaxAdContentRating
|
|
213
|
+
|
|
214
|
+
| Members | Value |
|
|
215
|
+
| ----------------- | ----------------- |
|
|
216
|
+
| **`G`** | <code>'G'</code> |
|
|
217
|
+
| **`MA`** | <code>'MA'</code> |
|
|
218
|
+
| **`PG`** | <code>'PG'</code> |
|
|
219
|
+
| **`T`** | <code>'T'</code> |
|
|
220
|
+
| **`UNSPECIFIED`** | <code>''</code> |
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
#### TrackingAuthorizationStatus
|
|
224
|
+
|
|
225
|
+
| Members | Value |
|
|
226
|
+
| ------------------- | -------------- |
|
|
227
|
+
| **`notDetermined`** | <code>0</code> |
|
|
228
|
+
| **`restricted`** | <code>1</code> |
|
|
229
|
+
| **`denied`** | <code>2</code> |
|
|
230
|
+
| **`authorized`** | <code>3</code> |
|
|
231
|
+
|
|
232
|
+
</docgen-api>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
6
|
+
googlePlayServicesAdsVersion = project.hasProperty('googlePlayServicesAdsVersion') ? rootProject.ext.googlePlayServicesAdsVersion : '23.0.0'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
buildscript {
|
|
10
|
+
repositories {
|
|
11
|
+
google()
|
|
12
|
+
jcenter()
|
|
13
|
+
mavenCentral()
|
|
14
|
+
}
|
|
15
|
+
dependencies {
|
|
16
|
+
classpath 'com.android.tools.build:gradle:8.3.1'
|
|
17
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply plugin: 'com.android.library'
|
|
22
|
+
apply plugin: 'org.jetbrains.kotlin.android'
|
|
23
|
+
|
|
24
|
+
android {
|
|
25
|
+
namespace "admob.plus.capacitor"
|
|
26
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
27
|
+
defaultConfig {
|
|
28
|
+
minSdk project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
29
|
+
targetSdk project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
30
|
+
versionCode 1
|
|
31
|
+
versionName "1.0"
|
|
32
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
33
|
+
}
|
|
34
|
+
buildTypes {
|
|
35
|
+
release {
|
|
36
|
+
minifyEnabled false
|
|
37
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
lintOptions {
|
|
41
|
+
abortOnError false
|
|
42
|
+
}
|
|
43
|
+
compileOptions {
|
|
44
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
45
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
46
|
+
}
|
|
47
|
+
kotlinOptions {
|
|
48
|
+
jvmTarget = '17'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
repositories {
|
|
53
|
+
google()
|
|
54
|
+
jcenter()
|
|
55
|
+
mavenCentral()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
dependencies {
|
|
60
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
61
|
+
implementation project(':capacitor-android')
|
|
62
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
63
|
+
implementation 'androidx.core:core-ktx:1.9.0'
|
|
64
|
+
testImplementation "junit:junit:$junitVersion"
|
|
65
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
66
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
67
|
+
implementation "com.google.android.gms:play-services-ads:$googlePlayServicesAdsVersion"
|
|
68
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
package admob.plus.capacitor
|
|
2
|
+
|
|
3
|
+
import admob.plus.capacitor.ads.Banner
|
|
4
|
+
import admob.plus.capacitor.ads.Interstitial
|
|
5
|
+
import admob.plus.capacitor.ads.Rewarded
|
|
6
|
+
import admob.plus.capacitor.ads.RewardedInterstitial
|
|
7
|
+
import admob.plus.core.GenericAd
|
|
8
|
+
import admob.plus.core.Helper
|
|
9
|
+
import android.app.Activity
|
|
10
|
+
import com.getcapacitor.JSObject
|
|
11
|
+
import com.getcapacitor.Plugin
|
|
12
|
+
import com.getcapacitor.PluginCall
|
|
13
|
+
import com.getcapacitor.PluginMethod
|
|
14
|
+
import com.getcapacitor.annotation.CapacitorPlugin
|
|
15
|
+
import com.google.android.gms.ads.MobileAds
|
|
16
|
+
import com.google.android.gms.ads.initialization.InitializationStatus
|
|
17
|
+
import org.json.JSONException
|
|
18
|
+
import org.json.JSONObject
|
|
19
|
+
|
|
20
|
+
@CapacitorPlugin(name = "AdMobPlus")
|
|
21
|
+
class AdMobPlusPlugin : Plugin(), Helper.Adapter {
|
|
22
|
+
private var helper: Helper? = null
|
|
23
|
+
override fun load() {
|
|
24
|
+
super.load()
|
|
25
|
+
helper = Helper(this)
|
|
26
|
+
ExecuteContext.Companion.plugin = this
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@PluginMethod
|
|
30
|
+
fun trackingAuthorizationStatus(call: PluginCall) {
|
|
31
|
+
try {
|
|
32
|
+
call.resolve(JSObject("{\"status\": false}"))
|
|
33
|
+
} catch (ex: JSONException) {
|
|
34
|
+
call.reject(ex.toString())
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@PluginMethod
|
|
39
|
+
fun requestTrackingAuthorization(call: PluginCall) {
|
|
40
|
+
try {
|
|
41
|
+
call.resolve(JSObject("{\"status\": false}"))
|
|
42
|
+
} catch (ex: JSONException) {
|
|
43
|
+
call.reject(ex.toString())
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@PluginMethod
|
|
48
|
+
fun start(call: PluginCall) {
|
|
49
|
+
MobileAds.initialize(context) { status: InitializationStatus? ->
|
|
50
|
+
helper!!.configForTestLab()
|
|
51
|
+
call.resolve()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@PluginMethod
|
|
56
|
+
fun configure(call: PluginCall) {
|
|
57
|
+
val ctx = ExecuteContext(call)
|
|
58
|
+
ctx.configure(helper!!)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@PluginMethod
|
|
62
|
+
fun configRequest(call: PluginCall) {
|
|
63
|
+
val ctx = ExecuteContext(call)
|
|
64
|
+
MobileAds.setRequestConfiguration(ctx.optRequestConfiguration())
|
|
65
|
+
helper!!.configForTestLab()
|
|
66
|
+
ctx.resolve()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@PluginMethod
|
|
70
|
+
fun adCreate(call: PluginCall) {
|
|
71
|
+
val ctx = ExecuteContext(call)
|
|
72
|
+
getBridge().executeOnMainThread {
|
|
73
|
+
val adClass = ctx.optString("cls")
|
|
74
|
+
if (adClass == null) {
|
|
75
|
+
ctx.reject("ad cls is missing")
|
|
76
|
+
} else {
|
|
77
|
+
when (adClass) {
|
|
78
|
+
"BannerAd" -> Banner(ctx)
|
|
79
|
+
"InterstitialAd" -> Interstitial(ctx)
|
|
80
|
+
"RewardedAd" -> Rewarded(ctx)
|
|
81
|
+
"RewardedInterstitialAd" -> RewardedInterstitial(ctx)
|
|
82
|
+
else -> ctx.reject("ad cls is not supported: $adClass")
|
|
83
|
+
}
|
|
84
|
+
ctx.resolve()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@PluginMethod
|
|
90
|
+
fun adIsLoaded(call: PluginCall) {
|
|
91
|
+
val ctx = ExecuteContext(call)
|
|
92
|
+
getBridge().executeOnMainThread {
|
|
93
|
+
val ad = ctx.optAdOrError() as GenericAd?
|
|
94
|
+
if (ad != null) {
|
|
95
|
+
ctx.resolve(ad.isLoaded)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@PluginMethod
|
|
101
|
+
fun adLoad(call: PluginCall) {
|
|
102
|
+
val ctx = ExecuteContext(call)
|
|
103
|
+
getBridge().executeOnMainThread {
|
|
104
|
+
val ad = ctx.optAdOrError() as GenericAd?
|
|
105
|
+
ad?.load(ctx)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@PluginMethod
|
|
110
|
+
fun adShow(call: PluginCall) {
|
|
111
|
+
val ctx = ExecuteContext(call)
|
|
112
|
+
getBridge().executeOnMainThread {
|
|
113
|
+
val ad = ctx.optAdOrError() as GenericAd?
|
|
114
|
+
if (ad != null) {
|
|
115
|
+
if (ad.isLoaded) {
|
|
116
|
+
ad.show(ctx)
|
|
117
|
+
} else {
|
|
118
|
+
ctx.reject("ad is not loaded")
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@PluginMethod
|
|
125
|
+
fun adHide(call: PluginCall) {
|
|
126
|
+
val ctx = ExecuteContext(call)
|
|
127
|
+
getBridge().executeOnMainThread {
|
|
128
|
+
val ad = ctx.optAdOrError() as GenericAd?
|
|
129
|
+
ad?.hide(ctx)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
fun emit(eventName: String?, data: JSObject?) {
|
|
134
|
+
notifyListeners(eventName, data)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
override val activity: Activity
|
|
138
|
+
get() = getActivity()
|
|
139
|
+
|
|
140
|
+
override fun emit(eventName: String?, data: Map<String?, Any?>?) {
|
|
141
|
+
try {
|
|
142
|
+
emit(eventName, JSObject.fromJSONObject(JSONObject(data)))
|
|
143
|
+
} catch (e: JSONException) {
|
|
144
|
+
e.printStackTrace()
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
package admob.plus.capacitor
|
|
2
|
+
|
|
3
|
+
import admob.plus.capacitor.ads.AdBase
|
|
4
|
+
import admob.plus.core.Context
|
|
5
|
+
import admob.plus.core.Helper.Companion.jsonArray2stringList
|
|
6
|
+
import android.app.Activity
|
|
7
|
+
import com.getcapacitor.JSObject
|
|
8
|
+
import com.getcapacitor.PluginCall
|
|
9
|
+
import org.json.JSONException
|
|
10
|
+
import org.json.JSONObject
|
|
11
|
+
import java.lang.reflect.InvocationTargetException
|
|
12
|
+
|
|
13
|
+
class ExecuteContext internal constructor(private val call: PluginCall) : Context {
|
|
14
|
+
fun <T : AdBase?> optAdOrCreate(type: Class<T>): T? {
|
|
15
|
+
var ad = type.cast(optAd())
|
|
16
|
+
if (ad == null) {
|
|
17
|
+
try {
|
|
18
|
+
ad = type.getDeclaredConstructor(ExecuteContext::class.java).newInstance(this)
|
|
19
|
+
} catch (e: IllegalAccessException) {
|
|
20
|
+
e.printStackTrace()
|
|
21
|
+
this.reject("Fail to create ad")
|
|
22
|
+
} catch (e: InstantiationException) {
|
|
23
|
+
e.printStackTrace()
|
|
24
|
+
this.reject("Fail to create ad")
|
|
25
|
+
} catch (e: InvocationTargetException) {
|
|
26
|
+
e.printStackTrace()
|
|
27
|
+
this.reject("Fail to create ad")
|
|
28
|
+
} catch (e: NoSuchMethodException) {
|
|
29
|
+
e.printStackTrace()
|
|
30
|
+
this.reject("Fail to create ad")
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return ad
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
val activity: Activity
|
|
37
|
+
get() = plugin!!.getActivity()
|
|
38
|
+
|
|
39
|
+
override fun has(name: String): Boolean {
|
|
40
|
+
return call.hasOption(name)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
override fun opt(name: String): Any? {
|
|
44
|
+
return call.data.opt(name)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override fun optBoolean(name: String): Boolean? {
|
|
48
|
+
return call.getBoolean(name)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override fun optDouble(name: String): Double? {
|
|
52
|
+
return call.getDouble(name)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override fun optFloat(name: String): Float? {
|
|
56
|
+
return call.getFloat(name)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override fun optInt(name: String): Int? {
|
|
60
|
+
return call.getInt(name)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override fun optString(name: String): String? {
|
|
64
|
+
return call.getString(name)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
override fun optStringList(name: String): List<String?> {
|
|
68
|
+
return jsonArray2stringList(call.getArray(name))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override fun optObject(name: String): JSONObject? {
|
|
72
|
+
return call.getObject(name, null)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
override fun resolve() {
|
|
76
|
+
call.resolve()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
override fun resolve(data: Boolean) {
|
|
80
|
+
try {
|
|
81
|
+
call.resolve(JSObject("true"))
|
|
82
|
+
} catch (e: JSONException) {
|
|
83
|
+
e.printStackTrace()
|
|
84
|
+
reject()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
override fun reject(msg: String?) {
|
|
89
|
+
call.reject(msg)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
companion object {
|
|
93
|
+
var plugin: AdMobPlusPlugin? = null
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
|
+
package admob.plus.capacitor
|
|
3
|
+
|
|
4
|
+
class Generated {
|
|
5
|
+
object Events {
|
|
6
|
+
const val AD_CLICK = "ad.click"
|
|
7
|
+
const val AD_DISMISS = "ad.dismiss"
|
|
8
|
+
const val AD_IMPRESSION = "ad.impression"
|
|
9
|
+
const val AD_LOAD = "ad.load"
|
|
10
|
+
const val AD_LOAD_FAIL = "ad.loadfail"
|
|
11
|
+
const val AD_REWARD = "ad.reward"
|
|
12
|
+
const val AD_SHOW = "ad.show"
|
|
13
|
+
const val AD_SHOW_FAIL = "ad.showfail"
|
|
14
|
+
const val BANNER_CLICK = "banner.click"
|
|
15
|
+
const val BANNER_CLOSE = "banner.close"
|
|
16
|
+
const val BANNER_IMPRESSION = "banner.impression"
|
|
17
|
+
const val BANNER_LOAD = "banner.load"
|
|
18
|
+
const val BANNER_LOAD_FAIL = "banner.loadfail"
|
|
19
|
+
const val BANNER_OPEN = "banner.open"
|
|
20
|
+
const val BANNER_SIZE_CHANGE = "banner.sizechange"
|
|
21
|
+
const val INTERSTITIAL_DISMISS = "interstitial.dismiss"
|
|
22
|
+
const val INTERSTITIAL_IMPRESSION = "interstitial.impression"
|
|
23
|
+
const val INTERSTITIAL_LOAD = "interstitial.load"
|
|
24
|
+
const val INTERSTITIAL_LOAD_FAIL = "interstitial.loadfail"
|
|
25
|
+
const val INTERSTITIAL_SHOW = "interstitial.show"
|
|
26
|
+
const val INTERSTITIAL_SHOW_FAIL = "interstitial.showfail"
|
|
27
|
+
const val REWARDED_DISMISS = "rewarded.dismiss"
|
|
28
|
+
const val REWARDED_IMPRESSION = "rewarded.impression"
|
|
29
|
+
const val REWARDED_INTERSTITIAL_DISMISS = "rewardedi.dismiss"
|
|
30
|
+
const val REWARDED_INTERSTITIAL_IMPRESSION = "rewardedi.impression"
|
|
31
|
+
const val REWARDED_INTERSTITIAL_LOAD = "rewardedi.load"
|
|
32
|
+
const val REWARDED_INTERSTITIAL_LOAD_FAIL = "rewardedi.loadfail"
|
|
33
|
+
const val REWARDED_INTERSTITIAL_REWARD = "rewardedi.reward"
|
|
34
|
+
const val REWARDED_INTERSTITIAL_SHOW = "rewardedi.show"
|
|
35
|
+
const val REWARDED_INTERSTITIAL_SHOW_FAIL = "rewardedi.showfail"
|
|
36
|
+
const val REWARDED_LOAD = "rewarded.load"
|
|
37
|
+
const val REWARDED_LOAD_FAIL = "rewarded.loadfail"
|
|
38
|
+
const val REWARDED_REWARD = "rewarded.reward"
|
|
39
|
+
const val REWARDED_SHOW = "rewarded.show"
|
|
40
|
+
const val REWARDED_SHOW_FAIL = "rewarded.showfail"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
package admob.plus.capacitor.ads
|
|
2
|
+
|
|
3
|
+
import admob.plus.capacitor.ExecuteContext
|
|
4
|
+
import admob.plus.core.Ad
|
|
5
|
+
import admob.plus.core.Helper
|
|
6
|
+
|
|
7
|
+
open class AdBase(ctx: ExecuteContext?) : Ad(ctx!!) {
|
|
8
|
+
override val adapter: Helper.Adapter
|
|
9
|
+
get() = ExecuteContext.Companion.plugin!!
|
|
10
|
+
}
|