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

[interactive_media_ads] Adds remaining methods for internal wrapper of the Android native BaseManager #7943

Merged
merged 5 commits into from
Nov 7, 2024
Merged
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
4 changes: 4 additions & 0 deletions packages/interactive_media_ads/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.2+15

* Adds remaining methods for internal wrapper of the Android native `BaseManager`.

## 0.2.2+14

* Adds internal wrapper for iOS native `IMACompanionAdSlot` and `IMACompanionDelegate`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AdsRequestProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
*
* This must match the version in pubspec.yaml.
*/
const val pluginVersion = "0.2.2+14"
const val pluginVersion = "0.2.2+15"
}

override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

package dev.flutter.packages.interactive_media_ads

import com.google.ads.interactivemedia.v3.api.Ad
import com.google.ads.interactivemedia.v3.api.AdErrorEvent
import com.google.ads.interactivemedia.v3.api.AdEvent
import com.google.ads.interactivemedia.v3.api.AdProgressInfo
import com.google.ads.interactivemedia.v3.api.AdsRenderingSettings
import com.google.ads.interactivemedia.v3.api.BaseManager

/**
Expand Down Expand Up @@ -34,7 +37,37 @@ class BaseManagerProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
pigeon_instance.destroy()
}

override fun init(pigeon_instance: BaseManager) {
pigeon_instance.init()
override fun init(pigeon_instance: BaseManager, settings: AdsRenderingSettings?) {
if (settings == null) {
pigeon_instance.init()
} else {
pigeon_instance.init(settings)
}
}

override fun focus(pigeon_instance: BaseManager) {
pigeon_instance.focus()
}

override fun getAdProgressInfo(pigeon_instance: BaseManager): AdProgressInfo? {
return pigeon_instance.adProgressInfo
}

override fun getCurrentAd(pigeon_instance: BaseManager): Ad? {
return pigeon_instance.currentAd
}

override fun removeAdErrorListener(
pigeon_instance: BaseManager,
errorListener: AdErrorEvent.AdErrorListener
) {
pigeon_instance.removeAdErrorListener(errorListener)
}

override fun removeAdEventListener(
pigeon_instance: BaseManager,
adEventListener: AdEvent.AdEventListener
) {
pigeon_instance.removeAdEventListener(adEventListener)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1861,8 +1861,36 @@ abstract class PigeonApiBaseManager(
/** Stops the ad and all tracking, then releases all assets that were loaded to play the ad. */
abstract fun destroy(pigeon_instance: com.google.ads.interactivemedia.v3.api.BaseManager)

/** Initializes the ad experience using default rendering settings */
abstract fun init(pigeon_instance: com.google.ads.interactivemedia.v3.api.BaseManager)
/** Initializes the ad experience on the manager. */
abstract fun init(
pigeon_instance: com.google.ads.interactivemedia.v3.api.BaseManager,
settings: com.google.ads.interactivemedia.v3.api.AdsRenderingSettings?
)

/** Generic focus endpoint that puts focus on the skip button if present. */
abstract fun focus(pigeon_instance: com.google.ads.interactivemedia.v3.api.BaseManager)

/** Returns the latest AdProgressInfo for the current playing ad. */
abstract fun getAdProgressInfo(
pigeon_instance: com.google.ads.interactivemedia.v3.api.BaseManager
): com.google.ads.interactivemedia.v3.api.AdProgressInfo?

/** Get currently playing ad. */
abstract fun getCurrentAd(
pigeon_instance: com.google.ads.interactivemedia.v3.api.BaseManager
): com.google.ads.interactivemedia.v3.api.Ad?

/** Removes a listener for error events. */
abstract fun removeAdErrorListener(
pigeon_instance: com.google.ads.interactivemedia.v3.api.BaseManager,
errorListener: com.google.ads.interactivemedia.v3.api.AdErrorEvent.AdErrorListener
)

/** Removes a listener for ad events. */
abstract fun removeAdEventListener(
pigeon_instance: com.google.ads.interactivemedia.v3.api.BaseManager,
adEventListener: com.google.ads.interactivemedia.v3.api.AdEvent.AdEventListener
)

