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 Android native AdProgressInfo #7723

Merged
merged 4 commits into from
Sep 30, 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+4

* Adds internal wrapper for Android native `AdProgressInfo`.

## 0.2.2+3

* Adds internal wrapper for iOS native `IMAFriendlyObstruction`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.

package dev.flutter.packages.interactive_media_ads

import com.google.ads.interactivemedia.v3.api.AdProgressInfo

/**
* ProxyApi implementation for [AdProgressInfo].
*
* <p>This class may handle instantiating native object instances that are attached to a Dart
* instance or handle method calls on the associated native class or an instance of that class.
*/
class AdProgressInfoProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
PigeonApiAdProgressInfo(pigeonRegistrar) {

override fun adBreakDuration(pigeon_instance: AdProgressInfo): Double {
return pigeon_instance.adBreakDuration
}

override fun adPeriodDuration(pigeon_instance: AdProgressInfo): Double {
return pigeon_instance.adPeriodDuration
}

override fun adPosition(pigeon_instance: AdProgressInfo): Long {
return pigeon_instance.adPosition.toLong()
}

override fun currentTime(pigeon_instance: AdProgressInfo): Double {
return pigeon_instance.currentTime
}

override fun duration(pigeon_instance: AdProgressInfo): Double {
return pigeon_instance.duration
}

override fun totalAds(pigeon_instance: AdProgressInfo): Long {
return pigeon_instance.totalAds.toLong()
}
}
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+3"
const val pluginVersion = "0.2.2+4"
}

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 (v22.3.0), do not edit directly.
// Autogenerated from Pigeon (v22.4.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass", "SyntheticAccessor")

