@@ -13,15 +13,15 @@ class GDbanner {
1313
1414 protected static void init () {
1515
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 ;
1818 GDHttpRequest .sendHttpRequest (GDlogger .mContext , url , Request .Method .GET , null , new GDHttpCallback () {
1919 @ Override
2020 public void onSuccess (JSONObject data ) {
2121
2222 try {
2323 boolean success = data .getBoolean ("success" );
24- if (success ) {
24+ if (success ) {
2525 JSONObject result = data .getJSONObject ("result" );
2626 JSONObject game = result .getJSONObject ("game" );
2727
@@ -33,13 +33,15 @@ public void onSuccess(JSONObject data) {
3333 GDGameData .bundleId = game .getString ("androidBundleId" );
3434
3535 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 {
3941 String error = "Something went wrong fetching game data." ;
4042 GDutils .log (error );
4143
42- if (GDlogger .gDad .devListener != null )
44+ if (GDlogger .gDad .devListener != null )
4345 GDlogger .gDad .devListener .onAPINotReady (error );
4446 GDstatic .enable = false ;
4547
@@ -48,7 +50,7 @@ public void onSuccess(JSONObject data) {
4850 } catch (JSONException e ) {
4951 e .printStackTrace ();
5052 GDutils .log ("Something went wrong parsing json game data." );
51- if (GDlogger .gDad .devListener != null )
53+ if (GDlogger .gDad .devListener != null )
5254 GDlogger .gDad .devListener .onAPINotReady ("Something went wrong parsing json game data." );
5355 GDstatic .enable = false ;
5456
@@ -58,15 +60,16 @@ public void onSuccess(JSONObject data) {
5860 @ Override
5961 public void onError (VolleyError error ) {
6062 GDutils .log ("Something went wrong fetching json game data." );
61- if (GDlogger .gDad .devListener != null )
63+ if (GDlogger .gDad .devListener != null )
6264 GDlogger .gDad .devListener .onAPINotReady ("Something went wrong fetching json game data." );
6365 GDstatic .enable = false ;
6466
6567 }
6668 });
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 );
7073 }
7174 }
7275
@@ -76,11 +79,12 @@ protected static void ShowBanner(String args) {
7679 final GDshowObj gDshowObj ;
7780 gDshowObj = gson .fromJson (args , GDshowObj .class );
7881
79-
8082 if ((GDGameData .enableAds || GDstatic .testAds ) && gDshowObj ._key != null && gDshowObj ._key .equals ("preroll" ) && GDlogger .gDad != null ) {
8183
8284 if (GDGameData .preRoll ) {
83- GDlogger .gDad .showBanner (args );
85+
86+ ShowPreloadedBanner (args );
87+
8488 } else {
8589 if (GDlogger .gDad .devListener != null ) {
8690 GDlogger .gDad .devListener .onBannerFailed ("Banner request failed: 'Preroll is disabled.'" );
@@ -93,14 +97,13 @@ protected static void ShowBanner(String args) {
9397 if (gDshowObj .isInterstitial ) {
9498 if (GDstatic .reqInterstitialEnabled ) {
9599
96- GDlogger . gDad . showBanner (args );
100+ ShowPreloadedBanner (args );
97101 adInterstitialTimer = null ;
98102
99- if (!GDstatic .testAds ){
103+ if (!GDstatic .testAds ) {
100104 setAdTimer (true ); // inter timer
101105 GDstatic .reqInterstitialEnabled = false ;
102- }
103- else {
106+ } else {
104107 GDstatic .reqInterstitialEnabled = true ;
105108 }
106109
@@ -110,12 +113,11 @@ protected static void ShowBanner(String args) {
110113 GDlogger .gDad .devListener .onBannerFailed ("You can not invoke 'ShowBanner()' within " + GDGameData .timeAds + " min(s)." );
111114 }
112115 }
113- }
114- else {
116+ } else {
115117 if (GDstatic .reqBannerEnabled ) {
116118 GDlogger .gDad .showBanner (args );
117119 adBannerTimer = null ;
118- if (!GDstatic .testAds ){
120+ if (!GDstatic .testAds ) {
119121 setAdTimer (false ); // banner timer
120122 GDstatic .reqBannerEnabled = false ;
121123 }
@@ -132,13 +134,35 @@ protected static void ShowBanner(String args) {
132134 if (GDlogger .gDad .devListener != null ) {
133135 GDlogger .gDad .devListener .onBannerFailed ("Banner request failed: 'Midroll is disabled.'" );
134136 }
137+
135138 }
136139
137140 }
138141
139142
140143 }
141144
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+
142166 private static void setAdTimer (final boolean isInterstitial ) {
143167
144168 if (GDstatic .enable ) {
0 commit comments