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 internal wrapper for remaining methods of the Android native AdsManager #7437

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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.1.2+2

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

## 0.1.2+1

* Updates README to clarify supported features and link to issues tracker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ class AdsManagerProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
override fun start(pigeon_instance: AdsManager) {
pigeon_instance.start()
}

override fun getAdCuePoints(pigeon_instance: AdsManager): List<Double> {
return pigeon_instance.adCuePoints.map { it.toDouble() }
}

override fun resume(pigeon_instance: AdsManager) {
pigeon_instance.resume()
}

override fun skip(pigeon_instance: AdsManager) {
pigeon_instance.skip()
}
}
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.1.2+1"
const val pluginVersion = "0.1.2+2"
}

override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v21.2.0), do not edit directly.
// Autogenerated from Pigeon (v21.3.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass", "SyntheticAccessor")

Expand Down Expand Up @@ -258,7 +258,7 @@ class InteractiveMediaAdsLibraryPigeonInstanceManager(
}
}

/** Generated API for managing the Dart and native `PigeonInstanceManager`s. */
/** Generated API for managing the Dart and native `InstanceManager`s. */
private class InteractiveMediaAdsLibraryPigeonInstanceManagerApi(
val binaryMessenger: BinaryMessenger
) {
Expand All @@ -278,7 +278,7 @@ private class InteractiveMediaAdsLibraryPigeonInstanceManagerApi(
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.interactive_media_ads.PigeonInstanceManagerApi.removeStrongReference",
"dev.flutter.pigeon.interactive_media_ads.PigeonInternalInstanceManager.removeStrongReference",
codec)
if (instanceManager != null) {
channel.setMessageHandler { message, reply ->
Expand All @@ -301,7 +301,7 @@ private class InteractiveMediaAdsLibraryPigeonInstanceManagerApi(
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.interactive_media_ads.PigeonInstanceManagerApi.clear",
"dev.flutter.pigeon.interactive_media_ads.PigeonInternalInstanceManager.clear",
codec)
if (instanceManager != null) {
channel.setMessageHandler { _, reply ->
Expand All @@ -323,7 +323,7 @@ private class InteractiveMediaAdsLibraryPigeonInstanceManagerApi(

fun removeStrongReference(identifierArg: Long, callback: (Result<Unit>) -> Unit) {
val channelName =
"dev.flutter.pigeon.interactive_media_ads.PigeonInstanceManagerApi.removeStrongReference"
"dev.flutter.pigeon.interactive_media_ads.PigeonInternalInstanceManager.removeStrongReference"
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
channel.send(listOf(identifierArg)) {
if (it is List<*>) {
Expand Down Expand Up @@ -1488,6 +1488,25 @@ abstract class PigeonApiAdsManager(
/** Starts playing the ads. */
abstract fun start(pigeon_instance: com.google.ads.interactivemedia.v3.api.AdsManager)

/**
* List of content time offsets in seconds at which ad breaks are scheduled.
*
* The list will be empty if no ad breaks are scheduled.
*/
abstract fun getAdCuePoints(
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdsManager
): List<Double>

/** Resumes the current ad. */
abstract fun resume(pigeon_instance: com.google.ads.interactivemedia.v3.api.AdsManager)

/**
* Skips the current ad.
*
* `AdsManager.skip()` only skips ads if IMA does not render the 'Skip ad' button.
*/
abstract fun skip(pigeon_instance: com.google.ads.interactivemedia.v3.api.AdsManager)

companion object {
@Suppress("LocalVariableName")
fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiAdsManager?) {
Expand Down Expand Up @@ -1557,6 +1576,72 @@ abstract class PigeonApiAdsManager(
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.interactive_media_ads.AdsManager.getAdCuePoints",
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.AdsManager
val wrapped: List<Any?> =
try {
listOf(api.getAdCuePoints(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.AdsManager.resume",
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.AdsManager
val wrapped: List<Any?> =
try {
api.resume(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.AdsManager.skip", 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.AdsManager
val wrapped: List<Any?> =
try {
api.skip(pigeon_instanceArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package dev.flutter.packages.interactive_media_ads

import com.google.ads.interactivemedia.v3.api.AdsManager
import kotlin.test.Test
import kotlin.test.assertEquals
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever

class AdsManagerProxyApiTest {
@Test
Expand Down Expand Up @@ -39,4 +41,35 @@ class AdsManagerProxyApiTest {

verify(instance).start()
}

@Test
fun getAdCuePoints() {
val api = TestProxyApiRegistrar().getPigeonApiAdsManager()

val instance = mock<AdsManager>()
val value = listOf(1.0)
whenever(instance.adCuePoints).thenReturn(listOf(1.0f))

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

@Test
fun resume() {
val api = TestProxyApiRegistrar().getPigeonApiAdsManager()

val instance = mock<AdsManager>()
api.resume(instance)

verify(instance).resume()
}

@Test
fun skip() {
val api = TestProxyApiRegistrar().getPigeonApiAdsManager()

val instance = mock<AdsManager>()
api.skip(instance)

verify(instance).skip()
}
}
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.1.2+1"
static let pluginVersion = "0.1.2+2"

func pigeonDefaultConstructor(
pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer,
Expand Down
Loading