mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 03:11:10 +01:00
Add profile names megaphone.
This commit is contained in:
committed by
Greyson Parrelli
parent
c041614d1f
commit
3ea1492d67
@@ -19,12 +19,16 @@ import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
|
||||
import org.thoughtcrime.securesms.lock.v2.KbsMigrationActivity;
|
||||
import org.thoughtcrime.securesms.lock.v2.PinUtil;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||
import org.thoughtcrime.securesms.profiles.edit.EditProfileActivity;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
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:
|
||||
@@ -43,6 +47,10 @@ 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);
|
||||
private static final MegaphoneSchedule EVERY_TWO_DAYS = new RecurringSchedule(TimeUnit.DAYS.toMillis(2));
|
||||
|
||||
private Megaphones() {}
|
||||
|
||||
static @Nullable Megaphone getNextMegaphone(@NonNull Context context, @NonNull Map<Event, MegaphoneRecord> records) {
|
||||
@@ -80,8 +88,9 @@ public final class Megaphones {
|
||||
*/
|
||||
private static Map<Event, MegaphoneSchedule> buildDisplayOrder() {
|
||||
return new LinkedHashMap<Event, MegaphoneSchedule>() {{
|
||||
put(Event.REACTIONS, new ForeverSchedule(true));
|
||||
put(Event.REACTIONS, ALWAYS);
|
||||
put(Event.PINS_FOR_ALL, new PinsForAllSchedule());
|
||||
put(Event.PROFILE_NAMES_FOR_ALL, FeatureFlags.profileNamesMegaphoneEnabled() ? EVERY_TWO_DAYS : NEVER);
|
||||
put(Event.PIN_REMINDER, new SignalPinReminderSchedule());
|
||||
}};
|
||||
}
|
||||
@@ -94,6 +103,8 @@ public final class Megaphones {
|
||||
return buildPinsForAllMegaphone(record);
|
||||
case PIN_REMINDER:
|
||||
return buildPinReminderMegaphone(context);
|
||||
case PROFILE_NAMES_FOR_ALL:
|
||||
return buildProfileNamesMegaphone(context);
|
||||
default:
|
||||
throw new IllegalArgumentException("Event not handled!");
|
||||
}
|
||||
@@ -121,8 +132,6 @@ public final class Megaphones {
|
||||
.setMandatory(true)
|
||||
.setImage(R.drawable.kbs_pin_megaphone);
|
||||
|
||||
long daysRemaining = PinsForAllSchedule.getDaysRemaining(record.getFirstVisible(), System.currentTimeMillis());
|
||||
|
||||
if (PinUtil.userHasPin(ApplicationDependencies.getApplication())) {
|
||||
return buildPinsForAllMegaphoneForUserWithPin(builder.enableSnooze(null));
|
||||
} else {
|
||||
@@ -185,10 +194,34 @@ public final class Megaphones {
|
||||
.build();
|
||||
}
|
||||
|
||||
private static @NonNull Megaphone buildProfileNamesMegaphone(@NonNull Context context) {
|
||||
Megaphone.Builder builder = new Megaphone.Builder(Event.PROFILE_NAMES_FOR_ALL, Megaphone.Style.BASIC)
|
||||
.enableSnooze(null)
|
||||
.setImage(R.drawable.profile_megaphone);
|
||||
|
||||
Megaphone.EventListener eventListener = (megaphone, listener) -> {
|
||||
listener.onMegaphoneSnooze(Event.PROFILE_NAMES_FOR_ALL);
|
||||
listener.onMegaphoneNavigationRequested(new Intent(context, EditProfileActivity.class));
|
||||
};
|
||||
|
||||
if (TextSecurePreferences.getProfileName(ApplicationDependencies.getApplication()) == ProfileName.EMPTY) {
|
||||
return builder.setTitle(R.string.ProfileNamesMegaphone__add_a_profile_name)
|
||||
.setBody(R.string.ProfileNamesMegaphone__this_will_be_displayed_when_you_start)
|
||||
.setActionButton(R.string.ProfileNamesMegaphone__add_profile_name, eventListener)
|
||||
.build();
|
||||
} else {
|
||||
return builder.setTitle(R.string.ProfileNamesMegaphone__confirm_your_profile_name)
|
||||
.setBody(R.string.ProfileNamesMegaphone__your_profile_can_now_include)
|
||||
.setActionButton(R.string.ProfileNamesMegaphone__confirm_name, eventListener)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public enum Event {
|
||||
REACTIONS("reactions"),
|
||||
PINS_FOR_ALL("pins_for_all"),
|
||||
PIN_REMINDER("pin_reminder");
|
||||
PIN_REMINDER("pin_reminder"),
|
||||
PROFILE_NAMES_FOR_ALL("profile_names");
|
||||
|
||||
private final String key;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user