Skip to content

Commit 83d4391

Browse files
committed
Update to v6.68
1 parent 4e7bcf8 commit 83d4391

File tree

7 files changed

+150
-44
lines changed

7 files changed

+150
-44
lines changed

AnLinux/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
minSdkVersion 21
77
targetSdkVersion 35
88
compileSdk 35
9-
versionCode 667
10-
versionName "6.67 Stable"
9+
versionCode 668
10+
versionName "6.68 Stable"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {

AnLinux/app/release/app-release.apk

1.74 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

AnLinux/app/release/output-metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"type": "SINGLE",
1212
"filters": [],
1313
"attributes": [],
14-
"versionCode": 667,
15-
"versionName": "6.67 Stable",
14+
"versionCode": 668,
15+
"versionName": "6.68 Stable",
1616
"outputFile": "app-release.apk"
1717
}
1818
],
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package exa.lnx.a;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.util.Log;
6+
7+
import androidx.annotation.NonNull;
8+
9+
import com.google.android.gms.ads.AdError;
10+
import com.google.android.gms.ads.AdRequest;
11+
import com.google.android.gms.ads.FullScreenContentCallback;
12+
import com.google.android.gms.ads.LoadAdError;
13+
import com.google.android.gms.ads.appopen.AppOpenAd;
14+
15+
import java.util.Date;
16+
17+
public class AppOpenAdManager {
18+
private static final String LOG_TAG = "AppOpenAdManager";
19+
private static final String AD_UNIT_ID = "ca-app-pub-5748356089815497/7922138881";
20+
21+
private AppOpenAd appOpenAd = null;
22+
private boolean isLoadingAd = false;
23+
private boolean isShowingAd = false;
24+
25+
private long loadTime = 0;
26+
27+
/** Constructor. */
28+
public AppOpenAdManager() {}
29+
30+
public interface OnShowAdCompleteListener {
31+
void onShowAdComplete();
32+
}
33+
34+
/** Request an ad. */
35+
public void loadAd(Context context) {
36+
// Do not load ad if there is an unused ad or one is already loading.
37+
if (isLoadingAd || isAdAvailable()) {
38+
return;
39+
}
40+
41+
isLoadingAd = true;
42+
AdRequest request = new AdRequest.Builder().build();
43+
AppOpenAd.load(
44+
context, AD_UNIT_ID, request,
45+
AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT,
46+
new AppOpenAd.AppOpenAdLoadCallback() {
47+
@Override
48+
public void onAdLoaded(AppOpenAd ad) {
49+
// Called when an app open ad has loaded.
50+
Log.d(LOG_TAG, "Ad was loaded.");
51+
appOpenAd = ad;
52+
isLoadingAd = false;
53+
loadTime = (new Date()).getTime();
54+
}
55+
56+
@Override
57+
public void onAdFailedToLoad(LoadAdError loadAdError) {
58+
// Called when an app open ad has failed to load.
59+
Log.d(LOG_TAG, loadAdError.getMessage());
60+
isLoadingAd = false;
61+
}
62+
});
63+
}
64+
/** Check if ad exists and can be shown. */
65+
private boolean wasLoadTimeLessThanNHoursAgo(long numHours) {
66+
long dateDifference = (new Date()).getTime() - this.loadTime;
67+
long numMilliSecondsPerHour = 3600000;
68+
return (dateDifference < (numMilliSecondsPerHour * numHours));
69+
}
70+
private boolean isAdAvailable() {
71+
return appOpenAd != null && wasLoadTimeLessThanNHoursAgo(4);
72+
}
73+
public void showAdIfAvailable(
74+
@NonNull final Activity activity,
75+
@NonNull OnShowAdCompleteListener onShowAdCompleteListener){
76+
// If the app open ad is already showing, do not show the ad again.
77+
if (isShowingAd) {
78+
Log.d(LOG_TAG, "The app open ad is already showing.");
79+
return;
80+
}
81+
82+
// If the app open ad is not available yet, invoke the callback then load the ad.
83+
if (!isAdAvailable()) {
84+
Log.d(LOG_TAG, "The app open ad is not ready yet.");
85+
onShowAdCompleteListener.onShowAdComplete();
86+
loadAd(activity);
87+
return;
88+
}
89+
90+
appOpenAd.setFullScreenContentCallback(
91+
new FullScreenContentCallback() {
92+
93+
@Override
94+
public void onAdDismissedFullScreenContent() {
95+
// Called when fullscreen content is dismissed.
96+
// Set the reference to null so isAdAvailable() returns false.
97+
Log.d(LOG_TAG, "Ad dismissed fullscreen content.");
98+
appOpenAd = null;
99+
isShowingAd = false;
100+
101+
onShowAdCompleteListener.onShowAdComplete();
102+
loadAd(activity);
103+
}
104+
105+
@Override
106+
public void onAdFailedToShowFullScreenContent(AdError adError) {
107+
// Called when fullscreen content failed to show.
108+
// Set the reference to null so isAdAvailable() returns false.
109+
Log.d(LOG_TAG, adError.getMessage());
110+
appOpenAd = null;
111+
isShowingAd = false;
112+
113+
onShowAdCompleteListener.onShowAdComplete();
114+
loadAd(activity);
115+
}
116+
117+
@Override
118+
public void onAdShowedFullScreenContent() {
119+
// Called when fullscreen content is shown.
120+
Log.d(LOG_TAG, "Ad showed fullscreen content.");
121+
}
122+
});
123+
isShowingAd = true;
124+
appOpenAd.show(activity);
125+
}
126+
}

