Add a donate megaphone for Q2 2022.

fork-5.53.8
Greyson Parrelli 2022-05-11 14:24:18 -04:00 zatwierdzone przez Alex Hart
rodzic 12e6ebb4df
commit 92a506e4da
3 zmienionych plików z 54 dodań i 6 usunięć

Wyświetl plik

@ -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;

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -3890,6 +3890,15 @@
<string name="ChatColorGradientTool_top_edge_selector">Top edge selector</string>
<string name="ChatColorGradientTool_bottom_edge_selector">Bottom edge selector</string>
<!-- Title text for prompt to donate. Shown in a popup at the bottom of the chat list. -->
<string name="Donate2022Q2Megaphone_donate_to_signal">Donate to Signal</string>
<!-- Body text for prompt to donate. Shown in a popup at the bottom of the chat list. -->
<string name="Donate2022Q2Megaphone_signal_is_powered_by_people_like_you">Signal is powered by people like you. Donate monthly and receive a badge.</string>
<!-- Button label that brings a user to the donate screen. Shown in a popup at the bottom of the chat list. -->
<string name="Donate2022Q2Megaphone_donate">Donate</string>
<!-- Button label that dismissed a prompt to donate. Shown in a popup at the bottom of the chat list. -->
<string name="Donate2022Q2Megaphone_not_now">Not now</string>
<!-- EditReactionsFragment -->
<string name="EditReactionsFragment__customize_reactions">Customize reactions</string>
<string name="EditReactionsFragment__tap_to_replace_an_emoji">Tap to replace an emoji</string>