diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/app/Application.java b/onebusaway-android/src/main/java/org/onebusaway/android/app/Application.java index 79b1b0a07..f912ee399 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/app/Application.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/app/Application.java @@ -112,7 +112,10 @@ public void onCreate() { createNotificationChannels(); TravelBehaviorManager.startCollectingData(getApplicationContext()); - mDonationsManager = new DonationsManager(mPrefs, mFirebaseAnalytics, getResources()); + + incrementAppLaunchCount(); + + mDonationsManager = new DonationsManager(mPrefs, mFirebaseAnalytics, getResources(), getAppLaunchCount()); } /** @@ -139,6 +142,18 @@ public static SharedPreferences getPrefs() { public static DonationsManager getDonationsManager() { return get().mDonationsManager; } + private static String appLaunchCountPreferencesKey = "appLaunchCountPreferencesKey"; + + private void incrementAppLaunchCount() { + int count = PreferenceUtils.getInt(appLaunchCountPreferencesKey, 0); + count += 1; + PreferenceUtils.saveInt(appLaunchCountPreferencesKey, count); + } + + public int getAppLaunchCount() { + return PreferenceUtils.getInt(appLaunchCountPreferencesKey, 0); + } + /** * Returns the last known location that the application has seen, or null if we haven't seen a * location yet. When trying to get a most recent location in one shot, this method should diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/donations/DonationsManager.java b/onebusaway-android/src/main/java/org/onebusaway/android/donations/DonationsManager.java index 89c7d82c6..f3e9cedb1 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/donations/DonationsManager.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/donations/DonationsManager.java @@ -17,13 +17,18 @@ public class DonationsManager { private SharedPreferences mPreferences; - private Resources mResources; + private int mAppLaunchCount; - public DonationsManager(SharedPreferences preferences, FirebaseAnalytics firebaseAnalytics, Resources resources) { + public DonationsManager( + SharedPreferences preferences, + FirebaseAnalytics firebaseAnalytics, + Resources resources, + int appLaunchCount) { this.mPreferences = preferences; this.mAnalytics = firebaseAnalytics; this.mResources = resources; + this.mAppLaunchCount = appLaunchCount; } // region Analytics @@ -127,6 +132,11 @@ public boolean shouldShowDonationUI() { return false; } + // Don't show the donations UI on the first few launches of the app. + if (mAppLaunchCount < 3) { + return false; + } + // Don't show the UI if there's a reminder date that is still in the future. Date reminderDate = getDonationRequestReminderDate(); if (reminderDate != null && reminderDate.after(new Date())) {