diff --git a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java index 9aa1487688..2cdea81343 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java +++ b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java @@ -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 records) { @@ -80,8 +88,9 @@ public final class Megaphones { */ private static Map buildDisplayOrder() { return new LinkedHashMap() {{ - 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; diff --git a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileActivity.java b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileActivity.java index a76b46a7e8..b2398fd3c8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileActivity.java @@ -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) { @@ -32,8 +32,10 @@ public class EditProfileActivity extends BaseActionBarActivity implements EditPr 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()); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileFragment.java b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileFragment.java index 8067527d67..8edec4a81d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/profiles/edit/EditProfileFragment.java @@ -35,9 +35,11 @@ import com.dd.CircularProgressButton; 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; @@ -328,6 +330,8 @@ public class EditProfileFragment extends Fragment { 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 { diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/FeatureFlags.java b/app/src/main/java/org/thoughtcrime/securesms/util/FeatureFlags.java index d82d552a58..4f6c3b2153 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/FeatureFlags.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/FeatureFlags.java @@ -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 @@ -61,7 +62,8 @@ public final class FeatureFlags { private static final Set REMOTE_CAPABLE = Sets.newHashSet( 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); } + /** 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 getMemoryValues() { return new TreeMap<>(REMOTE_VALUES); diff --git a/app/src/main/res/drawable-mdpi/profile_megaphone.png b/app/src/main/res/drawable-mdpi/profile_megaphone.png new file mode 100644 index 0000000000..a5d9b3133e Binary files /dev/null and b/app/src/main/res/drawable-mdpi/profile_megaphone.png differ diff --git a/app/src/main/res/drawable-xhdpi/profile_megaphone.png b/app/src/main/res/drawable-xhdpi/profile_megaphone.png new file mode 100644 index 0000000000..801c510195 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/profile_megaphone.png differ diff --git a/app/src/main/res/drawable-xxhdpi/profile_megaphone.png b/app/src/main/res/drawable-xxhdpi/profile_megaphone.png new file mode 100644 index 0000000000..ca5f625a93 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/profile_megaphone.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/profile_megaphone.png b/app/src/main/res/drawable-xxxhdpi/profile_megaphone.png new file mode 100644 index 0000000000..21d9146573 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/profile_megaphone.png differ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 10df0ef350..f6e34b5f8d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1797,6 +1797,14 @@ We\'ll remind you later. Creating a PIN will become mandatory in %1$d days. We\'ll remind you later. Confirming your PIN will become mandatory in %1$d days. + + Add a profile name + This will be displayed when you start a new conversation or share it. + Add Profile Name + Confirm your Profile Name + Your profile can now include an optional last name. + Confirm Name + Transport icon Loading…