Expand Down Expand Up @@ -543,6 +543,12 @@ abstract class InteractiveMediaAdsLibraryPigeonProxyApiRegistrar(
*/
abstract fun getPigeonApiAdsRenderingSettings(): PigeonApiAdsRenderingSettings

/**
* An implementation of [PigeonApiAdProgressInfo] used to add a new Dart instance of
* `AdProgressInfo` to the Dart `InstanceManager`.
*/
abstract fun getPigeonApiAdProgressInfo(): PigeonApiAdProgressInfo

fun setUp() {
InteractiveMediaAdsLibraryPigeonInstanceManagerApi.setUpMessageHandlers(
binaryMessenger, instanceManager)
Expand Down Expand Up @@ -681,6 +687,8 @@ private class InteractiveMediaAdsLibraryPigeonProxyApiBaseCodec(
registrar.getPigeonApiAdEventListener().pigeon_newInstance(value) {}
} else if (value is com.google.ads.interactivemedia.v3.api.AdsRenderingSettings) {
registrar.getPigeonApiAdsRenderingSettings().pigeon_newInstance(value) {}
} else if (value is com.google.ads.interactivemedia.v3.api.AdProgressInfo) {
registrar.getPigeonApiAdProgressInfo().pigeon_newInstance(value) {}
}

when {
Expand Down Expand Up @@ -4620,3 +4628,93 @@ abstract class PigeonApiAdsRenderingSettings(
}
}
}
/**
* Represents the progress within this ad break.
*
* See
* https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/api/reference/com/google/ads/interactivemedia/v3/api/AdProgressInfo.html.
*/
@Suppress("UNCHECKED_CAST")
abstract class PigeonApiAdProgressInfo(
open val pigeonRegistrar: InteractiveMediaAdsLibraryPigeonProxyApiRegistrar
) {
/** Total ad break duration (in seconds). */
abstract fun adBreakDuration(
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdProgressInfo
): Double

/** Total ad period duration (in seconds). */
abstract fun adPeriodDuration(
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdProgressInfo
): Double

/** The position of current ad within the ad break, starting with 1. */
abstract fun adPosition(
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdProgressInfo
): Long

/** Current time within the ad (in seconds). */
abstract fun currentTime(
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdProgressInfo
): Double

/** Duration of current ad (in seconds). */
abstract fun duration(
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdProgressInfo
): Double

/** The total number of ads in this ad break. */
abstract fun totalAds(
pigeon_instance: com.google.ads.interactivemedia.v3.api.AdProgressInfo
): Long

@Suppress("LocalVariableName", "FunctionName")
/** Creates a Dart instance of AdProgressInfo and attaches it to [pigeon_instanceArg]. */
fun pigeon_newInstance(
pigeon_instanceArg: com.google.ads.interactivemedia.v3.api.AdProgressInfo,
callback: (Result<Unit>) -> Unit
) {
if (pigeonRegistrar.ignoreCallsToDart) {
callback(
Result.failure(
FlutterError("ignore-calls-error", "Calls to Dart are being ignored.", "")))
return
}
if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) {
Result.success(Unit)
return
}
val pigeon_identifierArg =
pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg)
val adBreakDurationArg = adBreakDuration(pigeon_instanceArg)
val adPeriodDurationArg = adPeriodDuration(pigeon_instanceArg)
val adPositionArg = adPosition(pigeon_instanceArg)
val currentTimeArg = currentTime(pigeon_instanceArg)
val durationArg = duration(pigeon_instanceArg)
val totalAdsArg = totalAds(pigeon_instanceArg)
val binaryMessenger = pigeonRegistrar.binaryMessenger
val codec = pigeonRegistrar.codec
val channelName = "dev.flutter.pigeon.interactive_media_ads.AdProgressInfo.pigeon_newInstance"
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
channel.send(
listOf(
pigeon_identifierArg,
adBreakDurationArg,
adPeriodDurationArg,
adPositionArg,
currentTimeArg,
durationArg,
totalAdsArg)) {
if (it is List<*>) {
if (it.size > 1) {
callback(
Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
} else {
callback(Result.success(Unit))
}
} else {
callback(Result.failure(createConnectionError(channelName)))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,8 @@ open class ProxyApiRegistrar(binaryMessenger: BinaryMessenger, var context: Cont
override fun getPigeonApiAdsRenderingSettings(): PigeonApiAdsRenderingSettings {
return AdsRenderingSettingsProxyApi(this)
}

override fun getPigeonApiAdProgressInfo(): PigeonApiAdProgressInfo {
return AdProgressInfoProxyApi(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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.

package dev.flutter.packages.interactive_media_ads

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

class AdProgressInfoProxyApiTest {
@Test
fun adBreakDuration() {
val api = TestProxyApiRegistrar().getPigeonApiAdProgressInfo()

val instance = mock<AdProgressInfo>()
val value = 1.0
whenever(instance.adBreakDuration).thenReturn(value)

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

@Test
fun adPeriodDuration() {
val api = TestProxyApiRegistrar().getPigeonApiAdProgressInfo()

val instance = mock<AdProgressInfo>()
val value = 1.0
whenever(instance.adPeriodDuration).thenReturn(value)

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

@Test
fun adPosition() {
val api = TestProxyApiRegistrar().getPigeonApiAdProgressInfo()

val instance = mock<AdProgressInfo>()
val value = 0
whenever(instance.adPosition).thenReturn(value)

assertEquals(value.toLong(), api.adPosition(instance))
}

@Test
fun currentTime() {
val api = TestProxyApiRegistrar().getPigeonApiAdProgressInfo()

val instance = mock<AdProgressInfo>()
val value = 1.0
whenever(instance.currentTime).thenReturn(value)

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

@Test
fun duration() {
val api = TestProxyApiRegistrar().getPigeonApiAdProgressInfo()

val instance = mock<AdProgressInfo>()
val value = 1.0
whenever(instance.duration).thenReturn(value)

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

@Test
fun totalAds() {
val api = TestProxyApiRegistrar().getPigeonApiAdProgressInfo()

val instance = mock<AdProgressInfo>()
val value = 0
whenever(instance.totalAds).thenReturn(value)

assertEquals(value.toLong(), api.totalAds(instance))
}
}
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+3"
static let pluginVersion = "0.2.2+4"

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