admanagekit-mcp-server 1.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.
Files changed (74) hide show
  1. package/content/README.md +851 -0
  2. package/content/docs/AD_FREQUENCY_CONTROL.md +450 -0
  3. package/content/docs/AD_LOADING_STRATEGIES.md +369 -0
  4. package/content/docs/API_REFERENCE.md +734 -0
  5. package/content/docs/APP_PURCHASE_GUIDE.md +704 -0
  6. package/content/docs/BANNER_AD_IMPROVEMENTS.md +325 -0
  7. package/content/docs/COMPOSE_INTEGRATION.md +477 -0
  8. package/content/docs/CONFIGURATION_USAGE.md +168 -0
  9. package/content/docs/INTERSTITIAL_BUILDER_GUIDE.md +518 -0
  10. package/content/docs/JAVA_USAGE_GUIDE.md +785 -0
  11. package/content/docs/LOADING_STRATEGY_EXAMPLES.md +463 -0
  12. package/content/docs/NATIVE_AD_MANAGER_ENHANCEMENTS.md +347 -0
  13. package/content/docs/NATIVE_AD_PRELOADING.md +467 -0
  14. package/content/docs/NATIVE_TEMPLATE_VIEW.md +413 -0
  15. package/content/docs/app-open-ads.md +412 -0
  16. package/content/docs/interstitial-ads.md +269 -0
  17. package/content/docs/native-ads-caching.md +182 -0
  18. package/content/docs/release-notes/RELEASE_NOTES_v2.1.0.md +156 -0
  19. package/content/docs/release-notes/RELEASE_NOTES_v2.2.0.md +248 -0
  20. package/content/docs/release-notes/RELEASE_NOTES_v2.3.0.md +280 -0
  21. package/content/docs/release-notes/RELEASE_NOTES_v2.5.0.md +73 -0
  22. package/content/docs/release-notes/RELEASE_NOTES_v2.6.0.md +265 -0
  23. package/content/docs/release-notes/RELEASE_NOTES_v2.7.0.md +168 -0
  24. package/content/docs/release-notes/RELEASE_NOTES_v2.8.0.md +153 -0
  25. package/content/docs/release-notes/RELEASE_NOTES_v2.9.0.md +479 -0
  26. package/content/docs/release-notes/RELEASE_NOTES_v3.0.0.md +343 -0
  27. package/content/docs/release-notes/RELEASE_NOTES_v3.1.0.md +131 -0
  28. package/content/docs/release-notes/RELEASE_NOTES_v3.3.0.md +252 -0
  29. package/content/docs/release-notes/RELEASE_NOTES_v3.3.2.md +215 -0
  30. package/content/docs/release-notes/RELEASE_NOTES_v3.3.3.md +116 -0
  31. package/content/docs/release-notes/RELEASE_NOTES_v3.3.4.md +142 -0
  32. package/content/docs/release-notes/RELEASE_NOTES_v3.3.5.md +94 -0
  33. package/content/docs/rewarded-ads.md +623 -0
  34. package/content/wiki/Ad-Loading-Strategies.md +209 -0
  35. package/content/wiki/App-Open-Ads.md +189 -0
  36. package/content/wiki/Banner-Ads.md +133 -0
  37. package/content/wiki/Billing-Integration.md +69 -0
  38. package/content/wiki/Configuration.md +252 -0
  39. package/content/wiki/Consumable-Products.md +166 -0
  40. package/content/wiki/Home.md +144 -0
  41. package/content/wiki/Interstitial-Ads.md +313 -0
  42. package/content/wiki/Jetpack-Compose.md +270 -0
  43. package/content/wiki/NativeAdManager.md +220 -0
  44. package/content/wiki/Purchase-Categories.md +94 -0
  45. package/content/wiki/Rewarded-Ads.md +420 -0
  46. package/content/wiki/Subscription-Upgrades.md +278 -0
  47. package/content/wiki/Subscriptions.md +368 -0
  48. package/content/wiki/_Footer.md +3 -0
  49. package/content/wiki/_Sidebar.md +18 -0
  50. package/dist/index.d.ts +2 -0
  51. package/dist/index.js +6 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/server.d.ts +1 -0
  54. package/dist/server.js +18 -0
  55. package/dist/server.js.map +1 -0
  56. package/dist/tools/code-generation.d.ts +2 -0
  57. package/dist/tools/code-generation.js +264 -0
  58. package/dist/tools/code-generation.js.map +1 -0
  59. package/dist/tools/documentation.d.ts +2 -0
  60. package/dist/tools/documentation.js +202 -0
  61. package/dist/tools/documentation.js.map +1 -0
  62. package/dist/types.d.ts +18 -0
  63. package/dist/types.js +83 -0
  64. package/dist/types.js.map +1 -0
  65. package/dist/utils/doc-loader.d.ts +17 -0
  66. package/dist/utils/doc-loader.js +245 -0
  67. package/dist/utils/doc-loader.js.map +1 -0
  68. package/dist/utils/search.d.ts +2 -0
  69. package/dist/utils/search.js +62 -0
  70. package/dist/utils/search.js.map +1 -0
  71. package/dist/utils/templates.d.ts +60 -0
  72. package/dist/utils/templates.js +793 -0
  73. package/dist/utils/templates.js.map +1 -0
  74. package/package.json +51 -0
