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

Commit 7f8efac

Browse files
mickykebekroikie
authored andcommitted
listener on MobileAd shouldn't be final (#650)
* listener on MobileAd shouldn't be final * Ad listeners shouldn't necessarily have to be set during Ad initialization. * add isLoaded method to firebase_admob MobileAd checking whether ad has been loaded.
1 parent cd60fb0 commit 7f8efac

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

packages/firebase_admob/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.6.1
2+
3+
* listener on MobileAd shouldn't be final.
4+
* Ad listeners can to be set in or out of Ad initialization.
5+
16
## 0.6.0
27

38
* Add nonPersonalizedAds option to MobileAdTargetingInfo

packages/firebase_admob/android/src/main/java/io/flutter/plugins/firebaseadmob/FirebaseAdMobPlugin.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ private void callShowAd(int id, MethodCall call, Result result) {
154154
result.success(Boolean.TRUE);
155155
}
156156

157+
private void callIsAdLoaded(int id, MethodCall call, Result result) {
158+
MobileAd ad = MobileAd.getAdForId(id);
159+
if (ad == null) {
160+
result.error("no_ad_for_id", "isAdLoaded failed, no add exists for id=" + id, null);
161+
return;
162+
}
163+
result.success(ad.status == MobileAd.Status.LOADED ? Boolean.TRUE : Boolean.FALSE);
164+
}
165+
157166
private void callShowRewardedVideoAd(MethodCall call, Result result) {
158167
if (rewardedWrapper.getStatus() == RewardedVideoAdWrapper.Status.LOADED) {
159168
rewardedWrapper.show();
@@ -208,6 +217,9 @@ public void onMethodCall(MethodCall call, Result result) {
208217
case "disposeAd":
209218
callDisposeAd(id, call, result);
210219
break;
220+
case "isAdLoaded":
221+
callIsAdLoaded(id, call, result);
222+
break;
211223
default:
212224
result.notImplemented();
213225
}

packages/firebase_admob/ios/Classes/FirebaseAdMobPlugin.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,23 @@ - (void)callShowAd:(NSNumber *)mobileAdId
210210
result([NSNumber numberWithBool:YES]);
211211
}
212212

213+
- (void)callIsAdLoaded:(NSNumber *)mobileAdId
214+
call:(FlutterMethodCall *)call
215+
result:(FlutterResult)result {
216+
FLTMobileAd *ad = [FLTMobileAd getAdForId:mobileAdId];
217+
if (ad == nil) {
218+
NSString *message = [NSString
219+
stringWithFormat:@"isAdLoaded failed, no ad exists for id=%d", mobileAdId.intValue];
220+
result([FlutterError errorWithCode:@"no_ad_for_id" message:message details:nil]);
221+
return;
222+
}
223+
if (ad.status == LOADED) {
224+
result([NSNumber numberWithBool:YES]);
225+
} else {
226+
result([NSNumber numberWithBool:NO]);
227+
}
228+
}
229+
213230
- (void)callShowRewardedVideoAd:(FlutterMethodCall *)call result:(FlutterResult)result {
214231
if (self.rewardedWrapper.status != FLTRewardedVideoAdStatusLoaded) {
215232
result([FlutterError errorWithCode:@"ad_not_loaded"
@@ -270,6 +287,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
270287
result:result];
271288
} else if ([call.method isEqualToString:@"showAd"]) {
272289
[self callShowAd:mobileAdId call:call result:result];
290+
} else if ([call.method isEqualToString:@"isAdLoaded"]) {
291+
[self callIsAdLoaded:mobileAdId call:call result:result];
273292
} else if ([call.method isEqualToString:@"disposeAd"]) {
274293
[self callDisposeAd:mobileAdId call:call result:result];
275294
} else {

packages/firebase_admob/lib/firebase_admob.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ abstract class MobileAd {
190190
final String adUnitId;
191191

192192
/// Called when the status of the ad changes.
193-
final MobileAdListener listener;
193+
MobileAdListener listener;
194194

195195
/// An internal id that identifies this mobile ad to the native AdMob plugin.
196196
///
@@ -228,6 +228,12 @@ abstract class MobileAd {
228228
_allAds[id] = null;
229229
return _invokeBooleanMethod("disposeAd", <String, dynamic>{'id': id});
230230
}
231+
232+
Future<bool> isLoaded() {
233+
return _invokeBooleanMethod("isAdLoaded", <String, dynamic>{
234+
'id': id,
235+
});
236+
}
231237
}
232238

233239
/// A banner ad for the [FirebaseAdMobPlugin].

packages/firebase_admob/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: firebase_admob
22
description: Firebase AdMob plugin for Flutter applications.
33
author: Flutter Team <[email protected]>
44
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_admob
5-
version: 0.6.0
5+
version: 0.6.1
66

77
flutter:
88
plugin:

0 commit comments

Comments
 (0)