Skip to content

Commit

Permalink
Merge pull request #11 from Kiarasht/5.14
Browse files Browse the repository at this point in the history
UPM consent
  • Loading branch information
Kiarasht authored Dec 8, 2023
2 parents b360fe1 + 675e9ff commit 6bda057
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 76 deletions.
22 changes: 11 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'

android {
packagingOptions {
Expand All @@ -20,8 +21,8 @@ android {
applicationId "com.restart.spacestationtracker"
minSdkVersion 19
targetSdkVersion 34
versionCode 36
versionName "5.13"
versionCode 37
versionName "5.14"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
multiDexEnabled true
}
Expand All @@ -41,32 +42,31 @@ dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview:1.3.1'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.android.material:material:1.10.0'
implementation "androidx.coordinatorlayout:coordinatorlayout:1.2.0"
implementation 'androidx.work:work-runtime:2.8.1'
implementation 'androidx.work:work-runtime:2.9.0'

implementation platform('com.google.firebase:firebase-bom:28.4.2')

implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.google.firebase:firebase-ads:22.4.0'
implementation 'com.google.firebase:firebase-ads:22.6.0'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.android.gms:play-services-maps:18.2.0'
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.google.firebase:firebase-analytics'

implementation 'com.nightonke:boommenu:2.1.1'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.github.wooplr:Spotlight:1.2.3'
implementation 'androidx.browser:browser:1.6.0'
implementation 'androidx.browser:browser:1.7.0'
implementation 'com.github.bumptech.glide:glide:4.16.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.airbnb.android:lottie:6.1.0'
implementation 'com.google.android.ump:user-messaging-platform:2.1.0'

androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
}

apply plugin: 'com.google.gms.google-services'
}
24 changes: 7 additions & 17 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
{
"project_info": {
"project_number": "199927822810",
"project_id": "iss-tracker-3c17a",
"storage_bucket": "iss-tracker-3c17a.appspot.com"
"project_number": "689771934258",
"project_id": "titanium-gadget-112205",
"storage_bucket": "titanium-gadget-112205.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:199927822810:android:37f1c0bef15b7c93e568e3",
"mobilesdk_app_id": "1:689771934258:android:5940bdea7ae875001a022b",
"android_client_info": {
"package_name": "com.restart.spacestationtracker"
}
},
"oauth_client": [
{
"client_id": "199927822810-uqhc0m4o5jin8n8lmsvgqi4pgdulqql9.apps.googleusercontent.com",
"client_type": 3
}
],
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyACiaZ5RL3bYP6sY_SL0hRqXijRZyPTOBc"
"current_key": "AIzaSyAtpWPhzhbtqTgofnQhAHjiG12MmrY2AAE"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "199927822810-uqhc0m4o5jin8n8lmsvgqi4pgdulqql9.apps.googleusercontent.com",
"client_type": 3
}
]
"other_platform_oauth_client": []
}
}
}
Expand Down
136 changes: 93 additions & 43 deletions app/src/main/java/com/restart/spacestationtracker/MapsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.google.ads.mediation.admob.AdMobAdapter;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.FullScreenContentCallback;
Expand All @@ -52,7 +53,10 @@
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import com.google.firebase.crash.FirebaseCrash;
import com.google.android.ump.ConsentForm;
import com.google.android.ump.ConsentInformation;
import com.google.android.ump.ConsentRequestParameters;
import com.google.android.ump.UserMessagingPlatform;
import com.nightonke.boommenu.BoomButtons.ButtonPlaceEnum;
import com.nightonke.boommenu.BoomButtons.HamButton;
import com.nightonke.boommenu.BoomMenuButton;
Expand All @@ -66,6 +70,7 @@
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Contains the google map and uses volley to grab JSON objects and display
Expand All @@ -76,6 +81,8 @@ public class MapsActivity extends AppCompatActivity implements OnMapReadyCallbac
public static final String CHANNEL_ID = "iss_notification"; // Notification for Android 8.0 and higher
private static final String TAG = ".MapsActivity"; // Used for volley and occasional Log

private final AtomicBoolean isMobileAdsInitializeCalled = new AtomicBoolean(false);
private ConsentInformation consentInformation; // Need privacy consent before showing ads
private SharedPreferences mSharedPreferences; // Managing options from Settings
private BoomMenuButton mBoomMenu; // Manages the drawer pop menu
private InterstitialAd mInterstitialAd; // Managing interstitial ads with AdMob sdk
Expand Down Expand Up @@ -118,8 +125,47 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_maps);
initializeVariables();
initiateBoomMenu();
initializeAds();
//initializeNotificationChannel();

if (!mSharedPreferences.getBoolean(getString(R.string.firstTime), true)) {
initializeConsent();
if (consentInformation.canRequestAds()) {
initializeAds();
}
}
}

private void initializeConsent() {
ConsentRequestParameters params = new ConsentRequestParameters.Builder()
.setTagForUnderAgeOfConsent(false)
.build();

consentInformation = UserMessagingPlatform.getConsentInformation(this);
consentInformation.requestConsentInfoUpdate(
this,
params,
(ConsentInformation.OnConsentInfoUpdateSuccessListener) () -> {
UserMessagingPlatform.loadAndShowConsentFormIfRequired(
this,
(ConsentForm.OnConsentFormDismissedListener) loadAndShowError -> {
if (loadAndShowError != null) {
// Consent gathering failed.
// TODO: Report
}

if (consentInformation.canRequestAds()) {
initializeAds();
}
}
);
},
(ConsentInformation.OnConsentInfoUpdateFailureListener) requestConsentError -> {
// Consent gathering failed.
// TODO: Report
});

if (consentInformation.canRequestAds()) {
initializeAds();
}
}

/**
Expand Down Expand Up @@ -191,9 +237,12 @@ private void initializeVariables() {
* Initialize ads when the activity is started for the first time
*/
private void initializeAds() {
if (isMobileAdsInitializeCalled.getAndSet(true)) {
return;
}

List<String> testDevices = new ArrayList<>();
testDevices.add("9D8A446B53611FCE04214236159EB750");
testDevices.add("54686107F6B785A3B1575E1F6E4BD613");
//testDevices.add("54686107F6B785A3B1575E1F6E4BD613");
MobileAds.setRequestConfiguration(new RequestConfiguration.Builder()
.setTestDeviceIds(testDevices)
.build());
Expand Down Expand Up @@ -241,7 +290,9 @@ public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
});

mAdView = findViewById(R.id.adView);
mAdView.loadAd(new AdRequest.Builder().build());
Bundle extras = new Bundle();
extras.putString("collapsible", "bottom");
mAdView.loadAd(new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build());
}

/**
Expand Down Expand Up @@ -285,9 +336,6 @@ public void run() {
mTimer = new Timer();
}

mAdView = findViewById(R.id.adView);
mAdView.loadAd(new AdRequest.Builder().build());

// Update the color and size of polylines if they are different in settings than what they are right now
mCurrentColor = Color.YELLOW;
mCurrentWidth = 5;
Expand Down Expand Up @@ -623,7 +671,7 @@ private void updatePolyline(Date currentDate) {
});
} catch (Exception e) {
if (mLast == null) {
FirebaseCrash.report(new Exception("mLast was null"));
// TODO: Report crash
}
e.printStackTrace();
}
Expand Down Expand Up @@ -763,7 +811,7 @@ private void getLocationPermission() {
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (mInterstitialAd != null && !mSharedPreferences.getBoolean("fullPage", false)) {
if (mInterstitialAd != null) {
mInterstitialAd.show(MapsActivity.this);
mInterstitialAdActivity = 0;
} else {
Expand Down Expand Up @@ -834,7 +882,8 @@ private void startAnimation(final View mTitleTextView, final Activity activity)
.lineAnimDuration(400)
.lineAndArcColor(Color.parseColor("#6441A5"))
.dismissOnTouch(true)
.usageId("2").show()).show();
.usageId("2")
.setListener(s1 -> initializeConsent()).show()).show();
}

/**
Expand Down Expand Up @@ -879,40 +928,41 @@ private void onISS() {
* Request for a new interstitial ad
*/
private void requestNewInterstitial() {
if (!mSharedPreferences.getBoolean("fullPage", false)) {
// Initiate the interstitial ad and onAdClosed listener
InterstitialAd.load(this, getString(R.string.interstitial_ad_unit_id), new AdRequest.Builder().build(),
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
mInterstitialAd = interstitialAd;
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
@Override
public void onAdDismissedFullScreenContent() {
requestNewInterstitial();
switch (mInterstitialAdActivity) {
case 0:
startActivity(new Intent(mContext, Locations.class));
break;
case 1:
startActivity(new Intent(mContext, PeopleInSpace.class));
break;
}
}
if (consentInformation == null || !consentInformation.canRequestAds()) {
return;
}

@Override
public void onAdShowedFullScreenContent() {
mInterstitialAd = null;
// Initiate the interstitial ad and onAdClosed listener
InterstitialAd.load(this, getString(R.string.interstitial_ad_unit_id), new AdRequest.Builder().build(),
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
mInterstitialAd = interstitialAd;
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
@Override
public void onAdDismissedFullScreenContent() {
switch (mInterstitialAdActivity) {
case 0:
startActivity(new Intent(mContext, Locations.class));
break;
case 1:
startActivity(new Intent(mContext, PeopleInSpace.class));
break;
}
});
}
}

@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
mInterstitialAd = null;
}
});
}
@Override
public void onAdShowedFullScreenContent() {
mInterstitialAd = null;
}
});
}

@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
mInterstitialAd = null;
}
});
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/strings_do_not_translate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<resources>
<!-- String that are not translatable -->
<!-- Admob -->
<string name="app_ID_Main" translatable="false">ca-app-pub-1850763013639682~7037607031</string>
<string name="banner_ad_unit_id" translatable="false">ca-app-pub-1850763013639682/8514340237</string>
<string name="interstitial_ad_unit_id" translatable="false">ca-app-pub-1850763013639682/7680127834</string>
<string name="app_ID_Main" translatable="false">ca-app-pub-1850763013639682~8939815838</string>
<string name="banner_ad_unit_id" translatable="false">ca-app-pub-1850763013639682/4298913050</string>
<string name="interstitial_ad_unit_id" translatable="false">ca-app-pub-1850763013639682/1377236244</string>

<!-- Shared Pref -->
<string name="firstTime" translatable="false">firstTime</string>
Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.7.20'

repositories {
//noinspection JcenterRepositoryObsolete
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath 'com.android.tools.build:gradle:8.2.0'
classpath 'com.google.gms:google-services:4.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.4.0'
}
}

allprojects {
repositories {
//noinspection JcenterRepositoryObsolete
jcenter()
maven { url "https://jitpack.io" }
google()
Expand Down

0 comments on commit 6bda057

Please sign in to comment.