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 6dad0eb121..9768c6e274 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java +++ b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java @@ -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 DONATE_EVENTS = SetUtil.newHashSet(Event.BECOME_A_SUSTAINER); + private static final Set 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 records) { - long timeSinceLastDonatePrompt = timeSinceLastDonatePrompt(records); + private static boolean shouldShowDonateMegaphone(@NonNull Context context, @NonNull Event event, @NonNull Map 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 records) { + private static long timeSinceLastDonatePrompt(@NonNull Event excludeEvent, @NonNull Map 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; diff --git a/app/src/main/res/drawable/ic_donate_q2_2022.xml b/app/src/main/res/drawable/ic_donate_q2_2022.xml new file mode 100644 index 0000000000..0d1a853a0c --- /dev/null +++ b/app/src/main/res/drawable/ic_donate_q2_2022.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a91f99c05f..456ece0e87 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3890,6 +3890,15 @@ Top edge selector Bottom edge selector + + Donate to Signal + + Signal is powered by people like you. Donate monthly and receive a badge. + + Donate + + Not now + Customize reactions Tap to replace an emoji