AnLinux/app/src/main/java/exa/lnx/a/MainUI.java

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.google.android.gms.ads.FullScreenContentCallback;
4545
import com.google.android.gms.ads.MobileAds;
4646
import com.google.android.gms.ads.OnUserEarnedRewardListener;
47+
import com.google.android.gms.ads.appopen.AppOpenAd;
4748
import com.google.android.gms.ads.initialization.InitializationStatus;
4849
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
4950
import com.google.android.gms.ads.interstitial.InterstitialAd;
@@ -72,13 +73,15 @@ public class MainUI extends AppCompatActivity implements NavigationView.OnNaviga
7273
private long lastPressedTime;
7374
private static final int PERIOD = 3000;
7475
private RewardedAd rewardedAd;
76+
AppOpenAdManager appOpenAdManager;
7577
InterstitialAd mInterstitialAd;
7678
AdView mAdView;
7779
FrameLayout frameLayout;
7880
SharedPreferences sharedPreferences;
7981
SharedPreferences.Editor editor;
8082
int i = 0;
8183
boolean shouldShowAds = false;
84+
boolean canShowOpenAds = false;
8285
boolean isOreoNotified;
8386
boolean isFirstBugNotified;
8487

@@ -105,6 +108,7 @@ public void onInitializationComplete(InitializationStatus initializationStatus)
105108

106109
AdSize adSize = getAdSize();
107110
mAdView.setAdSize(adSize);
111+
appOpenAdManager = new AppOpenAdManager();
108112

109113
Toolbar toolbar = findViewById(R.id.toolbar);
110114

@@ -190,6 +194,21 @@ public void onResume() {
190194
if(rewardedAd == null){
191195
loadRewardedAd();
192196
}
197+
if(shouldShowAds){
198+
if(canShowOpenAds){
199+
appOpenAdManager.showAdIfAvailable(MainUI.this, new AppOpenAdManager.OnShowAdCompleteListener() {
200+
@Override
201+
public void onShowAdComplete() {
202+
// Empty because the user will go back to the activity that shows the ad.
203+
}
204+
});
205+
}
206+
}
207+
}
208+
@Override
209+
public void onPause() {
210+
super.onPause();
211+
canShowOpenAds = true;
193212
}
194213
@Override
195214
public boolean onKeyDown(int keyCode, KeyEvent event){
@@ -285,10 +304,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
285304
mInterstitialAd.show(MainUI.this);
286305
}
287306
i = 1;
288-
}else if(i == 1){
289-
i = 2;
290-
}else if(i == 2){
291-
i = 0;
292307
}
293308
newFragment(0);
294309
}
@@ -319,10 +334,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
319334
mInterstitialAd.show(MainUI.this);
320335
}
321336
i = 1;
322-
}else if(i == 1){
323-
i = 2;
324-
}else if(i == 2){
325-
i = 0;
326337
}
327338
newFragment(2);
328339
}
@@ -336,10 +347,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
336347
mInterstitialAd.show(MainUI.this);
337348
}
338349
i = 1;
339-
}else if(i == 1){
340-
i = 2;
341-
}else if(i == 2){
342-
i = 0;
343350
}
344351
newFragment(9);
345352
}
@@ -355,10 +362,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
355362
mInterstitialAd.show(MainUI.this);
356363
}
357364
i = 1;
358-
}else if(i == 1){
359-
i = 2;
360-
}else if(i == 2){
361-
i = 0;
362365
}
363366
newFragment(3);
364367
}
@@ -372,10 +375,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
372375
mInterstitialAd.show(MainUI.this);
373376
}
374377
i = 1;
375-
}else if(i == 1){
376-
i = 2;
377-
}else if(i == 2){
378-
i = 0;
379378
}
380379
newFragment(4);
381380
}
@@ -389,10 +388,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
389388
mInterstitialAd.show(MainUI.this);
390389
}
391390
i = 1;
392-
}else if(i == 1){
393-
i = 2;
394-
}else if(i == 2){
395-
i = 0;
396391
}
397392
newFragment(5);
398393
}
@@ -406,10 +401,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
406401
mInterstitialAd.show(MainUI.this);
407402
}
408403
i = 1;
409-
}else if(i == 1){
410-
i = 2;
411-
}else if(i == 2){
412-
i = 0;
413404
}
414405
newFragment(6);
415406
}
@@ -425,10 +416,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
425416
mInterstitialAd.show(MainUI.this);
426417
}
427418
i = 1;
428-
}else if(i == 1){
429-
i = 2;
430-
}else if(i == 2){
431-
i = 0;
432419
}
433420
newFragment(7);
434421
}
@@ -442,10 +429,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
442429
mInterstitialAd.show(MainUI.this);
443430
}
444431
i = 1;
445-
}else if(i == 1){
446-
i = 2;
447-
}else if(i == 2){
448-
i = 0;
449432
}
450433
newFragment(8);
451434
}
@@ -459,10 +442,6 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
459442
mInterstitialAd.show(MainUI.this);
460443
}
461444
i = 1;
462-
}else if(i == 1){
463-
i = 2;
464-
}else if(i == 2){
465-
i = 0;
466445
}
467446
newFragment(10);
468447
}
@@ -955,6 +934,7 @@ public void onConsentFormLoadFailure(FormError formError) {
955934
}
956935
);
957936
}
937+
958938
//Temporary Code, will be back later if any error in the future
959939
/*public void notifyUserForTemporary(){
960940
final ViewGroup nullParent = null;

0 commit comments

Comments
 (0)