Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

AdSizes for AdMob banner ads #402

Merged
merged 7 commits into from
Mar 19, 2018
Merged

AdSizes for AdMob banner ads #402

merged 7 commits into from
Mar 19, 2018

Conversation

RedBrogdon
Copy link
Contributor

@RedBrogdon RedBrogdon commented Mar 1, 2018

This PR adds a new AdSize class to the firebase_admob plugin for use in making banners (see Issue #8098). All the standard sizes are supported (see this AdMob guide for a list).

Right now, the public API and Android implementation are worked out, with iOS and finishing touches to come. I'm putting it up early so people can have a look at the API.

private void callLoadBannerAd(int id, Activity activity, MethodChannel channel, MethodCall call, Result result) {
String adUnitId = call.argument("adUnitId");
if (adUnitId == null || adUnitId.isEmpty()) {
result.error("no_unit_id", "a non-empty adUnitId was not provided for ad id=" + id, null);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording is a bit confusing. Would you be open to changing this to something like a null or empty adUnitId...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to see this final bit of the banner ad API!

Just a few comments about how ad sizes are represented.

SmartBanner,
}

/// [AdSize] represents the size of a banner ad.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to link to the relevant doc here; https://developers.google.com/admob/android/banner#banner_sizes I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

/// [AdSize] represents the size of a banner ad.
class AdSize {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just expose const constructors, like const AdSize.banner(), although it might be simpler to just expose statics, like AdSize.banner`.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually dithering about the most Dart-like way to do this, so I'm glad you brought it up. If having pre-built instances hang out as static constants is allowed, that's my preference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it doesn't matter here, static final class constants are computed lazily. Which is nice.

/// to use one of the named constructors like [AdSize.banner].
AdSize({this.width, this.height})
: assert(width > 0),
assert(height > 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you want to expose this constructor, since all of the valid ad sizes are covered by the other constructors.

It should be a (private) const constructor where all of the parameters are @required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. If the plugin is ever expanded to handle DoubleClick for Publishers, it'll need to be made public again, but this is just fine for AdMob.

/// automatically adjust their width to match that of the displaying device's
/// screen. Height also varies, and will be 32, 50, or 90 depending on how
/// tall the screen is.
AdSize.smartBanner()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs, it seems like there are only three valid height values (and you can't really specify the width?). You could either provide three constants or just provide a const constructor whose width could only be one of the 3 valid values.

Since the recommended practice is to base the banner's size on the screen size, you could also provide a smartBannerFor(MediaQueryData) constructor that DTRT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to revise this comment, since it clearly didn't impart the right info. :)

If you choose "smart banner" as your ad size, there are no other inputs you're allowed to give. You, as the publisher, do not determine how wide or high the ad is. The SDK will automatically set the width of the AdView to match the device width, and will set its height based on a calculation involving device height. So there's nothing more for the API to do here other than give the publisher a way to say "make me an AdSize object of the smart banner type."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I just didn't read this stuff carefully enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't have to, though, so it's good feedback.

/// Create a BannerAd.
///
/// A valid [adUnitId] is required.
BannerAd({
@required String adUnitId,
@required this.size,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not give this a default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two reasons, I guess.

  • Our Android and iOS APIs don't have a default, so it's what I'm used to.
  • In my mind, publishers should be consciously picking a size based on what their UI looks like. Most will pick the standard 320x50 banner anyway, but I'd like for them to think at least for a moment about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, sounds reasonable.

@@ -82,6 +82,65 @@ class MobileAdTargetingInfo {
}
}

// The types of ad sizes supported for banners.
enum AdSizeType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like indices of these enums are significant. That's worth a '//' implementation comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just add to the comment that's there and indicate how I'm using the index values? If there's an example of a similar comment, feel free to point me to it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.flutter.io/flutter/scheduler/SchedulerPhase-class.html uses an enum's index this way

It feels a little brittle to rely on the index because adding another id could disturb things. On the other hand, you could easily write a regression test that checked this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. What about passing the String name of the value, then, rather than using the index?

@mit-mit
Copy link
Member

mit-mit commented Mar 2, 2018

Thanks much @RedBrogdon for the contribution! Looks like there is a small merge conflict with master. Can you take a quick look?

@Purus
Copy link

Purus commented Mar 3, 2018

Please let me know I can be of any help on this?
Also kindly check on the issue flutter/flutter#14222 if you can help on this.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no and removed cla: yes labels Mar 7, 2018
@RedBrogdon
Copy link
Contributor Author

The API is finished at this point, and it's implemented all the way down for iOS and Android. Tests are passing, and the code's linted.

PTAL!

@RedBrogdon RedBrogdon changed the title [WIP] AdSizes for AdMob banner ads AdSizes for AdMob banner ads Mar 8, 2018
@Purus
Copy link

Purus commented Mar 9, 2018

Hope it's merged soon :)

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -38,14 +39,61 @@ private FirebaseAdMobPlugin(Registrar registrar, MethodChannel channel) {
private void callInitialize(MethodCall call, Result result) {
String appId = call.argument("appId");
if (appId == null || appId.isEmpty()) {
result.error("no_app_id", "a non-empty AdMob appId was not provided", null);
result.error("no_app_id", "a null or empty AdMob appId was provided", null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE

@RedBrogdon
Copy link
Contributor Author

@Purus, to answer your earlier question about what you might do to help: please give this a thorough test in whatever apps you're working on. It's playing along just fine for me, but I'm sure there are edge cases I haven't discovered.

@Purus
Copy link

Purus commented Mar 10, 2018

Sure.. I am happy to test it in my development apps. I will test once this is merged.

@RedBrogdon
Copy link
Contributor Author

When is this one likely to get merged?

@HansMuller
Copy link
Contributor

Sorry about the delay, landing and publishing this PR now

@HansMuller HansMuller merged commit fe2f653 into flutter:master Mar 19, 2018
@HansMuller HansMuller mentioned this pull request Mar 19, 2018
jonasbark pushed a commit to jonasbark/plugins that referenced this pull request Mar 20, 2018
* commit 'a404fbfd4842b51b57bc0c6298604cf5674e2c02': (40 commits)
  Update README.md (flutter#430)
  Updated to 0.5.0 (flutter#428)
  AdSizes for AdMob banner ads (flutter#402)
  bump minor version and add changelog entry (flutter#427)
  add fetchProvidersForEmail wrapper (flutter#410)
  Incremental Build Script (flutter#422)
  add runtime permission requests for external storage and camera (flutter#424)
  Fix Dart 2 type error and deprecation (flutter#425)
  Fix a Dart 2 runtime cast failure in firebase_database test (flutter#419)
  Fixed deprecation warnings (flutter#420)
  Fix Dart 2 runtime error in the camera plugin (flutter#417)
  Always use the latest Flutter available (flutter#415)
  Spelling (flutter#411)
  Configure Flutter CI (flutter#383)
  Set SDK constraints to match Flutter beta (flutter#412)
  Remove Gradle artifacts from repo (flutter#414)
  Google maps plugin stub (flutter#405)
  Allow null document snapshot data when document does not exist (flutter#406)
  Fix new formatting errors (flutter#408)
  Fix url_launcher for iOS <10 (flutter#407)
  ...
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
Adds a new AdSize class to the firebase_admob plugin for use in making banners (see Issue #8098). All the standard sizes are supported.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants