From a8d9933265165de94716254736064b264ffb8c0a Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Thu, 6 Jan 2022 16:58:47 -0500 Subject: [PATCH] Simplify megaphone priority. (#2063) --- .../securesms/megaphone/Megaphone.java | 40 ++----------------- .../securesms/megaphone/Megaphones.java | 18 ++++----- 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphone.java b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphone.java index 2eeabd949..027dabe1b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphone.java +++ b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphone.java @@ -9,9 +9,7 @@ import androidx.annotation.Nullable; import androidx.annotation.RawRes; import androidx.annotation.StringRes; -import org.thoughtcrime.securesms.dependencies.ApplicationDependencies; import org.thoughtcrime.securesms.megaphone.Megaphones.Event; -import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.mms.GlideRequest; /** @@ -21,7 +19,6 @@ public class Megaphone { private final Event event; private final Style style; - private final Priority priority; private final boolean canSnooze; private final int titleRes; private final int bodyRes; @@ -38,7 +35,6 @@ public class Megaphone { private Megaphone(@NonNull Builder builder) { this.event = builder.event; this.style = builder.style; - this.priority = builder.priority; this.canSnooze = builder.canSnooze; this.titleRes = builder.titleRes; this.bodyRes = builder.bodyRes; @@ -57,10 +53,6 @@ public class Megaphone { return event; } - public @NonNull Priority getPriority() { - return priority; - } - public boolean canSnooze() { return canSnooze; } @@ -123,10 +115,9 @@ public class Megaphone { public static class Builder { - private final Event event; - private final Style style; + private final Event event; + private final Style style; - private Priority priority; private boolean canSnooze; private int titleRes; private int bodyRes; @@ -142,17 +133,8 @@ public class Megaphone { public Builder(@NonNull Event event, @NonNull Style style) { - this.event = event; - this.style = style; - this.priority = Priority.DEFAULT; - } - - /** - * Prioritizes this megaphone over others that do not set this flag. - */ - public @NonNull Builder setPriority(@NonNull Priority priority) { - this.priority = priority; - return this; + this.event = event; + this.style = style; } public @NonNull Builder enableSnooze(@Nullable EventListener listener) { @@ -235,20 +217,6 @@ public class Megaphone { POPUP } - enum Priority { - DEFAULT(0), HIGH(1), CLIENT_EXPIRATION(1000); - - int priorityValue; - - Priority(int priorityValue) { - this.priorityValue = priorityValue; - } - - public int getPriorityValue() { - return priorityValue; - } - } - public interface EventListener { void onEvent(@NonNull Megaphone megaphone, @NonNull MegaphoneActionController listener); } 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 3d3d7c3de..dee644fee 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java +++ b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java @@ -80,7 +80,6 @@ public final class Megaphones { .map(Map.Entry::getKey) .map(records::get) .map(record -> Megaphones.forRecord(context, record)) - .sortBy(m -> -m.getPriority().getPriorityValue()) .toList(); if (megaphones.size() > 0) { @@ -91,19 +90,23 @@ public final class Megaphones { } /** - * This is when you would hide certain megaphones based on {@link FeatureFlags}. You could - * conditionally set a {@link ForeverSchedule} set to false for disabled features. + * The megaphones we want to display *in priority order*. This is a {@link LinkedHashMap}, so order is preserved. + * We will render the first applicable megaphone in this collection. + * + * This is also when you would hide certain megaphones based on things like {@link FeatureFlags}. */ private static Map buildDisplayOrder(@NonNull Context context) { return new LinkedHashMap() {{ put(Event.PINS_FOR_ALL, new PinsForAllSchedule()); + put(Event.NOTIFICATIONS, shouldShowNotificationsMegaphone(context) ? RecurringSchedule.every(TimeUnit.DAYS.toMillis(30)) : NEVER); + put(Event.BECOME_A_SUSTAINER, shouldShowDonateMegaphone(context) ? ShowForDurationSchedule.showForDays(7) : NEVER); put(Event.PIN_REMINDER, new SignalPinReminderSchedule()); put(Event.CLIENT_DEPRECATED, SignalStore.misc().isClientDeprecated() ? ALWAYS : NEVER); put(Event.ONBOARDING, shouldShowOnboardingMegaphone(context) ? ALWAYS : NEVER); - put(Event.NOTIFICATIONS, shouldShowNotificationsMegaphone(context) ? RecurringSchedule.every(TimeUnit.DAYS.toMillis(30)) : NEVER); + + // Feature-introduction megaphones should *probably* be added below this divider put(Event.CHAT_COLORS, ALWAYS); put(Event.ADD_A_PROFILE_PHOTO, shouldShowAddAProfilePhotoMegaphone(context) ? ALWAYS : NEVER); - put(Event.BECOME_A_SUSTAINER, shouldShowDonateMegaphone(context) ? ShowForDurationSchedule.showForDays(7) : NEVER); put(Event.NOTIFICATION_PROFILES, ShowForDurationSchedule.showForDays(7)); }}; } @@ -136,7 +139,6 @@ public final class Megaphones { private static @NonNull Megaphone buildPinsForAllMegaphone(@NonNull MegaphoneRecord record) { if (PinsForAllSchedule.shouldDisplayFullScreen(record.getFirstVisible(), System.currentTimeMillis())) { return new Megaphone.Builder(Event.PINS_FOR_ALL, Megaphone.Style.FULLSCREEN) - .setPriority(Megaphone.Priority.HIGH) .enableSnooze(null) .setOnVisibleListener((megaphone, listener) -> { if (new NetworkConstraint.Factory(ApplicationDependencies.getApplication()).create().isMet()) { @@ -146,7 +148,6 @@ public final class Megaphones { .build(); } else { return new Megaphone.Builder(Event.PINS_FOR_ALL, Megaphone.Style.BASIC) - .setPriority(Megaphone.Priority.HIGH) .setImage(R.drawable.kbs_pin_megaphone) .setTitle(R.string.KbsMegaphone__create_a_pin) .setBody(R.string.KbsMegaphone__pins_keep_information_thats_stored_with_signal_encrytped) @@ -195,14 +196,12 @@ public final class Megaphones { private static @NonNull Megaphone buildClientDeprecatedMegaphone(@NonNull Context context) { return new Megaphone.Builder(Event.CLIENT_DEPRECATED, Megaphone.Style.FULLSCREEN) .disableSnooze() - .setPriority(Megaphone.Priority.HIGH) .setOnVisibleListener((megaphone, listener) -> listener.onMegaphoneNavigationRequested(new Intent(context, ClientDeprecatedActivity.class))) .build(); } private static @NonNull Megaphone buildOnboardingMegaphone() { return new Megaphone.Builder(Event.ONBOARDING, Megaphone.Style.ONBOARDING) - .setPriority(Megaphone.Priority.DEFAULT) .build(); } @@ -228,7 +227,6 @@ public final class Megaphones { } }) .setSecondaryButton(R.string.NotificationsMegaphone_not_now, (megaphone, controller) -> controller.onMegaphoneSnooze(Event.NOTIFICATIONS)) - .setPriority(Megaphone.Priority.DEFAULT) .build(); }