Skip to content

Commit

Permalink
Adds internal wrapper for Android native ContentProgressProvider (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bparrishMines authored Sep 11, 2024
1 parent bb53e5d commit 4c18648
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 13 deletions.
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.1

* Adds internal wrapper for Android native `ContentProgressProvider`.

## 0.2.0

* Adds support for pausing and resuming Ad playback. See `AdsManager.pause` and `AdsManager.resume`.
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.0"
const val pluginVersion = "0.2.1"
}

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

package dev.flutter.packages.interactive_media_ads

import com.google.ads.interactivemedia.v3.api.player.ContentProgressProvider
import com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate

/**
* ProxyApi implementation for
* [com.google.ads.interactivemedia.v3.api.player.ContentProgressProvider].
* ProxyApi implementation for [ContentProgressProvider].
*
* <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 ContentProgressProviderProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
PigeonApiContentProgressProvider(pigeonRegistrar)
PigeonApiContentProgressProvider(pigeonRegistrar) {
internal class ContentProgressProviderImpl(val api: ContentProgressProviderProxyApi) :
ContentProgressProvider {
var currentProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY

override fun getContentProgress(): VideoProgressUpdate {
return currentProgress
}
}

override fun pigeon_defaultConstructor(): ContentProgressProvider {
return ContentProgressProviderImpl(this)
}

override fun setContentProgress(
pigeon_instance: ContentProgressProvider,
update: VideoProgressUpdate
) {
(pigeon_instance as ContentProgressProviderImpl).currentProgress = update
}
}
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.2.0), do not edit directly.
// Autogenerated from Pigeon (v22.3.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass", "SyntheticAccessor")

Expand Down Expand Up @@ -423,9 +423,7 @@ abstract class InteractiveMediaAdsLibraryPigeonProxyApiRegistrar(
* An implementation of [PigeonApiContentProgressProvider] used to add a new Dart instance of
* `ContentProgressProvider` to the Dart `InstanceManager`.
*/
open fun getPigeonApiContentProgressProvider(): PigeonApiContentProgressProvider {
return PigeonApiContentProgressProvider(this)
}
abstract fun getPigeonApiContentProgressProvider(): PigeonApiContentProgressProvider

