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

[firebase_admob] update AGP, gradle and admob #34

Merged
merged 3 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions packages/firebase_admob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.9.0+6

* Update Android gradle plugin, gradle, and Admob versions.
* Improvements to the Android implementation, fixing warnings about a possible null pointer exception.

## 0.9.0+5

* Update documentation to reflect new repository location.
Expand Down
4 changes: 2 additions & 2 deletions packages/firebase_admob/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.4.2'
}
}

Expand All @@ -45,6 +45,6 @@ android {
disable 'InvalidPackage'
}
dependencies {
api 'com.google.firebase:firebase-ads:17.2.0'
api 'com.google.firebase:firebase-ads:18.1.1'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.google.android.gms.ads.AdRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

class AdRequestBuilderFactory {
Expand Down Expand Up @@ -53,29 +54,28 @@ private Integer getTargetingInfoInteger(String key, Object value) {
return (Integer) value;
}

private ArrayList getTargetingInfoArrayList(String key, Object value) {
private List getTargetingInfoArrayList(String key, Object value) {
if (value == null) return null;
if (!(value instanceof ArrayList)) {
Log.w(TAG, "targeting info " + key + ": expected an ArrayList");
return null;
}
return (ArrayList) value;
return (List) value;
}

AdRequest.Builder createAdRequestBuilder() {
AdRequest.Builder builder = new AdRequest.Builder();
if (targetingInfo == null) return builder;

ArrayList testDevices =
getTargetingInfoArrayList("testDevices", targetingInfo.get("testDevices"));
List testDevices = getTargetingInfoArrayList("testDevices", targetingInfo.get("testDevices"));
if (testDevices != null) {
for (Object deviceValue : testDevices) {
String device = getTargetingInfoString("testDevices element", deviceValue);
if (device != null) builder.addTestDevice(device);
}
}

ArrayList keywords = getTargetingInfoArrayList("keywords", targetingInfo.get("keywords"));
List keywords = getTargetingInfoArrayList("keywords", targetingInfo.get("keywords"));
if (keywords != null) {
for (Object keywordValue : keywords) {
String keyword = getTargetingInfoString("keywords element", keywordValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import java.util.Locale;
import java.util.Map;

public class FirebaseAdMobPlugin implements MethodCallHandler {
Expand Down Expand Up @@ -51,34 +52,41 @@ private void callInitialize(MethodCall call, Result result) {
result.success(Boolean.TRUE);
}

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

int width = call.argument("width");
int height = call.argument("height");
String adSizeType = call.argument("adSizeType");
final Integer width = call.argument("width");
final Integer height = call.argument("height");
final String adSizeType = call.argument("adSizeType");

if (!adSizeType.equals("AdSizeType.WidthAndHeight")
&& !adSizeType.equals("AdSizeType.SmartBanner")) {
if (!"AdSizeType.WidthAndHeight".equals(adSizeType)
&& !"AdSizeType.SmartBanner".equals(adSizeType)) {
String errMsg =
String.format("an invalid adSizeType (%s) was provided for banner id=%d", adSizeType, id);
String.format(
Locale.ENGLISH,
"an invalid adSizeType (%s) was provided for banner id=%d",
adSizeType,
id);
result.error("invalid_adsizetype", errMsg, null);
}

if (adSizeType.equals("AdSizeType.WidthAndHeight") && (width <= 0 || height <= 0)) {
if ("AdSizeType.WidthAndHeight".equals(adSizeType) && (width <= 0 || height <= 0)) {
String errMsg =
String.format(
"an invalid AdSize (%d, %d) was provided for banner id=%d", width, height, id);
Locale.ENGLISH,
"an invalid AdSize (%d, %d) was provided for banner id=%d",
width,
height,
id);
result.error("invalid_adsize", errMsg, null);
}

AdSize adSize;
if (adSizeType.equals("AdSizeType.SmartBanner")) {
if ("AdSizeType.SmartBanner".equals(adSizeType)) {
adSize = AdSize.SMART_BANNER;
} else {
adSize = new AdSize(width, height);
Expand Down Expand Up @@ -142,28 +150,30 @@ private void callLoadRewardedVideoAd(MethodCall call, Result result) {
result.success(Boolean.TRUE);
}

private void callShowAd(int id, MethodCall call, Result result) {
private void callShowAd(Integer id, MethodCall call, Result result) {
MobileAd ad = MobileAd.getAdForId(id);
if (ad == null) {
result.error("ad_not_loaded", "show failed, the specified ad was not loaded id=" + id, null);
return;
}
if (call.argument("anchorOffset") != null) {
ad.anchorOffset = Double.parseDouble((String) call.argument("anchorOffset"));
final String anchorOffset = call.argument("anchorOffset");
final String horizontalCenterOffset = call.argument("horizontalCenterOffset");
final String anchorType = call.argument("anchorType");
if (anchorOffset != null) {
ad.anchorOffset = Double.parseDouble(anchorOffset);
}
if (call.argument("horizontalCenterOffset") != null) {
ad.horizontalCenterOffset =
Double.parseDouble((String) call.argument("horizontalCenterOffset"));
if (anchorType != null) {
ad.horizontalCenterOffset = Double.parseDouble(horizontalCenterOffset);
}
if (call.argument("anchorType") != null) {
ad.anchorType = call.argument("anchorType").equals("bottom") ? Gravity.BOTTOM : Gravity.TOP;
if (anchorType != null) {
ad.anchorType = "bottom".equals(anchorType) ? Gravity.BOTTOM : Gravity.TOP;
}

ad.show();
result.success(Boolean.TRUE);
}

private void callIsAdLoaded(int id, MethodCall call, Result result) {
private void callIsAdLoaded(Integer id, Result result) {
MobileAd ad = MobileAd.getAdForId(id);
if (ad == null) {
result.error("no_ad_for_id", "isAdLoaded failed, no add exists for id=" + id, null);
Expand All @@ -172,7 +182,7 @@ private void callIsAdLoaded(int id, MethodCall call, Result result) {
result.success(ad.status == MobileAd.Status.LOADED ? Boolean.TRUE : Boolean.FALSE);
}

private void callShowRewardedVideoAd(MethodCall call, Result result) {
private void callShowRewardedVideoAd(Result result) {
if (rewardedWrapper.getStatus() == RewardedVideoAdWrapper.Status.LOADED) {
rewardedWrapper.show();
result.success(Boolean.TRUE);
Expand All @@ -181,7 +191,7 @@ private void callShowRewardedVideoAd(MethodCall call, Result result) {
}
}

private void callDisposeAd(int id, MethodCall call, Result result) {
private void callDisposeAd(Integer id, Result result) {
MobileAd ad = MobileAd.getAdForId(id);
if (ad == null) {
result.error("no_ad_for_id", "dispose failed, no add exists for id=" + id, null);
Expand All @@ -194,10 +204,6 @@ private void callDisposeAd(int id, MethodCall call, Result result) {

@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("initialize")) {
callInitialize(call, result);
return;
}

Activity activity = registrar.activity();
if (activity == null) {
Expand All @@ -208,8 +214,11 @@ public void onMethodCall(MethodCall call, Result result) {
Integer id = call.argument("id");

switch (call.method) {
case "initialize":
callInitialize(call, result);
break;
case "loadBannerAd":
callLoadBannerAd(id, activity, channel, call, result);
callLoadBannerAd(id, activity, call, result);
break;
case "loadInterstitialAd":
callLoadInterstitialAd(MobileAd.createInterstitial(id, activity, channel), call, result);
Expand All @@ -221,13 +230,13 @@ public void onMethodCall(MethodCall call, Result result) {
callShowAd(id, call, result);
break;
case "showRewardedVideoAd":
callShowRewardedVideoAd(call, result);
callShowRewardedVideoAd(result);
break;
case "disposeAd":
callDisposeAd(id, call, result);
callDisposeAd(id, result);
break;
case "isAdLoaded":
callIsAdLoaded(id, call, result);
callIsAdLoaded(id, result);
break;
default:
result.notImplemented();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.*;
import io.flutter.plugin.common.MethodChannel;
import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
public class RewardedVideoAdWrapper implements RewardedVideoAdListener {
private static final String TAG = "flutter";

final RewardedVideoAd rewardedInstance;
final Activity activity;
final MethodChannel channel;
Status status;
private final RewardedVideoAd rewardedInstance;
private final MethodChannel channel;
private Status status;

@Override
public void onRewardedVideoAdLoaded() {
Expand Down Expand Up @@ -76,7 +75,6 @@ enum Status {
}

public RewardedVideoAdWrapper(Activity activity, MethodChannel channel) {
this.activity = activity;
this.channel = channel;
this.status = Status.CREATED;
this.rewardedInstance = MobileAds.getRewardedVideoAdInstance(activity);
Expand Down
4 changes: 2 additions & 2 deletions packages/firebase_admob/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ flutter {

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

apply plugin: 'com.google.gms.google-services'
2 changes: 1 addition & 1 deletion packages/firebase_admob/example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.3.0'
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Thu Aug 01 22:44:13 BRT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
2 changes: 1 addition & 1 deletion packages/firebase_admob/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Firebase AdMob, supporting
banner, interstitial (full-screen), and rewarded video ads
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_admob
version: 0.9.0+5
version: 0.9.0+6

flutter:
plugin:
Expand Down