Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.8.0 #37

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = 'com.cleveradssolutions.plugin.flutter'
version = '0.7.6'
version = '0.8.0'

buildscript {
ext.kotlin_version = '1.8.22'
Expand All @@ -18,6 +18,11 @@ rootProject.allprojects {
repositories {
google()
mavenCentral()
maven {
name = "CASBetaRepo"
url = "https://repo.repsy.io/mvn/cleveradssolutions/beta"
content { it.includeGroup("com.cleveradssolutions") }
}
maven {
name = "IronSourceAdsRepo"
url = "https://android-sdk.is.com/"
Expand Down Expand Up @@ -97,5 +102,5 @@ android {
}

dependencies {
implementation 'com.cleveradssolutions:cas-sdk:3.9.9'
implementation 'com.cleveradssolutions:cas-sdk:4.0.1-rc2'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.cleveradssolutions.plugin.flutter

import com.cleveradssolutions.plugin.flutter.appopen.AppOpenMethodHandler
import com.cleveradssolutions.plugin.flutter.bannerview.BannerViewFactory
import com.cleveradssolutions.plugin.flutter.bridge.AdSizeMethodHandler
import com.cleveradssolutions.plugin.flutter.bridge.AdsSettingsMethodHandler
Expand All @@ -9,6 +8,9 @@ import com.cleveradssolutions.plugin.flutter.bridge.ConsentFlowMethodHandler
import com.cleveradssolutions.plugin.flutter.bridge.TargetingOptionsMethodHandler
import com.cleveradssolutions.plugin.flutter.bridge.manager.ManagerBuilderMethodHandler
import com.cleveradssolutions.plugin.flutter.bridge.manager.MediationManagerMethodHandler
import com.cleveradssolutions.plugin.flutter.sdk.screen.AppOpenMethodHandler
import com.cleveradssolutions.plugin.flutter.sdk.screen.InterstitialMethodHandler
import com.cleveradssolutions.plugin.flutter.sdk.screen.RewardedMethodHandler
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding
import io.flutter.embedding.engine.plugins.activity.ActivityAware
Expand All @@ -28,12 +30,14 @@ class CASFlutter : FlutterPlugin, ActivityAware {
AdsSettingsMethodHandler(binding)
AppOpenMethodHandler(binding, context)
CASMethodHandler(binding, context)
InterstitialMethodHandler(binding, context)
ManagerBuilderMethodHandler(
binding,
consentFlowMethodHandler,
mediationManagerMethodHandler,
context
)
RewardedMethodHandler(binding, context)
TargetingOptionsMethodHandler(binding)

val bannerViewFactory = BannerViewFactory(binding, mediationManagerMethodHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

private const val CHANNEL_NAME = "cleveradssolutions/app_open"
private const val CHANNEL_NAME = "cleveradssolutions/app_open_old"

class AppOpenMethodHandler(
binding: FlutterPluginBinding,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.cleveradssolutions.plugin.flutter.bridge.base

import io.flutter.plugin.common.MethodChannel

interface IMappedCallback {

fun invokeMethod(
methodName: String,
args: Map<String, Any?>? = null,
callback: MethodChannel.Result? = null
)

fun invokeMethod(
methodName: String,
vararg args: Pair<String, Any?>,
callback: MethodChannel.Result? = null
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ package com.cleveradssolutions.plugin.flutter.bridge.base

import io.flutter.plugin.common.MethodChannel

abstract class MappedCallback(
open class MappedCallback(
private val handler: MappedMethodHandler<*>,
private val id: String
) {
) : IMappedCallback {

fun invokeMethod(
override fun invokeMethod(
methodName: String,
args: Map<String, Any?>? = null,
callback: MethodChannel.Result? = null
args: Map<String, Any?>?,
callback: MethodChannel.Result?
) {
handler.invokeMethod(id, methodName, args, callback)
}

fun invokeMethod(
override fun invokeMethod(
methodName: String,
vararg args: Pair<String, Any?>,
callback: MethodChannel.Result? = null
callback: MethodChannel.Result?
) {
handler.invokeMethod(id, methodName, args.toMap(), callback)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.cleveradssolutions.plugin.flutter.sdk

import com.cleveradssolutions.plugin.flutter.bridge.base.IMappedCallback
import com.cleveradssolutions.plugin.flutter.bridge.base.MappedCallback
import com.cleveradssolutions.plugin.flutter.bridge.base.MappedMethodHandler
import com.cleveradssolutions.plugin.flutter.util.toMap
import com.cleveradssolutions.sdk.AdContent
import com.cleveradssolutions.sdk.OnAdImpressionListener

class OnAdImpressionListenerHandler(
handler: MappedMethodHandler<*>,
id: String
) : OnAdImpressionListener, IMappedCallback by MappedCallback(handler, id) {

override fun onAdImpression(ad: AdContent) {
invokeMethod("onAdImpression", ad.toMap())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.cleveradssolutions.plugin.flutter.sdk.screen

import com.cleveradssolutions.plugin.flutter.CASFlutterContext
import com.cleveradssolutions.plugin.flutter.bridge.base.MappedMethodHandler
import com.cleveradssolutions.plugin.flutter.sdk.OnAdImpressionListenerHandler
import com.cleveradssolutions.plugin.flutter.util.errorActivityIsNull
import com.cleveradssolutions.plugin.flutter.util.getArgAndReturn
import com.cleveradssolutions.plugin.flutter.util.success
import com.cleveradssolutions.sdk.screen.CASAppOpen
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

private const val CHANNEL_NAME = "cleveradssolutions/app_open"

class AppOpenMethodHandler(
binding: FlutterPlugin.FlutterPluginBinding,
private val contextService: CASFlutterContext
) : MappedMethodHandler<CASAppOpen>(binding, CHANNEL_NAME) {

override fun initInstance(id: String): CASAppOpen {
val context = contextService.getContext()
val appOpen = CASAppOpen(context, id)
appOpen.contentCallback = ScreenAdContentCallbackHandler(this, id)
appOpen.onImpressionListener = OnAdImpressionListenerHandler(this, id)
return appOpen
}

override fun onMethodCall(
instance: CASAppOpen,
call: MethodCall,
result: MethodChannel.Result
) {
when (call.method) {
"isAutoloadEnabled" -> isAutoloadEnabled(instance, result)
"setAutoloadEnabled" -> setAutoloadEnabled(instance,call, result)
"isAutoshowEnabled" -> isAutoshowEnabled(instance, result)
"setAutoshowEnabled" -> setAutoshowEnabled(instance, call, result)
"isLoaded" -> isLoaded(instance, result)
"load" -> load(instance, result)
"show" -> show(instance, call, result)
"destroy" -> destroy(instance, result)
else -> super.onMethodCall(instance, call, result)
}
}

private fun isAutoloadEnabled(appOpen: CASAppOpen, result: MethodChannel.Result) {
result.success(appOpen.isAutoloadEnabled)
}

private fun setAutoloadEnabled(appOpen: CASAppOpen, call: MethodCall, result: MethodChannel.Result) {
call.getArgAndReturn<Boolean>("isEnabled", result) {
appOpen.isAutoloadEnabled = it
}

result.success()
}

private fun isAutoshowEnabled(appOpen: CASAppOpen, result: MethodChannel.Result) {
result.success(appOpen.isAutoshowEnabled)
}

private fun setAutoshowEnabled(appOpen: CASAppOpen, call: MethodCall, result: MethodChannel.Result) {
call.getArgAndReturn<Boolean>("isEnabled", result) {
appOpen.isAutoshowEnabled = it
}

result.success()
}

private fun isLoaded(appOpen: CASAppOpen, result: MethodChannel.Result) {
result.success(appOpen.isLoaded)
}

private fun load(appOpen: CASAppOpen, result: MethodChannel.Result) {
appOpen.load(contextService.getContext())

result.success()
}

private fun show(appOpen: CASAppOpen, call: MethodCall, result: MethodChannel.Result) {
val activity = contextService.getActivityOrError(call, result)
?: return result.errorActivityIsNull(call)

appOpen.show(activity)

result.success()
}

private fun destroy(appOpen: CASAppOpen, result: MethodChannel.Result) {
appOpen.destroy()

result.success()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.cleveradssolutions.plugin.flutter.sdk.screen

import com.cleveradssolutions.plugin.flutter.CASFlutterContext
import com.cleveradssolutions.plugin.flutter.bridge.base.MappedMethodHandler
import com.cleveradssolutions.plugin.flutter.sdk.OnAdImpressionListenerHandler
import com.cleveradssolutions.plugin.flutter.util.errorActivityIsNull
import com.cleveradssolutions.plugin.flutter.util.getArgAndReturn
import com.cleveradssolutions.plugin.flutter.util.success
import com.cleveradssolutions.sdk.screen.CASInterstitial
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

private const val CHANNEL_NAME = "cleveradssolutions/interstitial"

class InterstitialMethodHandler(
binding: FlutterPlugin.FlutterPluginBinding,
private val contextService: CASFlutterContext
) : MappedMethodHandler<CASInterstitial>(binding, CHANNEL_NAME) {

override fun initInstance(id: String): CASInterstitial {
val context = contextService.getContext()
val interstitial = CASInterstitial(context, id)
interstitial.contentCallback = ScreenAdContentCallbackHandler(this, id)
interstitial.onImpressionListener = OnAdImpressionListenerHandler(this, id)
return interstitial
}

override fun onMethodCall(
instance: CASInterstitial,
call: MethodCall,
result: MethodChannel.Result
) {
when (call.method) {
"isAutoloadEnabled" -> isAutoloadEnabled(instance, result)
"setAutoloadEnabled" -> setAutoloadEnabled(instance, call, result)
"isAutoshowEnabled" -> isAutoshowEnabled(instance, result)
"setAutoshowEnabled" -> setAutoshowEnabled(instance, call, result)
"isLoaded" -> isLoaded(instance, result)
"load" -> load(instance, result)
"show" -> show(instance, call, result)
"destroy" -> destroy(instance, result)
"getMinInterval" -> getMinInterval(instance, result)
"setMinInterval" -> setMinInterval(instance, call, result)
"restartInterval" -> restartInterval(instance, result)
else -> super.onMethodCall(instance, call, result)
}
}

private fun isAutoloadEnabled(interstitial: CASInterstitial, result: MethodChannel.Result) {
result.success(interstitial.isAutoloadEnabled)
}

private fun setAutoloadEnabled(
interstitial: CASInterstitial,
call: MethodCall,
result: MethodChannel.Result
) {
call.getArgAndReturn<Boolean>("isEnabled", result) {
interstitial.isAutoloadEnabled = it
}

result.success()
}

private fun isAutoshowEnabled(interstitial: CASInterstitial, result: MethodChannel.Result) {
result.success(interstitial.isAutoshowEnabled)
}

private fun setAutoshowEnabled(
interstitial: CASInterstitial,
call: MethodCall,
result: MethodChannel.Result
) {
call.getArgAndReturn<Boolean>("isEnabled", result) {
interstitial.isAutoshowEnabled = it
}

result.success()
}

private fun isLoaded(interstitial: CASInterstitial, result: MethodChannel.Result) {
result.success(interstitial.isLoaded)
}

private fun load(interstitial: CASInterstitial, result: MethodChannel.Result) {
interstitial.load(contextService.getContext())

result.success()
}

private fun show(
interstitial: CASInterstitial,
call: MethodCall,
result: MethodChannel.Result
) {
val activity = contextService.getActivityOrError(call, result)
?: return result.errorActivityIsNull(call)

interstitial.show(activity)

result.success()
}

private fun destroy(interstitial: CASInterstitial, result: MethodChannel.Result) {
interstitial.destroy()

result.success()
}

private fun getMinInterval(interstitial: CASInterstitial, result: MethodChannel.Result) {
result.success(interstitial.minInterval)
}

private fun setMinInterval(
interstitial: CASInterstitial,
call: MethodCall,
result: MethodChannel.Result
) {
call.getArgAndReturn<Int>("interval", result) {
interstitial.minInterval = it
}

result.success()
}

private fun restartInterval(interstitial: CASInterstitial, result: MethodChannel.Result) {
interstitial.restartInterval()

result.success()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.cleveradssolutions.plugin.flutter.sdk.screen

import com.cleveradssolutions.plugin.flutter.bridge.base.IMappedCallback
import com.cleveradssolutions.plugin.flutter.bridge.base.MappedCallback
import com.cleveradssolutions.plugin.flutter.bridge.base.MappedMethodHandler
import com.cleveradssolutions.plugin.flutter.util.toMap
import com.cleveradssolutions.sdk.AdContent
import com.cleveradssolutions.sdk.screen.OnRewardEarnedListener

class OnRewardEarnedListenerHandler(
handler: MappedMethodHandler<*>,
id: String
) : OnRewardEarnedListener, IMappedCallback by MappedCallback(handler, id) {

override fun onUserEarnedReward(ad: AdContent) {
invokeMethod("onUserEarnedReward", ad.toMap())
}

}
Loading