diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/RatingManager.java b/app/src/main/java/org/thoughtcrime/securesms/components/RatingManager.java index ec91dab1c..8204803f0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/RatingManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/RatingManager.java @@ -12,6 +12,7 @@ import android.widget.Toast; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.thoughtcrime.securesms.util.VersionTracker; import java.util.concurrent.TimeUnit; @@ -25,7 +26,7 @@ public class RatingManager { public static void showRatingDialogIfNecessary(Context context) { if (!TextSecurePreferences.isRatingEnabled(context)) return; - long daysSinceInstall = getDaysSinceInstalled(context); + long daysSinceInstall = VersionTracker.getDaysSinceFirstInstalled(context); long laterTimestamp = TextSecurePreferences.getRatingLaterTimestamp(context); if (daysSinceInstall >= DAYS_SINCE_INSTALL_THRESHOLD && @@ -72,17 +73,4 @@ public class RatingManager { } } - private static long getDaysSinceInstalled(Context context) { - try { - long installTimestamp = context.getPackageManager() - .getPackageInfo(context.getPackageName(), 0) - .firstInstallTime; - - return TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - installTimestamp); - } catch (PackageManager.NameNotFoundException e) { - Log.w(TAG, e); - return 0; - } - } - } diff --git a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java index 1474b5a7b..dc9a56419 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java +++ b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java @@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.util.CommunicationActions; import org.thoughtcrime.securesms.util.FeatureFlags; import org.thoughtcrime.securesms.util.PopulationFeatureFlags; import org.thoughtcrime.securesms.util.TextSecurePreferences; +import org.thoughtcrime.securesms.util.VersionTracker; import java.util.LinkedHashMap; import java.util.List; @@ -89,8 +90,8 @@ public final class Megaphones { put(Event.MESSAGE_REQUESTS, shouldShowMessageRequestsMegaphone() ? ALWAYS : NEVER); put(Event.LINK_PREVIEWS, shouldShowLinkPreviewsMegaphone(context) ? ALWAYS : NEVER); put(Event.CLIENT_DEPRECATED, SignalStore.misc().isClientDeprecated() ? ALWAYS : NEVER); - put(Event.RESEARCH, shouldShowResearchMegaphone() ? ShowForDurationSchedule.showForDays(7) : NEVER); - put(Event.DONATE, shouldShowDonateMegaphone() ? ShowForDurationSchedule.showForDays(7) : NEVER); + put(Event.RESEARCH, shouldShowResearchMegaphone(context) ? ShowForDurationSchedule.showForDays(7) : NEVER); + put(Event.DONATE, shouldShowDonateMegaphone(context) ? ShowForDurationSchedule.showForDays(7) : NEVER); }}; } @@ -242,12 +243,12 @@ public final class Megaphones { return Recipient.self().getProfileName() == ProfileName.EMPTY; } - private static boolean shouldShowResearchMegaphone() { - return PopulationFeatureFlags.isInResearchMegaphone(); + private static boolean shouldShowResearchMegaphone(@NonNull Context context) { + return VersionTracker.getDaysSinceFirstInstalled(context) > 7 && PopulationFeatureFlags.isInResearchMegaphone(); } - private static boolean shouldShowDonateMegaphone() { - return PopulationFeatureFlags.isInDonateMegaphone(); + private static boolean shouldShowDonateMegaphone(@NonNull Context context) { + return VersionTracker.getDaysSinceFirstInstalled(context) > 7 && PopulationFeatureFlags.isInDonateMegaphone(); } private static boolean shouldShowLinkPreviewsMegaphone(@NonNull Context context) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/VersionTracker.java b/app/src/main/java/org/thoughtcrime/securesms/util/VersionTracker.java index e94710c02..b8f895096 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/VersionTracker.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/VersionTracker.java @@ -1,12 +1,15 @@ package org.thoughtcrime.securesms.util; import android.content.Context; +import android.content.pm.PackageManager; + import androidx.annotation.NonNull; import org.thoughtcrime.securesms.keyvalue.SignalStore; import org.thoughtcrime.securesms.logging.Log; import java.io.IOException; +import java.util.concurrent.TimeUnit; public class VersionTracker { @@ -30,4 +33,17 @@ public class VersionTracker { throw new AssertionError(ioe); } } + + public static long getDaysSinceFirstInstalled(Context context) { + try { + long installTimestamp = context.getPackageManager() + .getPackageInfo(context.getPackageName(), 0) + .firstInstallTime; + + return TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - installTimestamp); + } catch (PackageManager.NameNotFoundException e) { + Log.w(TAG, e); + return 0; + } + } }