Skip to content

Commit 77411d3

Browse files
committed
Implement ads wait logic
1 parent fca572c commit 77411d3

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

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

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
public abstract class Activity_Base_Ads_Banner extends org.metatrans.commons.Activity_Base implements IActivityInterstitial, IActivityRewardedVideo {
1515

1616

17-
private static volatile long timestamp_last_interstitial_ad_openning;
17+
private static final int INTERSTITIAL_INTERVAL = 60 * 1000; //1 minute
18+
19+
private static final int REWARD_INTERVAL = 7 * 60 * 1000; //7 minutes
20+
21+
private static volatile long timestamp_last_interstitial_ad_opening;
22+
23+
private static volatile long timestamp_last_rewarded_ad_opening;
1824

1925

2026
private IAdLoadFlow current_adLoadFlow_Banner;
@@ -32,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
3238
super.onCreate(savedInstanceState);
3339

3440
//Skip ads first 1 minute
35-
timestamp_last_interstitial_ad_openning = System.currentTimeMillis();
41+
timestamp_last_interstitial_ad_opening = System.currentTimeMillis();
3642
}
3743

3844

@@ -49,18 +55,26 @@ protected void onResume() {
4955
//try-catch ensures no errors, because of ads logic.
5056
try {
5157

52-
attachBanner();
58+
if (showAds()) {
59+
60+
attachBanner();
61+
}
5362

5463
preloadInterstitial();
5564

5665
preloadRewardedVideo();
5766

58-
} catch(Throwable t) {
67+
} catch (Throwable t) {
5968

6069
t.printStackTrace();
6170
}
6271
}
6372

73+
private boolean showAds() {
74+
75+
return System.currentTimeMillis() >= timestamp_last_rewarded_ad_opening + REWARD_INTERVAL;
76+
}
77+
6478

6579
@Override
6680
protected void onPause() {
@@ -197,6 +211,11 @@ public boolean openInterstitial() {
197211

198212
System.out.println("Activity_Base_Ads_Banner.openInterstitial(): called");
199213

214+
if (!showAds()) {
215+
216+
System.out.println("Activity_Base_Ads_Banner.openInterstitial(): !showAds()");
217+
}
218+
200219
try {
201220

202221
if (Application_Base.getInstance().getApp_Me().isPaid()) {
@@ -211,7 +230,7 @@ public boolean openInterstitial() {
211230

212231
long now = System.currentTimeMillis();
213232

214-
if (now >= timestamp_last_interstitial_ad_openning + 60 * 1000) {
233+
if (now >= timestamp_last_interstitial_ad_opening + INTERSTITIAL_INTERVAL) {
215234

216235
if (current_adLoadFlow_Interstitial != null) {
217236

@@ -222,7 +241,7 @@ public boolean openInterstitial() {
222241
success = true;
223242
}
224243

225-
timestamp_last_interstitial_ad_openning = now;
244+
timestamp_last_interstitial_ad_opening = now;
226245

227246
} else {
228247

@@ -282,6 +301,11 @@ public boolean openRewardedVideo() {
282301

283302
System.out.println("Activity_Base_Ads_Banner.openRewardedVideo(): called");
284303

304+
if (!showAds()) {
305+
306+
System.out.println("Activity_Base_Ads_Banner.openRewardedVideo(): !showAds()");
307+
}
308+
285309
try {
286310

287311
if (Application_Base.getInstance().getApp_Me().isPaid()) {
@@ -295,6 +319,8 @@ public boolean openRewardedVideo() {
295319

296320
current_adLoadFlow_RewardedVideo.resume();
297321

322+
timestamp_last_rewarded_ad_opening = System.currentTimeMillis();
323+
298324
System.out.println("Activity_Base_Ads_Banner.openRewardedVideo(): RESUMED");
299325

300326
return true;

0 commit comments

Comments
 (0)