@@ -0,0 +1,793 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateConfig = generateConfig;
4
+ exports.generateAdIntegration = generateAdIntegration;
5
+ exports.generateBillingCode = generateBillingCode;
6
+ exports.generateComposeCode = generateComposeCode;
7
+ const types_js_1 = require("../types.js");
8
+ function adUnitOrDefault(adUnitId, type) {
9
+ return adUnitId || types_js_1.TEST_AD_UNITS[type] || "ca-app-pub-xxx/yyy";
10
+ }
11
+ function generateConfig(options) {
12
+ const lang = options.language || "kotlin";
13
+ if (lang === "kotlin") {
14
+ return generateConfigKotlin(options);
15
+ }
16
+ return generateConfigJava(options);
17
+ }
18
+ function generateConfigKotlin(o) {
19
+ const configLines = [];
20
+ if (o.debug_mode !== undefined)
21
+ configLines.push(` debugMode = ${o.debug_mode}`);
22
+ if (o.test_mode !== undefined)
23
+ configLines.push(` testMode = ${o.test_mode}`);
24
+ if (o.smart_preloading)
25
+ configLines.push(` enableSmartPreloading = true`);
26
+ if (o.auto_retry !== undefined)
27
+ configLines.push(` autoRetryFailedAds = ${o.auto_retry}`);
28
+ if (o.max_retry_attempts !== undefined)
29
+ configLines.push(` maxRetryAttempts = ${o.max_retry_attempts}`);
30
+ if (o.performance_metrics)
31
+ configLines.push(` enablePerformanceMetrics = true`);
32
+ if (o.interstitial_strategy)
33
+ configLines.push(` interstitialLoadingStrategy = AdLoadingStrategy.${o.interstitial_strategy}`);
34
+ if (o.app_open_strategy)
35
+ configLines.push(` appOpenLoadingStrategy = AdLoadingStrategy.${o.app_open_strategy}`);
36
+ if (o.native_strategy)
37
+ configLines.push(` nativeLoadingStrategy = AdLoadingStrategy.${o.native_strategy}`);
38
+ if (o.interstitial_auto_reload !== undefined)
39
+ configLines.push(` interstitialAutoReload = ${o.interstitial_auto_reload}`);
40
+ if (o.app_open_auto_reload !== undefined)
41
+ configLines.push(` appOpenAutoReload = ${o.app_open_auto_reload}`);
42
+ if (o.rewarded_auto_reload !== undefined)
43
+ configLines.push(` rewardedAutoReload = ${o.rewarded_auto_reload}`);
44
+ const appOpenUnit = o.app_open_ad_unit
45
+ ? `"${o.app_open_ad_unit}"`
46
+ : `"${types_js_1.TEST_AD_UNITS.app_open}"`;
47
+ const imports = [
48
+ "import android.app.Application",
49
+ "import com.i2hammad.admanagekit.config.AdManageKitConfig",
50
+ ];
51
+ if (o.interstitial_strategy ||
52
+ o.app_open_strategy ||
53
+ o.native_strategy) {
54
+ imports.push("import com.i2hammad.admanagekit.config.AdLoadingStrategy");
55
+ }
56
+ if (o.billing) {
57
+ imports.push("import com.i2hammad.admanagekit.core.BillingConfig");
58
+ imports.push("import com.i2hammad.admanagekit.billing.BillingPurchaseProvider");
59
+ }
60
+ if (o.app_open_ad_unit !== undefined || true) {
61
+ imports.push("import com.i2hammad.admanagekit.admob.AppOpenManager");
62
+ }
63
+ return `${imports.join("\n")}
64
+
65
+ class MyApp : Application() {
66
+ private lateinit var appOpenManager: AppOpenManager
67
+
68
+ override fun onCreate() {
69
+ super.onCreate()
70
+
71
+ // Configure AdManageKit
72
+ AdManageKitConfig.apply {
73
+ ${configLines.join("\n")}
74
+ }
75
+ ${o.billing
76
+ ? `
77
+ // Set up billing provider
78
+ BillingConfig.setPurchaseProvider(BillingPurchaseProvider())
79
+ `
80
+ : ""}
81
+ // Initialize app open ads
82
+ appOpenManager = AppOpenManager(this, ${appOpenUnit})
83
+ }
84
+ }`;
85
+ }
86
+ function generateConfigJava(o) {
87
+ const configLines = [];
88
+ if (o.debug_mode !== undefined)
89
+ configLines.push(` AdManageKitConfig.INSTANCE.setDebugMode(${o.debug_mode});`);
90
+ if (o.test_mode !== undefined)
91
+ configLines.push(` AdManageKitConfig.INSTANCE.setTestMode(${o.test_mode});`);
92
+ if (o.smart_preloading)
93
+ configLines.push(` AdManageKitConfig.INSTANCE.setEnableSmartPreloading(true);`);
94
+ if (o.auto_retry !== undefined)
95
+ configLines.push(` AdManageKitConfig.INSTANCE.setAutoRetryFailedAds(${o.auto_retry});`);
96
+ if (o.interstitial_strategy)
97
+ configLines.push(` AdManageKitConfig.INSTANCE.setInterstitialLoadingStrategy(AdLoadingStrategy.${o.interstitial_strategy});`);
98
+ if (o.app_open_strategy)
99
+ configLines.push(` AdManageKitConfig.INSTANCE.setAppOpenLoadingStrategy(AdLoadingStrategy.${o.app_open_strategy});`);
100
+ if (o.native_strategy)
101
+ configLines.push(` AdManageKitConfig.INSTANCE.setNativeLoadingStrategy(AdLoadingStrategy.${o.native_strategy});`);
102
+ const appOpenUnit = o.app_open_ad_unit || types_js_1.TEST_AD_UNITS.app_open;
103
+ return `import android.app.Application;
104
+ import com.i2hammad.admanagekit.config.AdManageKitConfig;
105
+ import com.i2hammad.admanagekit.config.AdLoadingStrategy;
106
+ import com.i2hammad.admanagekit.admob.AppOpenManager;
107
+ ${o.billing ? "import com.i2hammad.admanagekit.core.BillingConfig;\nimport com.i2hammad.admanagekit.billing.BillingPurchaseProvider;\n" : ""}
108
+ public class MyApp extends Application {
109
+ private AppOpenManager appOpenManager;
110
+
111
+ @Override
112
+ public void onCreate() {
113
+ super.onCreate();
114
+
115
+ // Configure AdManageKit
116
+ ${configLines.join("\n")}
117
+ ${o.billing ? "\n // Set up billing provider\n BillingConfig.INSTANCE.setPurchaseProvider(new BillingPurchaseProvider());\n" : ""}
118
+ // Initialize app open ads
119
+ appOpenManager = new AppOpenManager(this, "${appOpenUnit}");
120
+ }
121
+ }`;
122
+ }
123
+ function generateAdIntegration(options) {
124
+ const lang = options.language || "kotlin";
125
+ const type = options.ad_type;
126
+ switch (type) {
127
+ case "interstitial":
128
+ return generateInterstitial(options, lang);
129
+ case "banner":
130
+ return generateBanner(options, lang);
131
+ case "native_small":
132
+ case "native_medium":
133
+ case "native_large":
134
+ return generateNativeView(options, lang);
135
+ case "native_template":
136
+ return generateNativeTemplate(options, lang);
137
+ case "app_open":
138
+ return generateAppOpen(options, lang);
139
+ case "rewarded":
140
+ return generateRewarded(options, lang);
141
+ default:
142
+ return `// Unknown ad type: ${type}`;
143
+ }
144
+ }
145
+ function generateInterstitial(o, lang) {
146
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "interstitial");
147
+ const mode = o.display_mode || "builder";
148
+ if (lang === "kotlin") {
149
+ if (mode === "builder") {
150
+ let builder = `// Interstitial Ad using InterstitialAdBuilder
151
+ InterstitialAdBuilder.with(activity)
152
+ .adUnit("${adUnit}")`;
153
+ if (o.loading_strategy)
154
+ builder += `\n .loadingStrategy(AdLoadingStrategy.${o.loading_strategy})`;
155
+ if (o.with_fallbacks)
156
+ builder += `\n .fallback("fallback-ad-unit-id")`;
157
+ if (o.frequency_control?.every_nth_time)
158
+ builder += `\n .everyNthTime(${o.frequency_control.every_nth_time})`;
159
+ if (o.frequency_control?.max_shows)
160
+ builder += `\n .maxShows(${o.frequency_control.max_shows})`;
161
+ if (o.frequency_control?.min_interval_seconds)
162
+ builder += `\n .minIntervalSeconds(${o.frequency_control.min_interval_seconds})`;
163
+ if (o.auto_reload !== undefined)
164
+ builder += `\n .autoReload(${o.auto_reload})`;
165
+ builder += `\n .show { navigateNext() }`;
166
+ return builder;
167
+ }
168
+ if (mode === "force") {
169
+ return `// Load interstitial ad
170
+ AdManager.getInstance().loadInterstitialAd(this, "${adUnit}")
171
+
172
+ // Force show interstitial
173
+ AdManager.getInstance().forceShowInterstitial(this, object : AdManagerCallback() {
174
+ override fun onNextAction() {
175
+ navigateNext()
176
+ }
177
+ ${o.with_callbacks !== false
178
+ ? ` override fun onAdLoaded() {
179
+ Log.d("Ads", "Ad loaded")
180
+ }
181
+ override fun onFailedToLoad(error: AdKitError?) {
182
+ Log.e("Ads", "Failed: \${error?.message}")
183
+ }
184
+ override fun onAdShowed() {
185
+ Log.d("Ads", "Ad shown")
186
+ }`
187
+ : ""}
188
+ })`;
189
+ }
190
+ if (mode === "time_based") {
191
+ return `// Load interstitial ad
192
+ AdManager.getInstance().loadInterstitialAd(this, "${adUnit}")
193
+
194
+ // Show based on time interval (default 15s between ads)
195
+ AdManager.getInstance().showInterstitialAdByTime(this, object : AdManagerCallback() {
196
+ override fun onNextAction() {
197
+ navigateNext()
198
+ }
199
+ })`;
200
+ }
201
+ if (mode === "count_based") {
202
+ return `// Load interstitial ad
203
+ AdManager.getInstance().loadInterstitialAd(this, "${adUnit}")
204
+
205
+ // Show based on count (e.g., every 3rd call)
206
+ AdManager.getInstance().showInterstitialAdByCount(this, object : AdManagerCallback() {
207
+ override fun onNextAction() {
208
+ navigateNext()
209
+ }
210
+ }, maxDisplayCount = 3)`;
211
+ }
212
+ if (mode === "splash_wait") {
213
+ return `// Smart splash screen ad - waits for ad to load or shows cached
214
+ AdManager.getInstance().showOrWaitForAd(
215
+ activity = this,
216
+ callback = object : AdManagerCallback() {
217
+ override fun onNextAction() {
218
+ navigateToMain()
219
+ }
220
+ },
221
+ timeoutMillis = 10_000
222
+ )`;
223
+ }
224
+ }
225
+ // Java
226
+ return `// Load interstitial ad
227
+ AdManager.getInstance().loadInterstitialAd(this, "${adUnit}");
228
+
229
+ // Show interstitial
230
+ AdManager.getInstance().forceShowInterstitial(this, new AdManagerCallback() {
231
+ @Override
232
+ public void onNextAction() {
233
+ navigateNext();
234
+ }
235
+ });`;
236
+ }
237
+ function generateBanner(o, lang) {
238
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "banner");
239
+ const xml = `<!-- XML Layout -->
240
+ <com.i2hammad.admanagekit.admob.BannerAdView
241
+ android:id="@+id/bannerAdView"
242
+ android:layout_width="match_parent"
243
+ android:layout_height="wrap_content" />`;
244
+ if (lang === "kotlin") {
245
+ if (o.collapsible) {
246
+ return `${xml}
247
+
248
+ // Load collapsible banner
249
+ bannerAdView.loadCollapsibleBanner(this, "${adUnit}", true)`;
250
+ }
251
+ let code = `${xml}
252
+
253
+ // Load banner ad
254
+ bannerAdView.loadBanner(this, "${adUnit}")`;
255
+ if (o.with_callbacks !== false) {
256
+ code += `
257
+
258
+ // With callback
259
+ bannerAdView.loadBanner(this, "${adUnit}", object : AdLoadCallback() {
260
+ override fun onAdLoaded() {
261
+ Log.d("Ads", "Banner loaded")
262
+ }
263
+ override fun onFailedToLoad(error: AdKitError?) {
264
+ Log.e("Ads", "Banner failed: \${error?.message}")
265
+ }
266
+ })`;
267
+ }
268
+ return code;
269
+ }
270
+ return `${xml}
271
+
272
+ // Load banner ad (Java)
273
+ bannerAdView.loadBanner(this, "${adUnit}");`;
274
+ }
275
+ function generateNativeView(o, lang) {
276
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "native");
277
+ const size = o.ad_type.replace("native_", "");
278
+ const viewClass = size === "small"
279
+ ? "NativeBannerSmall"
280
+ : size === "medium"
281
+ ? "NativeBannerMedium"
282
+ : "NativeLarge";
283
+ const xml = `<!-- XML Layout -->
284
+ <com.i2hammad.admanagekit.admob.${viewClass}
285
+ android:id="@+id/${viewClass.charAt(0).toLowerCase() + viewClass.slice(1)}"
286
+ android:layout_width="match_parent"
287
+ android:layout_height="wrap_content" />`;
288
+ if (lang === "kotlin") {
289
+ const useCached = o.use_caching ? ", useCachedAd = true" : "";
290
+ return `${xml}
291
+
292
+ // Load native ${size} ad
293
+ ${viewClass.charAt(0).toLowerCase() + viewClass.slice(1)}.loadNativeBannerAd(this, "${adUnit}"${useCached})`;
294
+ }
295
+ return `${xml}
296
+
297
+ // Load native ${size} ad (Java)
298
+ ${viewClass.charAt(0).toLowerCase() + viewClass.slice(1)}.loadNativeBannerAd(this, "${adUnit}");`;
299
+ }
300
+ function generateNativeTemplate(o, lang) {
301
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "native");
302
+ const template = o.template || "MATERIAL3";
303
+ const xml = `<!-- XML Layout -->
304
+ <com.i2hammad.admanagekit.admob.NativeTemplateView
305
+ android:id="@+id/nativeTemplateView"
306
+ android:layout_width="match_parent"
307
+ android:layout_height="wrap_content"
308
+ app:adTemplate="${template.toLowerCase()}" />`;
309
+ if (lang === "kotlin") {
310
+ let code = `${xml}
311
+
312
+ // Load native template ad
313
+ nativeTemplateView.setTemplate(NativeAdTemplate.${template})
314
+ nativeTemplateView.loadNativeAd(activity, "${adUnit}")`;
315
+ if (o.with_callbacks !== false) {
316
+ code += `
317
+
318
+ // With callback and strategy
319
+ nativeTemplateView.loadNativeAd(activity, "${adUnit}", object : AdLoadCallback() {
320
+ override fun onAdLoaded() { /* success */ }
321
+ override fun onFailedToLoad(error: AdKitError?) { /* error */ }
322
+ }${o.loading_strategy ? `, AdLoadingStrategy.${o.loading_strategy}` : ""})`;
323
+ }
324
+ return code;
325
+ }
326
+ return `${xml}
327
+
328
+ // Load native template ad (Java)
329
+ nativeTemplateView.setTemplate(NativeAdTemplate.${template});
330
+ nativeTemplateView.loadNativeAd(activity, "${adUnit}");`;
331
+ }
332
+ function generateAppOpen(o, lang) {
333
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "app_open");
334
+ if (lang === "kotlin") {
335
+ let code = `// In your Application class
336
+ class MyApp : Application() {
337
+ private lateinit var appOpenManager: AppOpenManager
338
+
339
+ override fun onCreate() {
340
+ super.onCreate()
341
+ appOpenManager = AppOpenManager(this, "${adUnit}")`;
342
+ if (o.exclude_activities?.length) {
343
+ for (const activity of o.exclude_activities) {
344
+ code += `\n appOpenManager.disableAppOpenWithActivity(${activity}::class.java)`;
345
+ }
346
+ }
347
+ code += `
348
+ }
349
+ }`;
350
+ code += `
351
+
352
+ // Force show app open ad
353
+ appOpenManager.forceShowAdIfAvailable(activity, object : AdManagerCallback() {
354
+ override fun onNextAction() {
355
+ continueToApp()
356
+ }
357
+ })
358
+
359
+ // Skip next ad (e.g., before external intent)
360
+ appOpenManager.skipNextAd()
361
+
362
+ // Prefetch for return from external intent
363
+ appOpenManager.prefetchNextAd()`;
364
+ return code;
365
+ }
366
+ return `// In your Application class (Java)
367
+ public class MyApp extends Application {
368
+ private AppOpenManager appOpenManager;
369
+
370
+ @Override
371
+ public void onCreate() {
372
+ super.onCreate();
373
+ appOpenManager = new AppOpenManager(this, "${adUnit}");
374
+ }
375
+ }`;
376
+ }
377
+ function generateRewarded(o, lang) {
378
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "rewarded");
379
+ if (lang === "kotlin") {
380
+ let code = `// Initialize once (e.g., in Application.onCreate())
381
+ RewardedAdManager.initialize(context, "${adUnit}")
382
+
383
+ // Show when ready
384
+ if (RewardedAdManager.isAdLoaded()) {
385
+ RewardedAdManager.showAd(activity, object : RewardedAdManager.RewardedAdCallback {
386
+ override fun onRewardEarned(rewardType: String, rewardAmount: Int) {
387
+ grantReward(rewardType, rewardAmount)
388
+ }
389
+ override fun onAdDismissed() {
390
+ continueGameFlow()
391
+ }`;
392
+ if (o.with_callbacks !== false) {
393
+ code += `
394
+ override fun onAdShowed() {
395
+ Log.d("Ads", "Rewarded ad shown")
396
+ }
397
+ override fun onAdFailedToShow(error: AdKitError?) {
398
+ Log.e("Ads", "Failed to show: \${error?.message}")
399
+ }
400
+ override fun onAdClicked() {
401
+ Log.d("Ads", "Ad clicked")
402
+ }`;
403
+ }
404
+ code += `
405
+ }`;
406
+ if (o.auto_reload !== undefined) {
407
+ code += `, autoReload = ${o.auto_reload}`;
408
+ }
409
+ code += `)
410
+ }
411
+
412
+ // Preload during natural pauses
413
+ RewardedAdManager.preload(context)
414
+
415
+ // Load with timeout (for splash screens)
416
+ RewardedAdManager.loadRewardedAdWithTimeout(context, 5000, object : RewardedAdManager.OnRewardedAdLoadCallback {
417
+ override fun onAdLoaded() { /* ready */ }
418
+ override fun onAdFailedToLoad(error: AdKitLoadError?) { /* failed */ }
419
+ })`;
420
+ return code;
421
+ }
422
+ return `// Initialize once (Java)
423
+ RewardedAdManager.INSTANCE.initialize(context, "${adUnit}");
424
+
425
+ // Show when ready
426
+ if (RewardedAdManager.INSTANCE.isAdLoaded()) {
427
+ RewardedAdManager.INSTANCE.showAd(activity, new RewardedAdManager.RewardedAdCallback() {
428
+ @Override
429
+ public void onRewardEarned(@NonNull String rewardType, int rewardAmount) {
430
+ grantReward(rewardType, rewardAmount);
431
+ }
432
+ @Override
433
+ public void onAdDismissed() {
434
+ continueGameFlow();
435
+ }
436
+ });
437
+ }`;
438
+ }
439
+ function generateBillingCode(options) {
440
+ const lang = options.language || "kotlin";
441
+ const scenario = options.scenario;
442
+ if (lang !== "kotlin") {
443
+ return generateBillingJava(options);
444
+ }
445
+ switch (scenario) {
446
+ case "setup":
447
+ return generateBillingSetup(options);
448
+ case "purchase":
449
+ return generateBillingPurchase();
450
+ case "subscribe":
451
+ return generateBillingSubscribe();
452
+ case "consumable":
453
+ return generateBillingConsumable();
454
+ case "subscription_management":
455
+ return generateBillingSubscriptionMgmt();
456
+ case "expiry_verification":
457
+ return generateBillingExpiryVerification();
458
+ case "complete":
459
+ return [
460
+ generateBillingSetup(options),
461
+ generateBillingPurchase(),
462
+ generateBillingConsumable(),
463
+ generateBillingSubscriptionMgmt(),
464
+ ].join("\n\n// ---\n\n");
465
+ default:
466
+ return `// Unknown billing scenario: ${scenario}`;
467
+ }
468
+ }
469
+ function generateBillingSetup(o) {
470
+ const products = o.products || [
471
+ { product_id: "remove_ads", type: "PURCHASE", category: "REMOVE_ADS" },
472
+ {
473
+ product_id: "premium_monthly",
474
+ type: "SUBSCRIPTION",
475
+ offer_token: "free_trial",
476
+ },
477
+ ];
478
+ const productLines = products
479
+ .map((p) => {
480
+ if (p.type === "SUBSCRIPTION" && p.offer_token) {
481
+ return ` PurchaseItem("${p.product_id}", "${p.offer_token}", TYPE_IAP.SUBSCRIPTION)`;
482
+ }
483
+ if (p.category) {
484
+ return ` PurchaseItem("${p.product_id}", TYPE_IAP.PURCHASE, PurchaseCategory.${p.category})`;
485
+ }
486
+ return ` PurchaseItem("${p.product_id}", TYPE_IAP.${p.type})`;
487
+ })
488
+ .join(",\n");
489
+ return `import com.i2hammad.admanagekit.billing.*
490
+
491
+ // Define products
492
+ val products = listOf(
493
+ ${productLines}
494
+ )
495
+
496
+ // Initialize billing in Application.onCreate()
497
+ AppPurchase.getInstance().initBilling(application, products)
498
+
499
+ // Set up billing provider for ad suppression
500
+ BillingConfig.setPurchaseProvider(BillingPurchaseProvider())`;
501
+ }
502
+ function generateBillingPurchase() {
503
+ return `// Purchase a product
504
+ AppPurchase.getInstance().purchase(activity, "remove_ads")
505
+
506
+ // Check purchase status
507
+ if (AppPurchase.getInstance().isPurchased()) {
508
+ // User has premium access
509
+ }
510
+
511
+ // Listen for purchase events
512
+ AppPurchase.getInstance().setPurchaseHistoryListener(object : PurchaseHistoryListener {
513
+ override fun onNewPurchase(productId: String, purchase: PurchaseResult) {
514
+ Log.d("Billing", "Purchased: $productId")
515
+ }
516
+ override fun onPurchaseConsumed(productId: String, purchase: PurchaseResult) {
517
+ Log.d("Billing", "Consumed: $productId")
518
+ }
519
+ })`;
520
+ }
521
+ function generateBillingSubscribe() {
522
+ return `// Subscribe
523
+ AppPurchase.getInstance().subscribe(activity, "premium_monthly")
524
+
525
+ // Check subscription state
526
+ val state = AppPurchase.getInstance().getSubscriptionState("premium_monthly")
527
+ when (state) {
528
+ SubscriptionState.ACTIVE -> showPremiumUI()
529
+ SubscriptionState.CANCELLED -> showRenewalPrompt()
530
+ SubscriptionState.EXPIRED -> showSubscribeButton()
531
+ }`;
532
+ }
533
+ function generateBillingConsumable() {
534
+ return `// Handle consumable purchases
535
+ AppPurchase.getInstance().setPurchaseHistoryListener(object : PurchaseHistoryListener {
536
+ override fun onNewPurchase(productId: String, purchase: PurchaseResult) {
537
+ if (productId == "coins_100") {
538
+ addCoins(100 * purchase.quantity)
539
+ AppPurchase.getInstance().consumePurchase(productId) // Must manually consume!
540
+ }
541
+ }
542
+ override fun onPurchaseConsumed(productId: String, purchase: PurchaseResult) {
543
+ Log.d("Billing", "Consumed: $productId")
544
+ }
545
+ })`;
546
+ }
547
+ function generateBillingSubscriptionMgmt() {
548
+ return `// Check subscription state
549
+ val state = AppPurchase.getInstance().getSubscriptionState("premium_monthly")
550
+ when (state) {
551
+ SubscriptionState.ACTIVE -> showPremiumUI()
552
+ SubscriptionState.CANCELLED -> showRenewalPrompt() // Still has access until period ends
553
+ SubscriptionState.EXPIRED -> showSubscribeButton()
554
+ }
555
+
556
+ // Upgrade subscription
557
+ AppPurchase.getInstance().upgradeSubscription(activity, "premium_yearly")
558
+
559
+ // Downgrade subscription
560
+ AppPurchase.getInstance().downgradeSubscription(activity, "premium_basic")
561
+
562
+ // Full control with proration mode
563
+ AppPurchase.getInstance().changeSubscription(
564
+ activity,
565
+ "premium_monthly", // from
566
+ "premium_yearly", // to
567
+ SubscriptionReplacementMode.CHARGE_PRORATED_PRICE
568
+ )`;
569
+ }
570
+ function generateBillingExpiryVerification() {
571
+ return `// Set up server-side verification callback
572
+ AppPurchase.getInstance().setSubscriptionVerificationCallback { packageName, subscriptionId, purchaseToken, listener ->
573
+ yourApi.verifySubscription(purchaseToken) { expiryMillis ->
574
+ val details = SubscriptionVerificationCallback.SubscriptionDetails.Builder()
575
+ .setExpiryTimeMillis(expiryMillis)
576
+ .build()
577
+ listener.onVerified(details)
578
+ }
579
+ }
580
+
581
+ // Verify and get expiry info
582
+ AppPurchase.getInstance().verifySubscription("premium_monthly",
583
+ object : AppPurchase.SubscriptionVerificationListener {
584
+ override fun onVerified(subscription: PurchaseResult) {
585
+ val expiryDate = subscription.getExpiryTimeFormatted("dd MMM yyyy")
586
+ val daysLeft = subscription.getRemainingDays()
587
+ val isExpired = subscription.isExpired()
588
+ }
589
+ override fun onVerificationFailed(error: String?) {
590
+ Log.e("Billing", "Verification failed: $error")
591
+ }
592
+ }
593
+ )`;
594
+ }
595
+ function generateBillingJava(o) {
596
+ return `// Billing setup (Java)
597
+ List<PurchaseItem> products = Arrays.asList(
598
+ new PurchaseItem("remove_ads", TYPE_IAP.PURCHASE, PurchaseCategory.REMOVE_ADS),
599
+ new PurchaseItem("premium_monthly", "free_trial", TYPE_IAP.SUBSCRIPTION)
600
+ );
601
+
602
+ AppPurchase.getInstance().initBilling(getApplication(), products);
603
+ BillingConfig.INSTANCE.setPurchaseProvider(new BillingPurchaseProvider());
604
+
605
+ // Purchase
606
+ AppPurchase.getInstance().purchase(activity, "remove_ads");
607
+
608
+ // Check status
609
+ if (AppPurchase.getInstance().isPurchased()) {
610
+ // User has premium access
611
+ }`;
612
+ }
613
+ function generateComposeCode(options) {
614
+ const component = options.component;
615
+ switch (component) {
616
+ case "banner":
617
+ return generateComposeBanner(options);
618
+ case "native_template":
619
+ return generateComposeNativeTemplate(options);
620
+ case "native_small":
621
+ case "native_medium":
622
+ case "native_large":
623
+ return generateComposeNativeSize(options);
624
+ case "interstitial":
625
+ return generateComposeInterstitial(options);
626
+ case "interstitial_state":
627
+ return generateComposeInterstitialState(options);
628
+ case "conditional_ad":
629
+ return generateComposeConditional(options);
630
+ case "cache_warming":
631
+ return generateComposeCacheWarming(options);
632
+ case "complete_screen":
633
+ return generateComposeCompleteScreen(options);
634
+ default:
635
+ return `// Unknown Compose component: ${component}`;
636
+ }
637
+ }
638
+ function generateComposeBanner(o) {
639
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "banner");
640
+ return `@Composable
641
+ fun MyScreen() {
642
+ BannerAdCompose(adUnitId = "${adUnit}")
643
+ }`;
644
+ }
645
+ function generateComposeNativeTemplate(o) {
646
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "native");
647
+ const template = o.template || "MATERIAL3";
648
+ const strategy = o.loading_strategy
649
+ ? `,\n loadingStrategy = AdLoadingStrategy.${o.loading_strategy}`
650
+ : "";
651
+ return `@Composable
652
+ fun MyScreen() {
653
+ NativeTemplateCompose(
654
+ adUnitId = "${adUnit}",
655
+ template = NativeAdTemplate.${template}${strategy}
656
+ )
657
+ }`;
658
+ }
659
+ function generateComposeNativeSize(o) {
660
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "native");
661
+ const size = o.component.replace("native_", "");
662
+ const composable = size === "small"
663
+ ? "NativeBannerSmallCompose"
664
+ : size === "medium"
665
+ ? "NativeBannerMediumCompose"
666
+ : "NativeLargeCompose";
667
+ const strategy = o.loading_strategy
668
+ ? `,\n loadingStrategy = AdLoadingStrategy.${o.loading_strategy}`
669
+ : "";
670
+ return `@Composable
671
+ fun MyScreen() {
672
+ ${composable}(
673
+ adUnitId = "${adUnit}"${strategy}
674
+ )
675
+ }`;
676
+ }
677
+ function generateComposeInterstitial(o) {
678
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "interstitial");
679
+ return `@Composable
680
+ fun MyScreen() {
681
+ val showInterstitial = rememberInterstitialAd(
682
+ adUnitId = "${adUnit}",
683
+ preloadAd = true
684
+ )
685
+
686
+ Button(onClick = { showInterstitial() }) {
687
+ Text("Continue")
688
+ }
689
+ }`;
690
+ }
691
+ function generateComposeInterstitialState(o) {
692
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "interstitial");
693
+ const mode = o.show_mode || "FORCE";
694
+ return `@Composable
695
+ fun MyScreen() {
696
+ val interstitialState = rememberInterstitialAdState(
697
+ adUnitId = "${adUnit}",
698
+ preloadAd = true
699
+ )
700
+
701
+ Button(onClick = {
702
+ interstitialState.show(
703
+ showMode = InterstitialShowMode.${mode},
704
+ onNextAction = { navigateNext() }
705
+ )
706
+ }) {
707
+ Text("Continue")
708
+ }
709
+
710
+ // Check ad state
711
+ if (interstitialState.isLoaded) {
712
+ Text("Ad ready")
713
+ }
714
+ }`;
715
+ }
716
+ function generateComposeConditional(o) {
717
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "native");
718
+ return `@Composable
719
+ fun MyScreen() {
720
+ // Only shows ad for non-purchased users
721
+ ConditionalAd {
722
+ NativeTemplateCompose(
723
+ adUnitId = "${adUnit}",
724
+ template = NativeAdTemplate.MATERIAL3
725
+ )
726
+ }
727
+ }`;
728
+ }
729
+ function generateComposeCacheWarming(o) {
730
+ const adUnit = adUnitOrDefault(o.ad_unit_id, "native");
731
+ return `@Composable
732
+ fun MyScreen() {
733
+ // Warm cache on first composition
734
+ CacheWarmingEffect(
735
+ adUnitId = "${adUnit}",
736
+ count = 3
737
+ )
738
+
739
+ // Use cached ads
740
+ NativeTemplateCompose(
741
+ adUnitId = "${adUnit}",
742
+ template = NativeAdTemplate.LIST_ITEM,
743
+ loadingStrategy = AdLoadingStrategy.ONLY_CACHE
744
+ )
745
+ }`;
746
+ }
747
+ function generateComposeCompleteScreen(o) {
748
+ const bannerUnit = adUnitOrDefault(o.ad_unit_id, "banner");
749
+ const nativeUnit = adUnitOrDefault(undefined, "native");
750
+ const interstitialUnit = adUnitOrDefault(undefined, "interstitial");
751
+ return `@Composable
752
+ fun MainScreen() {
753
+ // Cache warming on screen entry
754
+ CacheWarmingEffect(adUnitId = "${nativeUnit}", count = 2)
755
+
756
+ val showInterstitial = rememberInterstitialAd(
757
+ adUnitId = "${interstitialUnit}",
758
+ preloadAd = true
759
+ )
760
+
761
+ Column(modifier = Modifier.fillMaxSize()) {
762
+ // Banner at top
763
+ BannerAdCompose(adUnitId = "${bannerUnit}")
764
+
765
+ // Content
766
+ LazyColumn(modifier = Modifier.weight(1f)) {
767
+ items(contentList) { item ->
768
+ ContentItem(item)
769
+ }
770
+
771
+ // Native ad in feed
772
+ item {
773
+ ConditionalAd {
774
+ NativeTemplateCompose(
775
+ adUnitId = "${nativeUnit}",
776
+ template = NativeAdTemplate.LIST_ITEM,
777
+ loadingStrategy = AdLoadingStrategy.HYBRID
778
+ )
779
+ }
780
+ }
781
+ }
782
+
783
+ // Interstitial trigger
784
+ Button(
785
+ onClick = { showInterstitial() },
786
+ modifier = Modifier.fillMaxWidth()
787
+ ) {
788
+ Text("Next Level")
789
+ }
790
+ }
791
+ }`;
792
+ }
793
+ //# sourceMappingURL=templates.js.map