-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 initial Android implementation #6733
base: main
Are you sure you want to change the base?
Conversation
|
||
// org.jetbrains.kotlin:kotlin-bom artifact purpose is to align kotlin stdlib and related code versions. | ||
// See: https://youtrack.jetbrains.com/issue/KT-55297/kotlin-stdlib-should-declare-constraints-on-kotlin-stdlib-jdk8-and-kotlin-stdlib-jdk7 | ||
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.10")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same line added to camera_android_camerax
: https://github.com/flutter/packages/blob/main/packages/camera/camera_android_camerax/android/build.gradle#L77
This fixed the build failure when adding the 'com.google.ads.interactivemedia.v3:interactivemedia:3.33.0'
dependency.
// of waiting for the main thread to run it. | ||
internal open fun runOnMainThread(callback: Runnable) { | ||
Handler(Looper.getMainLooper()).post { callback.run() } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added to the registrar to make it easier to handle and test callback methods on the correct thread.
override fun setVolume(pigeon_instance: VideoAdPlayer, value: Long) { | ||
(pigeon_instance as VideoAdPlayerImpl).savedVolume = value.toInt() | ||
} | ||
|
||
override fun setAdProgress(pigeon_instance: VideoAdPlayer, progress: VideoProgressUpdate) { | ||
(pigeon_instance as VideoAdPlayerImpl).savedAdProgress = progress | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom methods added since VideoAdPlayer.getVolume
and VideoAdPlayer.getAdProgress
require a synchronous callback method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth adding this as a code comment to these methods. It would be good to have it clarify why it's not calling api.foo
in addition to saving the value.
packages/interactive_media_ads/lib/src/android/android_ad_display_container.dart
Show resolved
Hide resolved
packages/interactive_media_ads/lib/src/android/android_ad_display_container.dart
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I only briefly skimmed the tests.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use InteractiveMediaAdsLibrary.g.kt
? I thought it was only Java that prevented using the extra suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I forgot that we only did that because of the limitations of Java and Obj-c.
AdError.AdErrorCode.INVALID_ARGUMENTS -> AdErrorCode.INVALID_ARGUMENTS | ||
AdError.AdErrorCode.PLAYLIST_NO_CONTENT_TRACKING -> AdErrorCode.PLAYLIST_NO_CONTENT_TRACKING | ||
AdError.AdErrorCode.UNEXPECTED_ADS_LOADED_EVENT -> AdErrorCode.UNEXPECTED_ADS_LOADED_EVENT | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this doesn't handle the case where a new error code is added upstream. It seems like it would probably even fail to compile if that happened?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention was for this to break compilation when a new enum is added. Since this uses a pinned version of the IMA SDK, we can add a new enum to the code generation whenever we bump the version.
We add an unknown
enum in the webview_flutter
implementations, but I assumed we did that because it uses a system library and not a pinned SDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this uses a pinned version of the IMA SDK
It doesn't really though, because of optimistic upgrades. Because of the way Gradle works, unless we want to make the entire build fail on conflicts (which would be a large hammer) we don't actually have any control over whether we get the version listed in build.gradle.
...d/src/main/kotlin/dev/flutter/packages/interactive_media_ads/BaseDisplayContainerProxyApi.kt
Show resolved
Hide resolved
override fun setVolume(pigeon_instance: VideoAdPlayer, value: Long) { | ||
(pigeon_instance as VideoAdPlayerImpl).savedVolume = value.toInt() | ||
} | ||
|
||
override fun setAdProgress(pigeon_instance: VideoAdPlayer, progress: VideoProgressUpdate) { | ||
(pigeon_instance as VideoAdPlayerImpl).savedAdProgress = progress | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth adding this as a code comment to these methods. It would be good to have it clarify why it's not calling api.foo
in addition to saving the value.
packages/interactive_media_ads/lib/src/android/android_ad_display_container.dart
Outdated
Show resolved
Hide resolved
packages/interactive_media_ads/lib/src/android/android_ad_display_container.dart
Show resolved
Hide resolved
packages/interactive_media_ads/lib/src/android/android_ad_display_container.dart
Show resolved
Hide resolved
) onError, | ||
void Function( | ||
VideoView, | ||
MediaPlayer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't some of these be more readable without the trailing comma? Or would the inconsistency hurt readability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, it does make it more readable. I removed the trailing commas
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// // ignore_for_file: avoid_unused_constructor_parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is everything in this file commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once the remaining comment about the enum fallback is resolved.
Android implementation for flutter/flutter#134228
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.