Skip to content

Commit

Permalink
Track app launch count and only show the donations UI after it reaches 3
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbrethorst committed Mar 30, 2024
1 parent dcb29ad commit cf499e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())) {
Expand Down

0 comments on commit cf499e3

Please sign in to comment.