/**
* An implementation of [PigeonApiAdsManager] used to add a new Dart instance of `AdsManager` to
Expand Down Expand Up @@ -544,6 +542,8 @@ abstract class InteractiveMediaAdsLibraryPigeonProxyApiRegistrar(
binaryMessenger, instanceManager)
PigeonApiAdsLoader.setUpMessageHandlers(binaryMessenger, getPigeonApiAdsLoader())
PigeonApiAdsRequest.setUpMessageHandlers(binaryMessenger, getPigeonApiAdsRequest())
PigeonApiContentProgressProvider.setUpMessageHandlers(
binaryMessenger, getPigeonApiContentProgressProvider())
PigeonApiAdsManager.setUpMessageHandlers(binaryMessenger, getPigeonApiAdsManager())
PigeonApiBaseManager.setUpMessageHandlers(binaryMessenger, getPigeonApiBaseManager())
PigeonApiImaSdkFactory.setUpMessageHandlers(binaryMessenger, getPigeonApiImaSdkFactory())
Expand All @@ -566,6 +566,7 @@ abstract class InteractiveMediaAdsLibraryPigeonProxyApiRegistrar(
InteractiveMediaAdsLibraryPigeonInstanceManagerApi.setUpMessageHandlers(binaryMessenger, null)
PigeonApiAdsLoader.setUpMessageHandlers(binaryMessenger, null)
PigeonApiAdsRequest.setUpMessageHandlers(binaryMessenger, null)
PigeonApiContentProgressProvider.setUpMessageHandlers(binaryMessenger, null)
PigeonApiAdsManager.setUpMessageHandlers(binaryMessenger, null)
PigeonApiBaseManager.setUpMessageHandlers(binaryMessenger, null)
PigeonApiImaSdkFactory.setUpMessageHandlers(binaryMessenger, null)
Expand Down Expand Up @@ -1429,9 +1430,83 @@ abstract class PigeonApiAdsRequest(
* https://developers.google.com/ad-manager/dynamic-ad-insertion/sdk/android/api/reference/com/google/ads/interactivemedia/v3/api/player/ContentProgressProvider.html.
*/
@Suppress("UNCHECKED_CAST")
open class PigeonApiContentProgressProvider(
abstract class PigeonApiContentProgressProvider(
open val pigeonRegistrar: InteractiveMediaAdsLibraryPigeonProxyApiRegistrar
) {
abstract fun pigeon_defaultConstructor():
com.google.ads.interactivemedia.v3.api.player.ContentProgressProvider

/**
* Sets an update on the progress of the video.
*
* This is a custom method added to the native class because the native method
* `getContentProgress` requires a synchronous return value.
*/
abstract fun setContentProgress(
pigeon_instance: com.google.ads.interactivemedia.v3.api.player.ContentProgressProvider,
update: com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate
)

companion object {
@Suppress("LocalVariableName")
fun setUpMessageHandlers(
binaryMessenger: BinaryMessenger,
api: PigeonApiContentProgressProvider?
) {
val codec = api?.pigeonRegistrar?.codec ?: InteractiveMediaAdsLibraryPigeonCodec()
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.interactive_media_ads.ContentProgressProvider.pigeon_defaultConstructor",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_identifierArg = args[0] as Long
val wrapped: List<Any?> =
try {
api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
api.pigeon_defaultConstructor(), pigeon_identifierArg)
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.ContentProgressProvider.setContentProgress",
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.player.ContentProgressProvider
val updateArg =
args[1] as com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate
val wrapped: List<Any?> =
try {
api.setContentProgress(pigeon_instanceArg, updateArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}

@Suppress("LocalVariableName", "FunctionName")
/** Creates a Dart instance of ContentProgressProvider and attaches it to [pigeon_instanceArg]. */
fun pigeon_newInstance(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.player.VideoProgressUpdate
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import org.mockito.kotlin.mock

class ContentProgressProviderProxyApiTest {
@Test
fun pigeon_defaultConstructor() {
val api = TestProxyApiRegistrar().getPigeonApiContentProgressProvider()

assertTrue(
api.pigeon_defaultConstructor()
is ContentProgressProviderProxyApi.ContentProgressProviderImpl)
}

@Test
fun setContentProgress() {
val api = TestProxyApiRegistrar().getPigeonApiContentProgressProvider()

val instance =
ContentProgressProviderProxyApi.ContentProgressProviderImpl(
api as ContentProgressProviderProxyApi)
val mockProgressUpdate = mock<VideoProgressUpdate>()
api.setContentProgress(instance, mockProgressUpdate)

assertEquals(mockProgressUpdate, instance.currentProgress)
assertEquals(mockProgressUpdate, instance.contentProgress)
}
}
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.0"
static let pluginVersion = "0.2.1"

func pigeonDefaultConstructor(
pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer,
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.2.0), do not edit directly.
// Autogenerated from Pigeon (v22.3.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers

Expand Down Expand Up @@ -1397,6 +1397,40 @@ class AdsRequest extends PigeonInternalProxyApiBaseClass {
///
/// See https://developers.google.com/ad-manager/dynamic-ad-insertion/sdk/android/api/reference/com/google/ads/interactivemedia/v3/api/player/ContentProgressProvider.html.
class ContentProgressProvider extends PigeonInternalProxyApiBaseClass {
ContentProgressProvider({
super.pigeon_binaryMessenger,
super.pigeon_instanceManager,
}) {
final int pigeonVar_instanceIdentifier =
pigeon_instanceManager.addDartCreatedInstance(this);
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
_pigeonVar_codecContentProgressProvider;
final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger;
() async {
const String pigeonVar_channelName =
'dev.flutter.pigeon.interactive_media_ads.ContentProgressProvider.pigeon_defaultConstructor';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final List<Object?>? pigeonVar_replyList = await pigeonVar_channel
.send(<Object?>[pigeonVar_instanceIdentifier]) as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else {
return;
}
}();
}

/// Constructs [ContentProgressProvider] without creating the associated native object.
///
/// This should only be used by subclasses created by this library or to
Expand All @@ -1407,6 +1441,10 @@ class ContentProgressProvider extends PigeonInternalProxyApiBaseClass {
super.pigeon_instanceManager,
});

late final _PigeonInternalProxyApiBaseCodec
_pigeonVar_codecContentProgressProvider =
_PigeonInternalProxyApiBaseCodec(pigeon_instanceManager);

static void pigeon_setUpMessageHandlers({
bool pigeon_clearHandlers = false,
BinaryMessenger? pigeon_binaryMessenger,
Expand Down Expand Up @@ -1456,6 +1494,37 @@ class ContentProgressProvider extends PigeonInternalProxyApiBaseClass {
}
}

/// Sets an update on the progress of the video.
///
/// This is a custom method added to the native class because the native
/// method `getContentProgress` requires a synchronous return value.
Future<void> setContentProgress(VideoProgressUpdate update) async {
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
_pigeonVar_codecContentProgressProvider;
final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger;
const String pigeonVar_channelName =
'dev.flutter.pigeon.interactive_media_ads.ContentProgressProvider.setContentProgress';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final List<Object?>? pigeonVar_replyList =
await pigeonVar_channel.send(<Object?>[this, update]) as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else {
return;
}
}

@override
ContentProgressProvider pigeon_copy() {
return ContentProgressProvider.pigeon_detached(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,15 @@ abstract class AdsRequest {
'com.google.ads.interactivemedia.v3.api.player.ContentProgressProvider',
),
)
abstract class ContentProgressProvider {}
abstract class ContentProgressProvider {
ContentProgressProvider();

/// Sets an update on the progress of the video.
///
/// This is a custom method added to the native class because the native
/// method `getContentProgress` requires a synchronous return value.
void setContentProgress(VideoProgressUpdate update);
}

/// An object which handles playing ads after they've been received from the
/// server.
Expand Down
2 changes: 1 addition & 1 deletion packages/interactive_media_ads/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: interactive_media_ads
description: A Flutter plugin for using the Interactive Media Ads SDKs on Android and iOS.
repository: https://github.com/flutter/packages/tree/main/packages/interactive_media_ads
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+interactive_media_ads%22
version: 0.2.0 # This must match the version in
version: 0.2.1 # This must match the version in
# `android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt` and
# `ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift`

Expand Down

0 comments on commit 4c18648

Please sign in to comment.