Add profile names megaphone.

This commit is contained in:
Alex Hart 2020-02-06 17:01:26 -04:00 committed by Greyson Parrelli
parent c041614d1f
commit 3ea1492d67
9 changed files with 71 additions and 16 deletions

View File

@ -19,12 +19,16 @@ import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
import org.thoughtcrime.securesms.lock.v2.KbsMigrationActivity; import org.thoughtcrime.securesms.lock.v2.KbsMigrationActivity;
import org.thoughtcrime.securesms.lock.v2.PinUtil; import org.thoughtcrime.securesms.lock.v2.PinUtil;
import org.thoughtcrime.securesms.logging.Log; 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.FeatureFlags;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit;
/** /**
* Creating a new megaphone: * Creating a new megaphone:
@ -43,6 +47,10 @@ public final class Megaphones {
private static final String TAG = Log.tag(Megaphones.class); 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() {} private Megaphones() {}
static @Nullable Megaphone getNextMegaphone(@NonNull Context context, @NonNull Map<Event, MegaphoneRecord> records) { 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() { private static Map<Event, MegaphoneSchedule> buildDisplayOrder() {
return new LinkedHashMap<Event, MegaphoneSchedule>() {{ return new LinkedHashMap<Event, MegaphoneSchedule>() {{
put(Event.REACTIONS, new ForeverSchedule(true)); put(Event.REACTIONS, ALWAYS);
put(Event.PINS_FOR_ALL, new PinsForAllSchedule()); 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()); put(Event.PIN_REMINDER, new SignalPinReminderSchedule());
}}; }};
} }
@ -94,6 +103,8 @@ public final class Megaphones {
return buildPinsForAllMegaphone(record); return buildPinsForAllMegaphone(record);
case PIN_REMINDER: case PIN_REMINDER:
return buildPinReminderMegaphone(context); return buildPinReminderMegaphone(context);
case PROFILE_NAMES_FOR_ALL:
return buildProfileNamesMegaphone(context);
default: default:
throw new IllegalArgumentException("Event not handled!"); throw new IllegalArgumentException("Event not handled!");
} }
@ -121,8 +132,6 @@ public final class Megaphones {
.setMandatory(true) .setMandatory(true)
.setImage(R.drawable.kbs_pin_megaphone); .setImage(R.drawable.kbs_pin_megaphone);
long daysRemaining = PinsForAllSchedule.getDaysRemaining(record.getFirstVisible(), System.currentTimeMillis());
if (PinUtil.userHasPin(ApplicationDependencies.getApplication())) { if (PinUtil.userHasPin(ApplicationDependencies.getApplication())) {
return buildPinsForAllMegaphoneForUserWithPin(builder.enableSnooze(null)); return buildPinsForAllMegaphoneForUserWithPin(builder.enableSnooze(null));
} else { } else {
@ -185,10 +194,34 @@ public final class Megaphones {
.build(); .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 { public enum Event {
REACTIONS("reactions"), REACTIONS("reactions"),
PINS_FOR_ALL("pins_for_all"), PINS_FOR_ALL("pins_for_all"),
PIN_REMINDER("pin_reminder"); PIN_REMINDER("pin_reminder"),
PROFILE_NAMES_FOR_ALL("profile_names");
private final String key; private final String key;

View File

@ -32,8 +32,10 @@ public class EditProfileActivity extends BaseActionBarActivity implements EditPr
setContentView(R.layout.profile_create_activity); setContentView(R.layout.profile_create_activity);
if (bundle == null) { if (bundle == null) {
Bundle extras = getIntent().getExtras();
NavGraph graph = Navigation.findNavController(this, R.id.nav_host_fragment).getGraph(); NavGraph graph = Navigation.findNavController(this, R.id.nav_host_fragment).getGraph();
Navigation.findNavController(this, R.id.nav_host_fragment).setGraph(graph, getIntent().getExtras());
Navigation.findNavController(this, R.id.nav_host_fragment).setGraph(graph, extras != null ? extras : new Bundle());
} }
} }

View File

@ -35,9 +35,11 @@ import com.dd.CircularProgressButton;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.avatar.AvatarSelection; import org.thoughtcrime.securesms.avatar.AvatarSelection;
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto; import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.keyvalue.SignalStore; import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.lock.v2.PinUtil; import org.thoughtcrime.securesms.lock.v2.PinUtil;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.megaphone.Megaphones;
import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.mms.GlideApp;
import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints; import org.thoughtcrime.securesms.profiles.ProfileMediaConstraints;
@ -328,6 +330,8 @@ public class EditProfileFragment extends Fragment {
SignalStore.registrationValues().setRegistrationComplete(); SignalStore.registrationValues().setRegistrationComplete();
} }
ApplicationDependencies.getMegaphoneRepository().markFinished(Megaphones.Event.PROFILE_NAMES_FOR_ALL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) handleFinishedLollipop(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) handleFinishedLollipop();
else handleFinishedLegacy(); else handleFinishedLegacy();
} else { } else {

View File

@ -53,6 +53,7 @@ public final class FeatureFlags {
private static final String STORAGE_SERVICE = generateKey("storageService"); private static final String STORAGE_SERVICE = generateKey("storageService");
private static final String PINS_FOR_ALL = generateKey("pinsForAll"); private static final String PINS_FOR_ALL = generateKey("pinsForAll");
private static final String PINS_MEGAPHONE_KILL_SWITCH = generateKey("pinsMegaphoneKillSwitch"); 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 * We will only store remote values for flags in this set. If you want a flag to be controllable
@ -61,7 +62,8 @@ public final class FeatureFlags {
private static final Set<String> REMOTE_CAPABLE = Sets.newHashSet( private static final Set<String> REMOTE_CAPABLE = Sets.newHashSet(
PINS_FOR_ALL, PINS_FOR_ALL,
PINS_MEGAPHONE_KILL_SWITCH PINS_MEGAPHONE_KILL_SWITCH,
PROFILE_NAMES_MEGAPHONE_ENABLED
); );
/** /**
@ -166,6 +168,12 @@ public final class FeatureFlags {
return getValue(PINS_MEGAPHONE_KILL_SWITCH, false); 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. */ /** Only for rendering debug info. */
public static synchronized @NonNull Map<String, Boolean> getMemoryValues() { public static synchronized @NonNull Map<String, Boolean> getMemoryValues() {
return new TreeMap<>(REMOTE_VALUES); return new TreeMap<>(REMOTE_VALUES);

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

View File

@ -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_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> <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 --> <!-- transport_selection_list_item -->
<string name="transport_selection_list_item__transport_icon">Transport icon</string> <string name="transport_selection_list_item__transport_icon">Transport icon</string>
<string name="ConversationListFragment_loading">Loading…</string> <string name="ConversationListFragment_loading">Loading…</string>