From 676356e800456d075f947c2e65ec3bbd3110f122 Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Thu, 13 Aug 2020 11:45:33 -0400 Subject: [PATCH] Add Mentions Megaphone. --- .../securesms/megaphone/Megaphone.java | 27 ++++++++-- .../megaphone/MegaphoneRepository.java | 1 + .../securesms/megaphone/Megaphones.java | 29 +++++++--- .../main/res/drawable/mention_megaphone.xml | 53 +++++++++++++++++++ app/src/main/res/values/strings.xml | 4 ++ 5 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/drawable/mention_megaphone.xml 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 73dc47b810..cca7e590df 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphone.java +++ b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphone.java @@ -1,6 +1,6 @@ package org.thoughtcrime.securesms.megaphone; -import android.content.Context; +import android.content.Intent; import android.graphics.drawable.Drawable; import androidx.annotation.DrawableRes; @@ -113,6 +113,9 @@ public class Megaphone { this.style = style; } + /** + * Prioritizes this megaphone over others that do not set this flag. + */ public @NonNull Builder setMandatory(boolean mandatory) { this.mandatory = mandatory; return this; @@ -141,8 +144,7 @@ public class Megaphone { } public @NonNull Builder setImage(@DrawableRes int imageRes) { - setImageRequest(GlideApp.with(ApplicationDependencies.getApplication()).load(imageRes)); - return this; + return setImageRequest(GlideApp.with(ApplicationDependencies.getApplication()).load(imageRes)); } public @NonNull Builder setImageRequest(@Nullable GlideRequest imageRequest) { @@ -167,7 +169,24 @@ public class Megaphone { } enum Style { - REACTIONS, BASIC, FULLSCREEN, POPUP + /** Specialized style for announcing reactions. */ + REACTIONS, + + /** Basic bottom of the screen megaphone with optional snooze and action buttons. */ + BASIC, + + /** + * Indicates megaphone does not have a view but will call {@link MegaphoneActionController#onMegaphoneNavigationRequested(Intent)} + * or {@link MegaphoneActionController#onMegaphoneNavigationRequested(Intent, int)} on the controller passed in + * via the {@link #onVisibleListener}. + */ + FULLSCREEN, + + /** + * Similar to {@link Style#BASIC} but only provides a close button that will call {@link #buttonListener} if set, + * otherwise, the event will be marked finished (it will not be shown again). + */ + POPUP } public interface EventListener { diff --git a/app/src/main/java/org/thoughtcrime/securesms/megaphone/MegaphoneRepository.java b/app/src/main/java/org/thoughtcrime/securesms/megaphone/MegaphoneRepository.java index e7bd928b6c..698f57cecb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/megaphone/MegaphoneRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/megaphone/MegaphoneRepository.java @@ -52,6 +52,7 @@ public class MegaphoneRepository { executor.execute(() -> { database.markFinished(Event.REACTIONS); database.markFinished(Event.MESSAGE_REQUESTS); + database.markFinished(Event.MENTIONS); resetDatabaseCache(); }); } 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 b5ad251eb0..3ff569a06b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java +++ b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java @@ -21,16 +21,13 @@ import org.thoughtcrime.securesms.lock.v2.KbsMigrationActivity; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.messagerequests.MessageRequestMegaphoneActivity; import org.thoughtcrime.securesms.profiles.ProfileName; -import org.thoughtcrime.securesms.profiles.edit.EditProfileActivity; import org.thoughtcrime.securesms.recipients.Recipient; -import org.thoughtcrime.securesms.util.AvatarUtil; import org.thoughtcrime.securesms.util.FeatureFlags; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.concurrent.TimeUnit; /** * Creating a new megaphone: @@ -49,10 +46,8 @@ public final class Megaphones { private static final String TAG = Log.tag(Megaphones.class); - private static final MegaphoneSchedule ALWAYS = new ForeverSchedule(true); - private static final MegaphoneSchedule NEVER = new ForeverSchedule(false); - - static final MegaphoneSchedule EVERY_TWO_DAYS = new RecurringSchedule(TimeUnit.DAYS.toMillis(2)); + private static final MegaphoneSchedule ALWAYS = new ForeverSchedule(true); + private static final MegaphoneSchedule NEVER = new ForeverSchedule(false); private Megaphones() {} @@ -95,6 +90,7 @@ public final class Megaphones { put(Event.PINS_FOR_ALL, new PinsForAllSchedule()); put(Event.PIN_REMINDER, new SignalPinReminderSchedule()); put(Event.MESSAGE_REQUESTS, shouldShowMessageRequestsMegaphone() ? ALWAYS : NEVER); + put(Event.MENTIONS, shouldShowMentionsMegaphone() ? ALWAYS : NEVER); }}; } @@ -108,6 +104,8 @@ public final class Megaphones { return buildPinReminderMegaphone(context); case MESSAGE_REQUESTS: return buildMessageRequestsMegaphone(context); + case MENTIONS: + return buildMentionsMegaphone(); default: throw new IllegalArgumentException("Event not handled!"); } @@ -145,6 +143,7 @@ public final class Megaphones { } } + @SuppressWarnings("CodeBlock2Expr") private static @NonNull Megaphone buildPinReminderMegaphone(@NonNull Context context) { return new Megaphone.Builder(Event.PIN_REMINDER, Megaphone.Style.BASIC) .setTitle(R.string.Megaphones_verify_your_signal_pin) @@ -177,6 +176,7 @@ public final class Megaphones { .build(); } + @SuppressWarnings("CodeBlock2Expr") private static @NonNull Megaphone buildMessageRequestsMegaphone(@NonNull Context context) { return new Megaphone.Builder(Event.MESSAGE_REQUESTS, Megaphone.Style.FULLSCREEN) .disableSnooze() @@ -188,15 +188,28 @@ public final class Megaphones { .build(); } + private static Megaphone buildMentionsMegaphone() { + return new Megaphone.Builder(Event.MENTIONS, Megaphone.Style.POPUP) + .setTitle(R.string.MentionsMegaphone__introducing_mentions) + .setBody(R.string.MentionsMegaphone__get_someones_attention_in_a_group_by_typing) + .setImage(R.drawable.mention_megaphone) + .build(); + } + private static boolean shouldShowMessageRequestsMegaphone() { return Recipient.self().getProfileName() == ProfileName.EMPTY; } + private static boolean shouldShowMentionsMegaphone() { + return FeatureFlags.mentions() && FeatureFlags.groupsV2(); + } + public enum Event { REACTIONS("reactions"), PINS_FOR_ALL("pins_for_all"), PIN_REMINDER("pin_reminder"), - MESSAGE_REQUESTS("message_requests"); + MESSAGE_REQUESTS("message_requests"), + MENTIONS("mentions"); private final String key; diff --git a/app/src/main/res/drawable/mention_megaphone.xml b/app/src/main/res/drawable/mention_megaphone.xml new file mode 100644 index 0000000000..6959aded08 --- /dev/null +++ b/app/src/main/res/drawable/mention_megaphone.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index da55a4fd0f..a2d3e414af 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2324,6 +2324,10 @@ We\'ll remind you later. Creating a PIN will become mandatory in %1$d days. We\'ll remind you later. Confirming your PIN will become mandatory in %1$d days. + + Introducing @Mentions + Get someone\'s attention in a \"New Group\" by typing @ + Transport icon Loading…