@@ -13,15 +13,15 @@ class GDbanner {
13
13
14
14
protected static void init () {
15
15
16
- if (GDstatic .enable && !GDstatic .testAds ) {
17
- String url = GDstatic .GAME_API_URL + '/' + GDstatic .gameId ;
16
+ if (GDstatic .enable && !GDstatic .testAds ) {
17
+ String url = GDstatic .GAME_API_URL + '/' + GDstatic .gameId ;
18
18
GDHttpRequest .sendHttpRequest (GDlogger .mContext , url , Request .Method .GET , null , new GDHttpCallback () {
19
19
@ Override
20
20
public void onSuccess (JSONObject data ) {
21
21
22
22
try {
23
23
boolean success = data .getBoolean ("success" );
24
- if (success ) {
24
+ if (success ) {
25
25
JSONObject result = data .getJSONObject ("result" );
26
26
JSONObject game = result .getJSONObject ("game" );
27
27
@@ -33,13 +33,15 @@ public void onSuccess(JSONObject data) {
33
33
GDGameData .bundleId = game .getString ("androidBundleId" );
34
34
35
35
GDutils .log (data .toString ());
36
- GDlogger .gDad .init (GDlogger .mContext ,GDlogger .isCordovaPlugin );
37
- }
38
- else {
36
+ GDlogger .gDad .init (GDlogger .mContext , GDlogger .isCordovaPlugin );
37
+
38
+ GDlogger .gdPreloadStream .setPreloadStream (true );
39
+ GDlogger .gdPreloadStream .init (GDlogger .mContext , GDlogger .isCordovaPlugin );
40
+ } else {
39
41
String error = "Something went wrong fetching game data." ;
40
42
GDutils .log (error );
41
43
42
- if (GDlogger .gDad .devListener != null )
44
+ if (GDlogger .gDad .devListener != null )
43
45
GDlogger .gDad .devListener .onAPINotReady (error );
44
46
GDstatic .enable = false ;
45
47
@@ -48,7 +50,7 @@ public void onSuccess(JSONObject data) {
48
50
} catch (JSONException e ) {
49
51
e .printStackTrace ();
50
52
GDutils .log ("Something went wrong parsing json game data." );
51
- if (GDlogger .gDad .devListener != null )
53
+ if (GDlogger .gDad .devListener != null )
52
54
GDlogger .gDad .devListener .onAPINotReady ("Something went wrong parsing json game data." );
53
55
GDstatic .enable = false ;
54
56
@@ -58,15 +60,16 @@ public void onSuccess(JSONObject data) {
58
60
@ Override
59
61
public void onError (VolleyError error ) {
60
62
GDutils .log ("Something went wrong fetching json game data." );
61
- if (GDlogger .gDad .devListener != null )
63
+ if (GDlogger .gDad .devListener != null )
62
64
GDlogger .gDad .devListener .onAPINotReady ("Something went wrong fetching json game data." );
63
65
GDstatic .enable = false ;
64
66
65
67
}
66
68
});
67
- }
68
- else if (GDstatic .testAds ){
69
- GDlogger .gDad .init (GDlogger .mContext ,GDlogger .isCordovaPlugin );
69
+ } else if (GDstatic .testAds ) {
70
+ GDlogger .gDad .init (GDlogger .mContext , GDlogger .isCordovaPlugin );
71
+ GDlogger .gdPreloadStream .setPreloadStream (true );
72
+ GDlogger .gdPreloadStream .init (GDlogger .mContext , GDlogger .isCordovaPlugin );
70
73
}
71
74
}
72
75
@@ -76,11 +79,12 @@ protected static void ShowBanner(String args) {
76
79
final GDshowObj gDshowObj ;
77
80
gDshowObj = gson .fromJson (args , GDshowObj .class );
78
81
79
-
80
82
if ((GDGameData .enableAds || GDstatic .testAds ) && gDshowObj ._key != null && gDshowObj ._key .equals ("preroll" ) && GDlogger .gDad != null ) {
81
83
82
84
if (GDGameData .preRoll ) {
83
- GDlogger .gDad .showBanner (args );
85
+
86
+ ShowPreloadedBanner (args );
87
+
84
88
} else {
85
89
if (GDlogger .gDad .devListener != null ) {
86
90
GDlogger .gDad .devListener .onBannerFailed ("Banner request failed: 'Preroll is disabled.'" );
@@ -93,14 +97,13 @@ protected static void ShowBanner(String args) {
93
97
if (gDshowObj .isInterstitial ) {
94
98
if (GDstatic .reqInterstitialEnabled ) {
95
99
96
- GDlogger . gDad . showBanner (args );
100
+ ShowPreloadedBanner (args );
97
101
adInterstitialTimer = null ;
98
102
99
- if (!GDstatic .testAds ){
103
+ if (!GDstatic .testAds ) {
100
104
setAdTimer (true ); // inter timer
101
105
GDstatic .reqInterstitialEnabled = false ;
102
- }
103
- else {
106
+ } else {
104
107
GDstatic .reqInterstitialEnabled = true ;
105
108
}
106
109
@@ -110,12 +113,11 @@ protected static void ShowBanner(String args) {
110
113
GDlogger .gDad .devListener .onBannerFailed ("You can not invoke 'ShowBanner()' within " + GDGameData .timeAds + " min(s)." );
111
114
}
112
115
}
113
- }
114
- else {
116
+ } else {
115
117
if (GDstatic .reqBannerEnabled ) {
116
118
GDlogger .gDad .showBanner (args );
117
119
adBannerTimer = null ;
118
- if (!GDstatic .testAds ){
120
+ if (!GDstatic .testAds ) {
119
121
setAdTimer (false ); // banner timer
120
122
GDstatic .reqBannerEnabled = false ;
121
123
}
@@ -132,13 +134,35 @@ protected static void ShowBanner(String args) {
132
134
if (GDlogger .gDad .devListener != null ) {
133
135
GDlogger .gDad .devListener .onBannerFailed ("Banner request failed: 'Midroll is disabled.'" );
134
136
}
137
+
135
138
}
136
139
137
140
}
138
141
139
142
140
143
}
141
144
145
+ protected static void ShowPreloadedBanner (String args ) {
146
+ // If preloaded ad exists, then show it.
147
+ // Otherwise, make sure you request preload and also request new ad to show.
148
+ if (GDlogger .gdPreloadStream .isPreloadedAdExist ()){
149
+ GDlogger .gdPreloadStream .showInterstitialAd ();
150
+ }
151
+ else {
152
+ if (!GDlogger .gdPreloadStream .isPreloadedAdLoading ()) {
153
+ if (GDlogger .gDad .devListener != null ) {
154
+ GDlogger .gDad .devListener .onPreloadFailed ("No ads found preloaded." );
155
+ }
156
+ GDlogger .gdPreloadStream .requestPreloadAd ();
157
+ } else {
158
+ if (GDlogger .gDad .devListener != null ) {
159
+ GDlogger .gDad .devListener .onPreloadFailed ("A preload ad is currently being loaded." );
160
+ }
161
+ }
162
+ GDlogger .gDad .showBanner (args );
163
+ }
164
+ }
165
+
142
166
private static void setAdTimer (final boolean isInterstitial ) {
143
167
144
168
if (GDstatic .enable ) {
0 commit comments