Skip to content

Commit

Permalink
Add profile names megaphone.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal authored and greyson-signal committed Feb 14, 2020
1 parent c041614 commit 3ea1492
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
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:
Expand All @@ -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) {
Expand Down Expand Up @@ -80,8 +88,9 @@ private 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());
}};
}
Expand All @@ -94,6 +103,8 @@ private static Map<Event, MegaphoneSchedule> buildDisplayOrder() {
return buildPinsForAllMegaphone(record);
case PIN_REMINDER:
return buildPinReminderMegaphone(context);
case PROFILE_NAMES_FOR_ALL:
return buildProfileNamesMegaphone(context);
default:
throw new IllegalArgumentException("Event not handled!");
}
Expand Down Expand Up @@ -121,8 +132,6 @@ private static Map<Event, MegaphoneSchedule> buildDisplayOrder() {
.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 {
Expand Down Expand Up @@ -185,10 +194,34 @@ public void onReminderCompleted(boolean includedFailure) {
.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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class EditProfileActivity extends BaseActionBarActivity implements EditPr
public static final String EXCLUDE_SYSTEM = "exclude_system";
public static final String DISPLAY_USERNAME = "display_username";
public static final String NEXT_BUTTON_TEXT = "next_button_text";
public static final String SHOW_TOOLBAR = "show_back_arrow";
public static final String SHOW_TOOLBAR = "show_back_arrow";

private final DynamicTheme dynamicTheme = new DynamicRegistrationTheme();
private final DynamicTheme dynamicTheme = new DynamicRegistrationTheme();

@Override
public void onCreate(Bundle bundle) {
Expand All @@ -32,8 +32,10 @@ public void onCreate(Bundle bundle) {
setContentView(R.layout.profile_create_activity);

if (bundle == null) {
NavGraph graph = Navigation.findNavController(this, R.id.nav_host_fragment).getGraph();
Navigation.findNavController(this, R.id.nav_host_fragment).setGraph(graph, getIntent().getExtras());
Bundle extras = getIntent().getExtras();
NavGraph graph = Navigation.findNavController(this, R.id.nav_host_fragment).getGraph();

Navigation.findNavController(this, R.id.nav_host_fragment).setGraph(graph, extras != null ? extras : new Bundle());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.avatar.AvatarSelection;
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.lock.v2.PinUtil;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.megaphone.Megaphones;
import org.thoughtcrime.securesms.mms.GlideApp;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints;
Expand Down Expand Up @@ -328,6 +330,8 @@ private void handleUpload() {
SignalStore.registrationValues().setRegistrationComplete();
}

ApplicationDependencies.getMegaphoneRepository().markFinished(Megaphones.Event.PROFILE_NAMES_FOR_ALL);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) handleFinishedLollipop();
else handleFinishedLegacy();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ public final class FeatureFlags {
private static final String PREFIX = "android.";
private static final long FETCH_INTERVAL = TimeUnit.HOURS.toMillis(2);

private static final String UUIDS = generateKey("uuids");
private static final String PROFILE_DISPLAY = generateKey("profileDisplay");
private static final String MESSAGE_REQUESTS = generateKey("messageRequests");
private static final String USERNAMES = generateKey("usernames");
private static final String STORAGE_SERVICE = generateKey("storageService");
private static final String PINS_FOR_ALL = generateKey("pinsForAll");
private static final String PINS_MEGAPHONE_KILL_SWITCH = generateKey("pinsMegaphoneKillSwitch");
private static final String UUIDS = generateKey("uuids");
private static final String PROFILE_DISPLAY = generateKey("profileDisplay");
private static final String MESSAGE_REQUESTS = generateKey("messageRequests");
private static final String USERNAMES = generateKey("usernames");
private static final String STORAGE_SERVICE = generateKey("storageService");
private static final String PINS_FOR_ALL = generateKey("pinsForAll");
private static final String PINS_MEGAPHONE_KILL_SWITCH = generateKey("pinsMegaphoneKillSwitch");
private static final String PROFILE_NAMES_MEGAPHONE_ENABLED = generateKey("profileNamesMegaphoneEnabled");

/**
* We will only store remote values for flags in this set. If you want a flag to be controllable
Expand All @@ -61,7 +62,8 @@ public final class FeatureFlags {

private static final Set<String> REMOTE_CAPABLE = Sets.newHashSet(
PINS_FOR_ALL,
PINS_MEGAPHONE_KILL_SWITCH
PINS_MEGAPHONE_KILL_SWITCH,
PROFILE_NAMES_MEGAPHONE_ENABLED
);

/**
Expand Down Expand Up @@ -166,6 +168,12 @@ public static boolean pinsForAllMegaphoneKillSwitch() {
return getValue(PINS_MEGAPHONE_KILL_SWITCH, false);
}

/** Safety switch for disabling profile names megaphone */
public static boolean profileNamesMegaphoneEnabled() {
return getValue(PROFILE_NAMES_MEGAPHONE_ENABLED, false) &&
TextSecurePreferences.getFirstInstallVersion(ApplicationDependencies.getApplication()) < 600;
}

/** Only for rendering debug info. */
public static synchronized @NonNull Map<String, Boolean> getMemoryValues() {
return new TreeMap<>(REMOTE_VALUES);
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,14 @@
<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>

<!-- Profile Names Megaphone -->
<string name="ProfileNamesMegaphone__add_a_profile_name">Add a profile name</string>
<string name="ProfileNamesMegaphone__this_will_be_displayed_when_you_start">This will be displayed when you start a new conversation or share it.</string>
<string name="ProfileNamesMegaphone__add_profile_name">Add Profile Name</string>
<string name="ProfileNamesMegaphone__confirm_your_profile_name">Confirm your Profile Name</string>
<string name="ProfileNamesMegaphone__your_profile_can_now_include">Your profile can now include an optional last name.</string>
<string name="ProfileNamesMegaphone__confirm_name">Confirm Name</string>

<!-- transport_selection_list_item -->
<string name="transport_selection_list_item__transport_icon">Transport icon</string>
<string name="ConversationListFragment_loading">Loading…</string>
Expand Down

0 comments on commit 3ea1492

Please sign in to comment.