Add Mentions Megaphone.

This commit is contained in:
Cody Henthorne 2020-08-13 11:45:33 -04:00 committed by Greyson Parrelli
parent f732e54c22
commit 676356e800
5 changed files with 102 additions and 12 deletions

View File

@ -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<Drawable> 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 {

View File

@ -52,6 +52,7 @@ public class MegaphoneRepository {
executor.execute(() -> {
database.markFinished(Event.REACTIONS);
database.markFinished(Event.MESSAGE_REQUESTS);
database.markFinished(Event.MENTIONS);
resetDatabaseCache();
});
}

View File

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

View File

@ -0,0 +1,53 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="64dp"
android:height="64dp"
android:viewportWidth="64"
android:viewportHeight="64">
<path
android:pathData="M32,0L32,0A32,32 0,0 1,64 32L64,32A32,32 0,0 1,32 64L32,64A32,32 0,0 1,0 32L0,32A32,32 0,0 1,32 0z"
android:fillColor="#5951C8"/>
<path
android:pathData="M32,32m-32,0a32,32 0,1 1,64 0a32,32 0,1 1,-64 0"
android:fillColor="#067589"/>
<path
android:pathData="M43.6667,30.6933C43.6667,35.2783 41.6367,38.335 38.2767,38.335C37.5411,38.3932 36.8095,38.1812 36.219,37.7388C35.6284,37.2964 35.2193,36.6539 35.0684,35.9317H34.9517C34.6613,36.6472 34.1568,37.2555 33.5072,37.6732C32.8577,38.0909 32.0949,38.2976 31.3234,38.265C28.3367,38.265 26.33,35.815 26.33,32.175C26.33,28.535 28.3834,26.1667 31.3234,26.1667C32.0384,26.1347 32.7477,26.3077 33.3678,26.6652C33.9879,27.0228 34.4929,27.5501 34.8234,28.185H34.94V26.47H37.0984V34.8817C37.0777,35.0982 37.1058,35.3166 37.1806,35.5209C37.2553,35.7252 37.3748,35.9102 37.5302,36.0623C37.6857,36.2144 37.8733,36.3299 38.0791,36.4001C38.285,36.4704 38.504,36.4937 38.72,36.4683C40.4234,36.4683 41.6834,34.38 41.6834,30.635C41.6834,25.4317 37.7284,21.92 32.0234,21.92C26.3184,21.92 22.3634,26.1667 22.3634,32.1867C22.3634,38.6733 26.6917,42.2433 32.455,42.2433C34.0813,42.2959 35.7042,42.063 37.25,41.555V43.3633C35.6884,43.8559 34.0573,44.0923 32.42,44.0633C25.4317,44.0633 20.3334,39.805 20.3334,32.105C20.3334,25 25.21,20.1583 32.175,20.1583C38.8367,20.1583 43.6667,24.3817 43.6667,30.6933ZM28.6284,32.175C28.6284,34.66 29.795,36.1883 31.65,36.1883C33.505,36.1883 34.87,34.625 34.87,32.175C34.87,29.725 33.6217,28.1733 31.6734,28.1733C29.725,28.1733 28.6284,29.6667 28.6284,32.175Z"
android:fillColor="#E9E9E9"
tools:ignore="VectorPath" />
<path
android:pathData="M54.4691,19.025L54.4691,19.025A1,1 90.3486,0 1,54.1031 20.3911L48.966,23.357A1,1 53.6434,0 1,47.5999 22.9909L47.5999,22.9909A1,1 53.6434,0 1,47.966 21.6249L53.1031,18.659A1,1 90.3486,0 1,54.4691 19.025z"
android:fillColor="#2398AD"/>
<path
android:pathData="M54.0201,31.991L54.0201,31.991A1,1 0,0 1,53.0201 32.991L51.0114,32.991A1,1 0,0 1,50.0114 31.991L50.0114,31.991A1,1 0,0 1,51.0114 30.991L53.0201,30.991A1,1 0,0 1,54.0201 31.991z"
android:fillColor="#2398AD"/>
<path
android:pathData="M43.0115,51.0435L43.0115,51.0435A1,1 103.2825,0 1,41.6454 50.6775L40.6454,48.9454A1,1 71.6588,0 1,41.0115 47.5794L41.0115,47.5794A1,1 71.6588,0 1,42.3775 47.9454L43.3775,49.6775A1,1 103.2825,0 1,43.0115 51.0435z"
android:fillColor="#2398AD"/>
<path
android:pathData="M32.0115,57.991L32.0115,57.991A1,1 0,0 1,31.0115 56.991L31.0115,50.991A1,1 0,0 1,32.0115 49.991L32.0115,49.991A1,1 0,0 1,33.0115 50.991L33.0115,56.991A1,1 0,0 1,32.0115 57.991z"
android:fillColor="#2398AD"/>
<path
android:pathData="M16.423,40.991L16.423,40.991A1,1 72.6269,0 1,16.057 42.3571L10.9031,45.3326A1,1 83.3671,0 1,9.5371 44.9666L9.5371,44.9666A1,1 83.3671,0 1,9.9031 43.6006L15.057,40.625A1,1 72.6269,0 1,16.423 40.991z"
android:fillColor="#2398AD"/>
<path
android:pathData="M14.0115,31.991L14.0115,31.991A1,1 0,0 1,13.0115 32.991L11.0912,32.991A1,1 0,0 1,10.0912 31.991L10.0912,31.991A1,1 0,0 1,11.0912 30.991L13.0115,30.991A1,1 0,0 1,14.0115 31.991z"
android:fillColor="#2398AD"/>
<path
android:pathData="M23.0115,16.4025L23.0115,16.4025A1,1 108.0537,0 1,21.6455 16.0365L20.6455,14.3044A1,1 118.2876,0 1,21.0115 12.9384L21.0115,12.9384A1,1 118.2876,0 1,22.3775 13.3044L23.3775,15.0365A1,1 108.0537,0 1,23.0115 16.4025z"
android:fillColor="#2398AD"/>
<path
android:pathData="M43.0114,12.9384L43.0114,12.9384A1,1 107.496,0 1,43.3775 14.3044L42.3775,16.0365A1,1 74.6968,0 1,41.0114 16.4025L41.0114,16.4025A1,1 74.6968,0 1,40.6454 15.0365L41.6454,13.3044A1,1 107.496,0 1,43.0114 12.9384z"
android:fillColor="#2398AD"/>
<path
android:pathData="M54.5241,44.9887L54.5241,44.9887A1,1 63.9079,0 1,53.1581 45.3548L47.9659,42.3571A1,1 63.9079,0 1,47.5999 40.991L47.5999,40.991A1,1 63.9079,0 1,48.9659 40.625L54.1581,43.6227A1,1 63.9079,0 1,54.5241 44.9887z"
android:fillColor="#2398AD"/>
<path
android:pathData="M23.0114,47.5795L23.0114,47.5795A1,1 74.9657,0 1,23.3774 48.9455L22.3774,50.6776A1,1 86.2546,0 1,21.0114 51.0436L21.0114,51.0436A1,1 86.2546,0 1,20.6454 49.6776L21.6454,47.9455A1,1 74.9657,0 1,23.0114 47.5795z"
android:fillColor="#2398AD"/>
<path
android:pathData="M16.423,22.991L16.423,22.991A1,1 119.4729,0 1,15.057 23.357L9.8946,20.3765A1,1 122.0668,0 1,9.5285 19.0105L9.5285,19.0105A1,1 122.0668,0 1,10.8946 18.6445L16.057,21.625A1,1 119.4729,0 1,16.423 22.991z"
android:fillColor="#2398AD"/>
<path
android:pathData="M32.0115,13.991L32.0115,13.991A1,1 0,0 1,31.0115 12.991L31.0115,6.991A1,1 0,0 1,32.0115 5.991L32.0115,5.991A1,1 0,0 1,33.0115 6.991L33.0115,12.991A1,1 0,0 1,32.0115 13.991z"
android:fillColor="#2398AD"/>
</vector>

View File

@ -2324,6 +2324,10 @@
<string name="KbsMegaphone__well_remind_you_later_creating_a_pin">We\'ll remind you later. Creating a PIN will become mandatory in %1$d days.</string>
<string name="KbsMegaphone__well_remind_you_later_confirming_your_pin">We\'ll remind you later. Confirming your PIN will become mandatory in %1$d days.</string>
<!-- Mention Megaphone -->
<string name="MentionsMegaphone__introducing_mentions">Introducing @Mentions</string>
<string name="MentionsMegaphone__get_someones_attention_in_a_group_by_typing">Get someone\'s attention in a \"New Group\" by typing @</string>
<!-- transport_selection_list_item -->
<string name="transport_selection_list_item__transport_icon">Transport icon</string>
<string name="ConversationListFragment_loading">Loading…</string>