Skip to content

Commit 7c31714

Browse files
committed
Pause flow only when it is active and resume it only when it is not active
1 parent c8b9c4b commit 7c31714

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

app/src/main/java/org/metatrans/commons/Activity_Base_Ads_Banner.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
public abstract class Activity_Base_Ads_Banner extends org.metatrans.commons.Activity_Base implements IActivityInterstitial, IActivityRewardedVideo {
1818

1919

20-
private static final int INTERSTITIAL_INTERVAL = DEBUG ? 5 * 1000 : 60 * 1000; //1 minute if productive
20+
//1 minute if productive mode and smaller for testing
21+
private static final int INTERSTITIAL_INTERVAL = (DEBUG ? (5 * 1000) : (60 * 1000));
2122

22-
private static final int REWARD_INTERVAL = 7 * 60 * 1000; //7 minutes
23+
private static final int REWARD_INTERVAL = 7 * INTERSTITIAL_INTERVAL;
2324

2425
private static final int WAITING_TIME_FOR_REWARDED_AD = (int) (3.5 * 1000); //3.5 seconds
2526

@@ -161,9 +162,16 @@ protected void attachBanner() {
161162

162163
if (current_adLoadFlow_Banner != null) {
163164

164-
System.out.println("Activity_Base_Ads_Banner: attachBanner() - resume add");
165+
if (!current_adLoadFlow_Banner.isActive()) {
165166

166-
current_adLoadFlow_Banner.resume();
167+
System.out.println("Activity_Base_Ads_Banner: attachBanner(): resume add");
168+
169+
current_adLoadFlow_Banner.resume();
170+
171+
} else {
172+
173+
System.out.println("Activity_Base_Ads_Banner: attachBanner(): skipping, because Banner is ALREADY active");
174+
}
167175

168176
isBannerAttached = true;
169177
}
@@ -175,7 +183,10 @@ protected void detachBanner() {
175183

176184
if (current_adLoadFlow_Banner != null) {
177185

178-
current_adLoadFlow_Banner.pause();
186+
if (current_adLoadFlow_Banner.isActive()) {
187+
188+
current_adLoadFlow_Banner.pause();
189+
}
179190

180191
current_adLoadFlow_Banner = null;
181192
}
@@ -208,7 +219,6 @@ private void preloadInterstitial() {
208219

209220
if (current_adLoadFlow_Interstitial.isActive()) {
210221

211-
//current_adLoadFlow_Interstitial.cleanCurrent();
212222
current_adLoadFlow_Interstitial.pause();
213223
}
214224
}
@@ -237,8 +247,12 @@ public boolean openInterstitial() {
237247
return false;
238248
}
239249

240-
241-
System.out.println("Activity_Base_Ads_Banner.openInterstitial(): INTERSTITIAL_INTERVAL=" + INTERSTITIAL_INTERVAL);
250+
System.out.println("Activity_Base_Ads_Banner.openInterstitial(): timestamp_last_interstitial_ad_opening="
251+
+ timestamp_last_interstitial_ad_opening);
252+
System.out.println("Activity_Base_Ads_Banner.openInterstitial(): readable_time="
253+
+ TimeUtils.getReadableDateTime(timestamp_last_interstitial_ad_opening));
254+
System.out.println("Activity_Base_Ads_Banner.openInterstitial(): INTERSTITIAL_INTERVAL="
255+
+ INTERSTITIAL_INTERVAL);
242256

243257
boolean success = false;
244258

@@ -248,9 +262,16 @@ public boolean openInterstitial() {
248262

249263
if (current_adLoadFlow_Interstitial != null) {
250264

251-
current_adLoadFlow_Interstitial.resume();
265+
if (!current_adLoadFlow_Interstitial.isActive()) {
252266

253-
System.out.println("Activity_Base_Ads_Banner.openInterstitial(): RESUMED");
267+
System.out.println("Activity_Base_Ads_Banner.openInterstitial(): RESUMED");
268+
269+
current_adLoadFlow_Interstitial.resume();
270+
271+
} else {
272+
273+
System.out.println("Activity_Base_Ads_Banner: openInterstitial(): skipping, because Interstitial is ALREADY active");
274+
}
254275

255276
success = true;
256277
}
@@ -298,7 +319,6 @@ private void preloadRewardedVideo() {
298319

299320
if (current_adLoadFlow_RewardedVideo.isActive()) {
300321

301-
//current_adLoadFlow_RewardedVideo.cleanCurrent();
302322
current_adLoadFlow_RewardedVideo.pause();
303323

304324
} else {
@@ -343,9 +363,16 @@ public boolean openRewardedVideo() {
343363

344364
if (current_adLoadFlow_RewardedVideo != null) {
345365

346-
current_adLoadFlow_RewardedVideo.resume();
366+
if (!current_adLoadFlow_RewardedVideo.isActive()) {
367+
368+
System.out.println("Activity_Base_Ads_Banner.openRewardedVideo(): RESUMED");
347369

348-
System.out.println("Activity_Base_Ads_Banner.openRewardedVideo(): RESUMED");
370+
current_adLoadFlow_RewardedVideo.resume();
371+
372+
} else {
373+
374+
System.out.println("Activity_Base_Ads_Banner: openRewardedVideo(): skipping, because RewardedVideo is ALREADY active");
375+
}
349376

350377
return true;
351378

0 commit comments

Comments
 (0)