Skip to content

Commit 66c69bc

Browse files
committed
Preload ad stream is running on bacground in order to keep it an ad ready.
1 parent 2b3e8c7 commit 66c69bc

File tree

4 files changed

+36
-50
lines changed

4 files changed

+36
-50
lines changed

Source/GDApi/gdapi/libs/gdapi.jar

-23.1 KB
Binary file not shown.

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDad.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void onAdFailedToLoad(int errorCode) {
152152
if (devListener != null && GDstatic.testAds){
153153
devListener.onBannerFailed(error);
154154
}
155-
else if(devListener != null && gdRequestAdHandler != null)
155+
else if(!GDstatic.testAds && gdRequestAdHandler != null)
156156
gdRequestAdHandler.Error(error);
157157

158158
}
@@ -238,7 +238,7 @@ public void onAdFailedToLoad(int errorCode) {
238238
if (devListener != null && GDstatic.testAds){
239239
devListener.onBannerFailed(error);
240240
}
241-
else if(devListener != null && gdRequestAdHandler != null)
241+
else if(!GDstatic.testAds && gdRequestAdHandler != null)
242242
gdRequestAdHandler.Error(error);
243243

244244
}

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDbanner.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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,16 +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);
36+
GDlogger.gDad.init(GDlogger.mContext, GDlogger.isCordovaPlugin);
3737

