mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 16:49:40 +01:00
Add a donate megaphone for Q2 2022.
This commit is contained in:
committed by
Alex Hart
parent
12e6ebb4df
commit
92a506e4da
@@ -64,7 +64,7 @@ public final class Megaphones {
|
||||
private static final MegaphoneSchedule ALWAYS = new ForeverSchedule(true);
|
||||
private static final MegaphoneSchedule NEVER = new ForeverSchedule(false);
|
||||
|
||||
private static final Set<Event> DONATE_EVENTS = SetUtil.newHashSet(Event.BECOME_A_SUSTAINER);
|
||||
private static final Set<Event> DONATE_EVENTS = SetUtil.newHashSet(Event.BECOME_A_SUSTAINER, Event.DONATE_Q2_2022);
|
||||
private static final long MIN_TIME_BETWEEN_DONATE_MEGAPHONES = TimeUnit.DAYS.toMillis(30);
|
||||
|
||||
private Megaphones() {}
|
||||
@@ -105,7 +105,7 @@ public final class Megaphones {
|
||||
put(Event.NOTIFICATIONS, shouldShowNotificationsMegaphone(context) ? RecurringSchedule.every(TimeUnit.DAYS.toMillis(30)) : NEVER);
|
||||
put(Event.ONBOARDING, shouldShowOnboardingMegaphone(context) ? ALWAYS : NEVER);
|
||||
put(Event.TURN_OFF_CENSORSHIP_CIRCUMVENTION, shouldShowTurnOffCircumventionMegaphone() ? RecurringSchedule.every(TimeUnit.DAYS.toMillis(7)) : NEVER);
|
||||
put(Event.BECOME_A_SUSTAINER, shouldShowDonateMegaphone(context, records) ? ShowForDurationSchedule.showForDays(7) : NEVER);
|
||||
put(Event.DONATE_Q2_2022, shouldShowDonateMegaphone(context, Event.DONATE_Q2_2022, records) ? ShowForDurationSchedule.showForDays(7) : NEVER);
|
||||
put(Event.PIN_REMINDER, new SignalPinReminderSchedule());
|
||||
|
||||
// Feature-introduction megaphones should *probably* be added below this divider
|
||||
@@ -129,6 +129,8 @@ public final class Megaphones {
|
||||
return buildAddAProfilePhotoMegaphone(context);
|
||||
case BECOME_A_SUSTAINER:
|
||||
return buildBecomeASustainerMegaphone(context);
|
||||
case DONATE_Q2_2022:
|
||||
return buildDonateQ2Megaphone(context);
|
||||
case TURN_OFF_CENSORSHIP_CIRCUMVENTION:
|
||||
return buildTurnOffCircumventionMegaphone(context);
|
||||
default:
|
||||
@@ -260,6 +262,21 @@ public final class Megaphones {
|
||||
.build();
|
||||
}
|
||||
|
||||
private static @NonNull Megaphone buildDonateQ2Megaphone(@NonNull Context context) {
|
||||
return new Megaphone.Builder(Event.DONATE_Q2_2022, Megaphone.Style.BASIC)
|
||||
.setTitle(R.string.Donate2022Q2Megaphone_donate_to_signal)
|
||||
.setImage(R.drawable.ic_donate_q2_2022)
|
||||
.setBody(R.string.Donate2022Q2Megaphone_signal_is_powered_by_people_like_you)
|
||||
.setActionButton(R.string.Donate2022Q2Megaphone_donate, (megaphone, listener) -> {
|
||||
listener.onMegaphoneNavigationRequested(AppSettingsActivity.subscriptions(context));
|
||||
listener.onMegaphoneCompleted(Event.DONATE_Q2_2022);
|
||||
})
|
||||
.setSecondaryButton(R.string.Donate2022Q2Megaphone_not_now, (megaphone, listener) -> {
|
||||
listener.onMegaphoneCompleted(Event.DONATE_Q2_2022);
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
private static @NonNull Megaphone buildTurnOffCircumventionMegaphone(@NonNull Context context) {
|
||||
return new Megaphone.Builder(Event.TURN_OFF_CENSORSHIP_CIRCUMVENTION, Megaphone.Style.BASIC)
|
||||
.setTitle(R.string.CensorshipCircumventionMegaphone_turn_off_censorship_circumvention)
|
||||
@@ -275,8 +292,8 @@ public final class Megaphones {
|
||||
.build();
|
||||
}
|
||||
|
||||
private static boolean shouldShowDonateMegaphone(@NonNull Context context, @NonNull Map<Event, MegaphoneRecord> records) {
|
||||
long timeSinceLastDonatePrompt = timeSinceLastDonatePrompt(records);
|
||||
private static boolean shouldShowDonateMegaphone(@NonNull Context context, @NonNull Event event, @NonNull Map<Event, MegaphoneRecord> records) {
|
||||
long timeSinceLastDonatePrompt = timeSinceLastDonatePrompt(event, records);
|
||||
|
||||
return timeSinceLastDonatePrompt > MIN_TIME_BETWEEN_DONATE_MEGAPHONES &&
|
||||
VersionTracker.getDaysSinceFirstInstalled(context) >= 7 &&
|
||||
@@ -336,10 +353,11 @@ public final class Megaphones {
|
||||
* Unfortunately lastSeen is only set today upon snoozing, which never happens to donate prompts.
|
||||
* So we use firstVisible as a proxy.
|
||||
*/
|
||||
private static long timeSinceLastDonatePrompt(@NonNull Map<Event, MegaphoneRecord> records) {
|
||||
private static long timeSinceLastDonatePrompt(@NonNull Event excludeEvent, @NonNull Map<Event, MegaphoneRecord> records) {
|
||||
long lastSeenDonatePrompt = records.entrySet()
|
||||
.stream()
|
||||
.filter(e -> DONATE_EVENTS.contains(e.getKey()))
|
||||
.filter(e -> !e.getKey().equals(excludeEvent))
|
||||
.map(e -> e.getValue().getFirstVisible())
|
||||
.filter(t -> t > 0)
|
||||
.sorted()
|
||||
@@ -357,7 +375,7 @@ public final class Megaphones {
|
||||
NOTIFICATIONS("notifications"),
|
||||
ADD_A_PROFILE_PHOTO("add_a_profile_photo"),
|
||||
BECOME_A_SUSTAINER("become_a_sustainer"),
|
||||
VALENTINES_DONATIONS_2022("valentines_donations_2022"),
|
||||
DONATE_Q2_2022("donate_q2_2022"),
|
||||
TURN_OFF_CENSORSHIP_CIRCUMVENTION("turn_off_censorship_circumvention");
|
||||
|
||||
private final String key;
|
||||
|
||||
Reference in New Issue
Block a user