Add Mentions Megaphone.
parent
f732e54c22
commit
676356e800
|
@ -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 {
|
||||
|
|
|
@ -52,6 +52,7 @@ public class MegaphoneRepository {
|
|||
executor.execute(() -> {
|
||||
database.markFinished(Event.REACTIONS);
|
||||
database.markFinished(Event.MESSAGE_REQUESTS);
|
||||
database.markFinished(Event.MENTIONS);
|
||||
resetDatabaseCache();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue