mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-26 05:17:56 +00:00
Don't show donate or research megaphones on new app installs.
This commit is contained in:
@@ -12,6 +12,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.thoughtcrime.securesms.util.VersionTracker;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ public class RatingManager {
|
|||||||
public static void showRatingDialogIfNecessary(Context context) {
|
public static void showRatingDialogIfNecessary(Context context) {
|
||||||
if (!TextSecurePreferences.isRatingEnabled(context)) return;
|
if (!TextSecurePreferences.isRatingEnabled(context)) return;
|
||||||
|
|
||||||
long daysSinceInstall = getDaysSinceInstalled(context);
|
long daysSinceInstall = VersionTracker.getDaysSinceFirstInstalled(context);
|
||||||
long laterTimestamp = TextSecurePreferences.getRatingLaterTimestamp(context);
|
long laterTimestamp = TextSecurePreferences.getRatingLaterTimestamp(context);
|
||||||
|
|
||||||
if (daysSinceInstall >= DAYS_SINCE_INSTALL_THRESHOLD &&
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.util.CommunicationActions;
|
|||||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||||
import org.thoughtcrime.securesms.util.PopulationFeatureFlags;
|
import org.thoughtcrime.securesms.util.PopulationFeatureFlags;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.thoughtcrime.securesms.util.VersionTracker;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -89,8 +90,8 @@ public final class Megaphones {
|
|||||||
put(Event.MESSAGE_REQUESTS, shouldShowMessageRequestsMegaphone() ? ALWAYS : NEVER);
|
put(Event.MESSAGE_REQUESTS, shouldShowMessageRequestsMegaphone() ? ALWAYS : NEVER);
|
||||||
put(Event.LINK_PREVIEWS, shouldShowLinkPreviewsMegaphone(context) ? ALWAYS : NEVER);
|
put(Event.LINK_PREVIEWS, shouldShowLinkPreviewsMegaphone(context) ? ALWAYS : NEVER);
|
||||||
put(Event.CLIENT_DEPRECATED, SignalStore.misc().isClientDeprecated() ? ALWAYS : NEVER);
|
put(Event.CLIENT_DEPRECATED, SignalStore.misc().isClientDeprecated() ? ALWAYS : NEVER);
|
||||||
put(Event.RESEARCH, shouldShowResearchMegaphone() ? ShowForDurationSchedule.showForDays(7) : NEVER);
|
put(Event.RESEARCH, shouldShowResearchMegaphone(context) ? ShowForDurationSchedule.showForDays(7) : NEVER);
|
||||||
put(Event.DONATE, shouldShowDonateMegaphone() ? 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;
|
return Recipient.self().getProfileName() == ProfileName.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldShowResearchMegaphone() {
|
private static boolean shouldShowResearchMegaphone(@NonNull Context context) {
|
||||||
return PopulationFeatureFlags.isInResearchMegaphone();
|
return VersionTracker.getDaysSinceFirstInstalled(context) > 7 && PopulationFeatureFlags.isInResearchMegaphone();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldShowDonateMegaphone() {
|
private static boolean shouldShowDonateMegaphone(@NonNull Context context) {
|
||||||
return PopulationFeatureFlags.isInDonateMegaphone();
|
return VersionTracker.getDaysSinceFirstInstalled(context) > 7 && PopulationFeatureFlags.isInDonateMegaphone();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldShowLinkPreviewsMegaphone(@NonNull Context context) {
|
private static boolean shouldShowLinkPreviewsMegaphone(@NonNull Context context) {
|
||||||
|
@@ -1,12 +1,15 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class VersionTracker {
|
public class VersionTracker {
|
||||||
|
|
||||||
@@ -30,4 +33,17 @@ public class VersionTracker {
|
|||||||
throw new AssertionError(ioe);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user