3838
GDlogger.gdPreloadStream.setPreloadStream(true);
39-
GDlogger.gdPreloadStream.init(GDlogger.mContext,GDlogger.isCordovaPlugin);
40-
}
41-
else{
39+
GDlogger.gdPreloadStream.init(GDlogger.mContext, GDlogger.isCordovaPlugin);
40+
} else {
4241
String error = "Something went wrong fetching game data.";
4342
GDutils.log(error);
4443

45-
if(GDlogger.gDad.devListener != null)
44+
if (GDlogger.gDad.devListener != null)
4645
GDlogger.gDad.devListener.onAPINotReady(error);
4746
GDstatic.enable = false;
4847

@@ -51,7 +50,7 @@ public void onSuccess(JSONObject data) {
5150
} catch (JSONException e) {
5251
e.printStackTrace();
5352
GDutils.log("Something went wrong parsing json game data.");
54-
if(GDlogger.gDad.devListener != null)
53+
if (GDlogger.gDad.devListener != null)
5554
GDlogger.gDad.devListener.onAPINotReady("Something went wrong parsing json game data.");
5655
GDstatic.enable = false;
5756

@@ -61,15 +60,14 @@ public void onSuccess(JSONObject data) {
6160
@Override
6261
public void onError(VolleyError error) {
6362
GDutils.log("Something went wrong fetching json game data.");
64-
if(GDlogger.gDad.devListener != null)
63+
if (GDlogger.gDad.devListener != null)
6564
GDlogger.gDad.devListener.onAPINotReady("Something went wrong fetching json game data.");
6665
GDstatic.enable = false;
6766

6867
}
6968
});
70-
}
71-
else if(GDstatic.testAds){
72-
GDlogger.gDad.init(GDlogger.mContext,GDlogger.isCordovaPlugin);
69+
} else if (GDstatic.testAds) {
70+
GDlogger.gDad.init(GDlogger.mContext, GDlogger.isCordovaPlugin);
7371
GDlogger.gdPreloadStream.setPreloadStream(true);
7472
GDlogger.gdPreloadStream.init(GDlogger.mContext, GDlogger.isCordovaPlugin);
7573
}
@@ -81,11 +79,12 @@ protected static void ShowBanner(String args) {
8179
final GDshowObj gDshowObj;
8280
gDshowObj = gson.fromJson(args, GDshowObj.class);
8381

84-
8582
if ((GDGameData.enableAds || GDstatic.testAds) && gDshowObj._key != null && gDshowObj._key.equals("preroll") && GDlogger.gDad != null) {
8683

8784
if (GDGameData.preRoll) {
88-
GDlogger.gDad.showBanner(args);
85+
86+
ShowPreloadedBanner(args);
87+
8988
} else {
9089
if (GDlogger.gDad.devListener != null) {
9190
GDlogger.gDad.devListener.onBannerFailed("Banner request failed: 'Preroll is disabled.'");
@@ -98,14 +97,13 @@ protected static void ShowBanner(String args) {
9897
if (gDshowObj.isInterstitial) {
9998
if (GDstatic.reqInterstitialEnabled) {
10099

101-
GDlogger.gDad.showBanner(args);
100+
ShowPreloadedBanner(args);
102101
adInterstitialTimer = null;
103102

104-
if(!GDstatic.testAds){
103+
if (!GDstatic.testAds) {
105104
setAdTimer(true); // inter timer
106105
GDstatic.reqInterstitialEnabled = false;
107-
}
108-
else{
106+
} else {
109107
GDstatic.reqInterstitialEnabled = true;
110108
}
111109

@@ -115,12 +113,11 @@ protected static void ShowBanner(String args) {
115113
GDlogger.gDad.devListener.onBannerFailed("You can not invoke 'ShowBanner()' within " + GDGameData.timeAds + " min(s).");
116114
}
117115
}
118-
}
119-
else {
116+
} else {
120117
if (GDstatic.reqBannerEnabled) {
121118
GDlogger.gDad.showBanner(args);
122119
adBannerTimer = null;
123-
if(!GDstatic.testAds){
120+
if (!GDstatic.testAds) {
124121
setAdTimer(false); // banner timer
125122
GDstatic.reqBannerEnabled = false;
126123
}
@@ -137,27 +134,32 @@ protected static void ShowBanner(String args) {
137134
if (GDlogger.gDad.devListener != null) {
138135
GDlogger.gDad.devListener.onBannerFailed("Banner request failed: 'Midroll is disabled.'");
139136
}
137+
140138
}
141139

142140
}
143141

144142

145143
}
146144

147-
protected static void ShowPreloadedBanner(){
148-
149-
if(GDlogger.gdPreloadStream.isPreloadedAdExist())
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()){
150149
GDlogger.gdPreloadStream.showInterstitialAd();
151-
else if(!GDlogger.gdPreloadStream.isPreloadedAdLoading()){
152-
if(GDlogger.gDad.devListener != null){
153-
GDlogger.gDad.devListener.onPreloadFailed("No ads found preloaded.");
154-
}
155-
GDlogger.gdPreloadStream.requestPreloadAd();
156150
}
157151
else{
158-
if(GDlogger.gDad.devListener != null){
159-
GDlogger.gDad.devListener.onPreloadFailed("A preload ad is currently being loaded.");
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+
}
160161
}
162+
GDlogger.gDad.showBanner(args);
161163
}
162164
}
163165

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDlogger.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public static void ShowBanner(String size, String alignment, String position) {
9797
}
9898

9999
public static void ShowBanner(Boolean isInterstitial) {
100-
101100
if(GDutils.isOnline(mContext)){
102101
String args = "{isInterstitial:" + isInterstitial + "}";
103102
if (GDstatic.enable) {
@@ -110,21 +109,6 @@ public static void ShowBanner(Boolean isInterstitial) {
110109
if(GDlogger.gDad.devListener != null)
111110
GDlogger.gDad.devListener.onBannerFailed("API cannot connect to internet. Please check the network connection.");
112111
}
113-
114-
}
115-
116-
public static void ShowPreloadedAd(){
117-
if(GDutils.isOnline(mContext)){
118-
if (GDstatic.enable) {
119-
GDbanner.ShowPreloadedBanner();
120-
} else {
121-
Log.i("GDLogger", "GDApi is not initialized!");
122-
}
123-
}
124-
else{
125-
if(GDlogger.gDad.devListener != null)
126-
GDlogger.gDad.devListener.onPreloadFailed("API cannot connect to internet. Please check the network connection.");
127-
}
128112
}
129113

130114
public static void setAdListener(GDadListener gDadListener) {

0 commit comments

Comments
 (0)