companion object {
@Suppress("LocalVariableName")
Expand Down Expand Up @@ -1949,9 +1977,128 @@ abstract class PigeonApiBaseManager(
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_instanceArg = args[0] as com.google.ads.interactivemedia.v3.api.BaseManager
val settingsArg =
args[1] as com.google.ads.interactivemedia.v3.api.AdsRenderingSettings?
val wrapped: List<Any?> =
try {
api.init(pigeon_instanceArg, settingsArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.interactive_media_ads.BaseManager.focus",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_instanceArg = args[0] as com.google.ads.interactivemedia.v3.api.BaseManager
val wrapped: List<Any?> =
try {
api.focus(pigeon_instanceArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.interactive_media_ads.BaseManager.getAdProgressInfo",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_instanceArg = args[0] as com.google.ads.interactivemedia.v3.api.BaseManager
val wrapped: List<Any?> =
try {
listOf(api.getAdProgressInfo(pigeon_instanceArg))
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.interactive_media_ads.BaseManager.getCurrentAd",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_instanceArg = args[0] as com.google.ads.interactivemedia.v3.api.BaseManager
val wrapped: List<Any?> =
try {
listOf(api.getCurrentAd(pigeon_instanceArg))
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.interactive_media_ads.BaseManager.removeAdErrorListener",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_instanceArg = args[0] as com.google.ads.interactivemedia.v3.api.BaseManager
val errorListenerArg =
args[1] as com.google.ads.interactivemedia.v3.api.AdErrorEvent.AdErrorListener
val wrapped: List<Any?> =
try {
api.removeAdErrorListener(pigeon_instanceArg, errorListenerArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.interactive_media_ads.BaseManager.removeAdEventListener",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_instanceArg = args[0] as com.google.ads.interactivemedia.v3.api.BaseManager
val adEventListenerArg =
args[1] as com.google.ads.interactivemedia.v3.api.AdEvent.AdEventListener
val wrapped: List<Any?> =
try {
api.init(pigeon_instanceArg)
api.removeAdEventListener(pigeon_instanceArg, adEventListenerArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

package dev.flutter.packages.interactive_media_ads

import com.google.ads.interactivemedia.v3.api.Ad
import com.google.ads.interactivemedia.v3.api.AdErrorEvent
import com.google.ads.interactivemedia.v3.api.AdEvent
import com.google.ads.interactivemedia.v3.api.AdProgressInfo
import com.google.ads.interactivemedia.v3.api.AdsRenderingSettings
import com.google.ads.interactivemedia.v3.api.BaseManager
import junit.framework.TestCase.assertEquals
import kotlin.test.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever

class BaseManagerProxyApiTest {
@Test
Expand Down Expand Up @@ -49,8 +54,63 @@ class BaseManagerProxyApiTest {
val api = TestProxyApiRegistrar().getPigeonApiBaseManager()

val instance = mock<BaseManager>()
api.init(instance)
val settings = mock<AdsRenderingSettings>()
api.init(instance, settings)

verify(instance).init()
verify(instance).init(settings)
}

@Test
fun focus() {
val api = TestProxyApiRegistrar().getPigeonApiBaseManager()

val instance = mock<BaseManager>()
api.focus(instance)

verify(instance).focus()
}

@Test
fun getAdProgressInfo() {
val api = TestProxyApiRegistrar().getPigeonApiBaseManager()

val instance = mock<BaseManager>()
val value = mock<AdProgressInfo>()
whenever(instance.adProgressInfo).thenReturn(value)

assertEquals(value, api.getAdProgressInfo(instance))
}

@Test
fun getCurrentAd() {
val api = TestProxyApiRegistrar().getPigeonApiBaseManager()

val instance = mock<BaseManager>()
val value = mock<Ad>()
whenever(instance.currentAd).thenReturn(value)

assertEquals(value, api.getCurrentAd(instance))
}

@Test
fun removeAdErrorListener() {
val api = TestProxyApiRegistrar().getPigeonApiBaseManager()

val instance = mock<BaseManager>()
val errorListener = mock<AdErrorEvent.AdErrorListener>()
api.removeAdErrorListener(instance, errorListener)

verify(instance).removeAdErrorListener(errorListener)
}

@Test
fun removeAdEventListener() {
val api = TestProxyApiRegistrar().getPigeonApiBaseManager()

val instance = mock<BaseManager>()
val adEventListener = mock<AdEvent.AdEventListener>()
api.removeAdEventListener(instance, adEventListener)

verify(instance).removeAdEventListener(adEventListener)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AdsRequestProxyAPIDelegate: PigeonApiDelegateIMAAdsRequest {
/// The current version of the `interactive_media_ads` plugin.
///
/// This must match the version in pubspec.yaml.
static let pluginVersion = "0.2.2+14"
static let pluginVersion = "0.2.2+15"

func pigeonDefaultConstructor(
pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AndroidAdsManager extends PlatformAdsManager {

@override
Future<void> init(AdsManagerInitParams params) {
return _manager.init();
return _manager.init(null);
}

@override
Expand Down
Loading