Add feature flag to new Profile display.

master
Alex Hart 2019-10-31 13:20:55 -03:00 committed by Alan Evans
parent d8714fe3b4
commit f85c3bb1e6
32 changed files with 212 additions and 63 deletions

View File

@ -91,6 +91,20 @@
tools:text="+14152222222"
tools:visibility="visible" />
<TextView
android:id="@+id/group_message_sender_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="4sp"
android:paddingEnd="4sp"
style="@style/Signal.Text.Preview"
android:fontFamily="sans-serif-regular"
android:textColor="?conversation_item_received_text_primary_color"
android:textStyle="italic"
android:maxLines="1"
android:ellipsize="end"
tools:text="~Clement Duval"/>
</LinearLayout>
<org.thoughtcrime.securesms.components.QuoteView

View File

@ -143,6 +143,12 @@
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/group_message_sender_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<org.thoughtcrime.securesms.components.ConversationItemFooter
android:id="@+id/conversation_item_footer"
android:layout_width="match_parent"

View File

@ -26,6 +26,7 @@ import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.recipients.RecipientUtil;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.VerifySpan;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
@ -49,7 +50,7 @@ public class ConfirmIdentityDialog extends AlertDialog {
super(context);
Recipient recipient = Recipient.resolved(mismatch.getRecipientId(context));
String name = recipient.getDisplayName(context);
String name = recipient.toShortString(context);
String introduction = context.getString(R.string.ConfirmIdentityDialog_your_safety_number_with_s_has_changed, name, name);
SpannableString spannableString = new SpannableString(introduction + " " +
context.getString(R.string.ConfirmIdentityDialog_you_may_wish_to_verify_your_safety_number_with_this_contact));

View File

@ -499,7 +499,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
if (failIfNotPush && !isPush) {
results.add(new Result(null, false, activity.getString(R.string.GroupCreateActivity_cannot_add_non_push_to_existing_group,
recipient.getDisplayName(activity))));
recipient.toShortString(activity))));
} else if (TextUtils.equals(TextSecurePreferences.getLocalNumber(activity), recipient.getE164().or(""))) {
results.add(new Result(null, false, activity.getString(R.string.GroupCreateActivity_youre_already_in_the_group)));
} else {

View File

@ -10,6 +10,7 @@ import android.text.TextUtils;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientExporter;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.Util;
import java.util.LinkedList;
@ -105,7 +106,7 @@ public class GroupMembersDialog extends AsyncTask<Void, Void, List<Recipient>> {
if (recipient.isLocalNumber()) {
recipientStrings.add(context.getString(R.string.GroupMembersDialog_me));
} else {
String name = recipient.getDisplayName(context);
String name = getRecipientName(recipient);
recipientStrings.add(name);
}
}
@ -113,6 +114,18 @@ public class GroupMembersDialog extends AsyncTask<Void, Void, List<Recipient>> {
return recipientStrings.toArray(new String[members.size()]);
}
private String getRecipientName(Recipient recipient) {
if (FeatureFlags.PROFILE_DISPLAY) return recipient.getDisplayName(context);
String name = recipient.toShortString(context);
if (recipient.getName(context) == null && !TextUtils.isEmpty(recipient.getProfileName())) {
name += " ~" + recipient.getProfileName();
}
return name;
}
public Recipient get(int index) {
return members.get(index);
}

View File

@ -139,9 +139,9 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity {
private void initializeToolbar() {
setSupportActionBar(this.toolbar);
getSupportActionBar().setTitle(recipient.get().getDisplayName(this));
getSupportActionBar().setTitle(recipient.get().toShortString(this));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
this.recipient.observe(this, recipient -> getSupportActionBar().setTitle(recipient.getDisplayName(this)));
this.recipient.observe(this, recipient -> getSupportActionBar().setTitle(recipient.toShortString(this)));
}
public void onEnterMultiSelect() {

View File

@ -160,7 +160,7 @@ public final class MediaPreviewActivity extends PassphraseRequiredActionBarActiv
}
if (mediaItem.outgoing) getSupportActionBar().setTitle(getString(R.string.MediaPreviewActivity_you));
else if (mediaItem.recipient != null) getSupportActionBar().setTitle(mediaItem.recipient.getDisplayName(this));
else if (mediaItem.recipient != null) getSupportActionBar().setTitle(mediaItem.recipient.toShortString(this));
else getSupportActionBar().setTitle("");
getSupportActionBar().setSubtitle(relativeTimeSpan);

View File

@ -38,6 +38,8 @@ import org.thoughtcrime.securesms.database.GroupDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobs.RotateProfileKeyJob;
import org.thoughtcrime.securesms.logging.Log;
import android.telephony.PhoneNumberUtils;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -79,6 +81,7 @@ import org.thoughtcrime.securesms.util.Dialogs;
import org.thoughtcrime.securesms.util.DynamicDarkToolbarTheme;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.GroupUtil;
import org.thoughtcrime.securesms.util.IdentityUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
@ -225,7 +228,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP);
this.avatar.setBackgroundColor(recipient.getColor().toActionBarColor(this));
this.toolbarLayout.setTitle(recipient.getDisplayName(this));
this.toolbarLayout.setTitle(recipient.toShortString(this));
this.toolbarLayout.setContentScrimColor(recipient.getColor().toActionBarColor(this));
}
@ -420,9 +423,14 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(requireActivity()));
colorPreference.setColor(recipient.getColor().toActionBarColor(requireActivity()));
aboutPreference.setTitle(recipient.getDisplayName(requireContext()));
if (FeatureFlags.PROFILE_DISPLAY) {
aboutPreference.setTitle(recipient.getDisplayName(requireContext()));
aboutPreference.setSummary(recipient.resolve().getE164().or(""));
} else {
aboutPreference.setTitle(formatRecipient(recipient));
aboutPreference.setSummary(recipient.getCustomLabel());
}
aboutPreference.setSummary(recipient.resolve().getE164().or(""));
aboutPreference.setSecure(recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED);
if (recipient.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
@ -450,6 +458,12 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
}
}
private @NonNull String formatRecipient(@NonNull Recipient recipient) {
if (recipient.getE164().isPresent()) return PhoneNumberUtils.formatNumber(recipient.requireE164());
else if (recipient.getEmail().isPresent()) return recipient.requireEmail();
else return "";
}
private @NonNull String getRingtoneSummary(@NonNull Context context, @Nullable Uri ringtone) {
if (ringtone == null) {
return context.getString(R.string.preferences__default);

View File

@ -445,7 +445,7 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
}
private void setRecipientText(Recipient recipient) {
description.setText(Html.fromHtml(String.format(getActivity().getString(R.string.verify_display_fragment__if_you_wish_to_verify_the_security_of_your_end_to_end_encryption_with_s), recipient.getDisplayName(getContext()))));
description.setText(Html.fromHtml(String.format(getActivity().getString(R.string.verify_display_fragment__if_you_wish_to_verify_the_security_of_your_end_to_end_encryption_with_s), recipient.toShortString(getContext()))));
description.setMovementMethod(LinkMovementMethod.getInstance());
}

View File

@ -172,7 +172,7 @@ public class WebRtcCallActivity extends Activity {
Permissions.with(this)
.request(Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA)
.ifNecessary()
.withRationaleDialog(getString(R.string.WebRtcCallActivity_to_answer_the_call_from_s_give_signal_access_to_your_microphone, event.getRecipient().getDisplayName(this)),
.withRationaleDialog(getString(R.string.WebRtcCallActivity_to_answer_the_call_from_s_give_signal_access_to_your_microphone, event.getRecipient().toShortString(this)),
R.drawable.ic_mic_solid_24, R.drawable.ic_videocam_white_48dp)
.withPermanentDenialDialog(getString(R.string.WebRtcCallActivity_signal_requires_microphone_and_camera_permissions_in_order_to_make_or_receive_calls))
.onAllGranted(() -> {

View File

@ -19,6 +19,7 @@ import android.util.AttributeSet;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.ResUtil;
import org.thoughtcrime.securesms.util.spans.CenterAlignedRelativeSizeSpan;
@ -43,7 +44,7 @@ public class FromTextView extends EmojiTextView {
}
public void setText(Recipient recipient, boolean read, @Nullable String suffix) {
String fromString = recipient.getDisplayName(getContext());
String fromString = recipient.toShortString(getContext());
int typeface;
@ -62,6 +63,19 @@ public class FromTextView extends EmojiTextView {
if (recipient.isLocalNumber()) {
builder.append(getContext().getString(R.string.note_to_self));
} else if (!FeatureFlags.PROFILE_DISPLAY && recipient.getName(getContext()) == null && !TextUtils.isEmpty(recipient.getProfileName())) {
SpannableString profileName = new SpannableString(" (~" + recipient.getProfileName() + ") ");
profileName.setSpan(new CenterAlignedRelativeSizeSpan(0.75f), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
profileName.setSpan(new TypefaceSpan("sans-serif-light"), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
profileName.setSpan(new ForegroundColorSpan(ResUtil.getColor(getContext(), R.attr.conversation_list_item_subject_color)), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL){
builder.append(profileName);
builder.append(fromSpan);
} else {
builder.append(fromSpan);
builder.append(profileName);
}
} else {
builder.append(fromSpan);
}

View File

@ -190,7 +190,7 @@ public class QuoteView extends FrameLayout implements RecipientForeverObserver {
boolean outgoing = messageType != MESSAGE_TYPE_INCOMING;
authorView.setText(author.isLocalNumber() ? getContext().getString(R.string.QuoteView_you)
: author.getDisplayName(getContext()));
: author.toShortString(getContext()));
// We use the raw color resource because Android 4.x was struggling with tints here
quoteBarView.setImageResource(author.getColor().toQuoteBarColorResource(getContext(), outgoing));

View File

@ -19,7 +19,7 @@ public class InviteReminder extends Reminder {
final @NonNull Recipient recipient)
{
super(context.getString(R.string.reminder_header_invite_title),
context.getString(R.string.reminder_header_invite_text, recipient.getDisplayName(context)));
context.getString(R.string.reminder_header_invite_text, recipient.toShortString(context)));
setDismissListener(v -> SignalExecutors.BOUNDED.execute(() -> {
DatabaseFactory.getRecipientDatabase(context).setSeenInviteReminder(recipient.getId(), true);

View File

@ -45,6 +45,7 @@ import org.thoughtcrime.securesms.recipients.LiveRecipient;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientForeverObserver;
import org.thoughtcrime.securesms.ringrtc.CameraState;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.VerifySpan;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.webrtc.SurfaceViewRenderer;
@ -124,7 +125,7 @@ public class WebRtcCallScreen extends FrameLayout implements RecipientForeverObs
}
public void setUntrustedIdentity(Recipient personInfo, IdentityKey untrustedIdentity) {
String name = recipient.get().getDisplayName(getContext());
String name = recipient.get().toShortString(getContext());
String introduction = String.format(getContext().getString(R.string.WebRtcCallScreen_new_safety_numbers), name, name);
SpannableString spannableString = new SpannableString(introduction + " " + getContext().getString(R.string.WebRtcCallScreen_you_may_wish_to_verify_this_contact));
@ -305,13 +306,23 @@ public class WebRtcCallScreen extends FrameLayout implements RecipientForeverObs
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(this.photo);
this.name.setText(recipient.getDisplayName(getContext()));
if (FeatureFlags.PROFILE_DISPLAY) {
this.name.setText(recipient.getDisplayName(getContext()));
if (recipient.getE164().isPresent()) {
this.phoneNumber.setText(recipient.requireE164());
this.phoneNumber.setVisibility(View.VISIBLE);
if (recipient.getE164().isPresent()) {
this.phoneNumber.setText(recipient.requireE164());
this.phoneNumber.setVisibility(View.VISIBLE);
} else {
this.phoneNumber.setVisibility(View.GONE);
}
} else {
this.phoneNumber.setVisibility(View.GONE);
this.name.setText(recipient.getName(getContext()));
if (recipient.getName(getContext()) == null && !TextUtils.isEmpty(recipient.getProfileName())) {
this.phoneNumber.setText(recipient.requireE164() + " (~" + recipient.getProfileName() + ")");
} else {
this.phoneNumber.setText(recipient.requireE164());
}
}
}

View File

@ -182,7 +182,7 @@ public class ContactsCursorLoader extends CursorLoader {
ThreadRecord threadRecord;
while ((threadRecord = reader.getNext()) != null) {
recentConversations.addRow(new Object[] { threadRecord.getRecipient().getId().serialize(),
threadRecord.getRecipient().getDisplayName(getContext()),
threadRecord.getRecipient().toShortString(getContext()),
threadRecord.getRecipient().requireStringId(),
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE,
"",

View File

@ -2806,7 +2806,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
String[] unverifiedNames = new String[unverifiedIdentities.size()];
for (int i=0;i<unverifiedIdentities.size();i++) {
unverifiedNames[i] = Recipient.resolved(unverifiedIdentities.get(i).getRecipientId()).getDisplayName(ConversationActivity.this);
unverifiedNames[i] = Recipient.resolved(unverifiedIdentities.get(i).getRecipientId()).toShortString(ConversationActivity.this);
}
AlertDialog.Builder builder = new AlertDialog.Builder(ConversationActivity.this);

View File

@ -106,6 +106,7 @@ import org.thoughtcrime.securesms.revealable.ViewOnceUtil;
import org.thoughtcrime.securesms.stickers.StickerUrl;
import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.LongClickCopySpan;
import org.thoughtcrime.securesms.util.LongClickMovementMethod;
import org.thoughtcrime.securesms.util.SearchUtil;
@ -153,6 +154,7 @@ public class ConversationItem extends LinearLayout implements BindableConversati
private ConversationItemFooter footer;
private ConversationItemFooter stickerFooter;
private TextView groupSender;
private TextView groupSenderProfileName;
private View groupSenderHolder;
private AvatarImageView contactPhoto;
private AlertView alertView;
@ -207,6 +209,7 @@ public class ConversationItem extends LinearLayout implements BindableConversati
this.footer = findViewById(R.id.conversation_item_footer);
this.stickerFooter = findViewById(R.id.conversation_item_sticker_footer);
this.groupSender = findViewById(R.id.group_message_sender);
this.groupSenderProfileName = findViewById(R.id.group_message_sender_profile);
this.alertView = findViewById(R.id.indicators_parent);
this.contactPhoto = findViewById(R.id.contact_photo);
this.contactPhotoHolder = findViewById(R.id.contact_photo_container);
@ -942,17 +945,34 @@ public class ConversationItem extends LinearLayout implements BindableConversati
@SuppressLint("SetTextI18n")
private void setGroupMessageStatus(MessageRecord messageRecord, Recipient recipient) {
if (groupThread && !messageRecord.isOutgoing()) {
this.groupSender.setText(recipient.getDisplayName(getContext()));
if (FeatureFlags.PROFILE_DISPLAY) {
this.groupSender.setText(recipient.getDisplayName(getContext()));
this.groupSenderProfileName.setVisibility(View.GONE);
} else {
this.groupSender.setText(recipient.toShortString(context));
if (recipient.getName(context) == null && !TextUtils.isEmpty(recipient.getProfileName())) {
this.groupSenderProfileName.setText("~" + recipient.getProfileName());
this.groupSenderProfileName.setVisibility(View.VISIBLE);
} else {
this.groupSenderProfileName.setText(null);
this.groupSenderProfileName.setVisibility(View.GONE);
}
}
}
}
private void setGroupAuthorColor(@NonNull MessageRecord messageRecord) {
if (shouldDrawBodyBubbleOutline(messageRecord)) {
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
} else if (hasSticker(messageRecord)) {
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
} else {
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color));
groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color));
}
}

View File

@ -1,9 +1,11 @@
package org.thoughtcrime.securesms.conversation;
import android.annotation.SuppressLint;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
@ -17,9 +19,13 @@ import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.AvatarImageView;
import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil;
import java.util.UUID;
public class ConversationTitleView extends RelativeLayout {
@SuppressWarnings("unused")
@ -104,18 +110,55 @@ public class ConversationTitleView extends RelativeLayout {
}
private void setRecipientTitle(Recipient recipient) {
if (recipient.isGroup()) setGroupRecipientTitle(recipient);
else if (recipient.isLocalNumber()) setSelfTitle();
else setIndividualRecipientTitle(recipient);
if (FeatureFlags.PROFILE_DISPLAY) {
if (recipient.isGroup()) setGroupRecipientTitle(recipient);
else if (recipient.isLocalNumber()) setSelfTitle();
else setIndividualRecipientTitle(recipient);
} else {
if (recipient.isGroup()) setGroupRecipientTitle(recipient);
else if (recipient.isLocalNumber()) setSelfTitle();
else if (TextUtils.isEmpty(recipient.getName(getContext()))) setNonContactRecipientTitle(recipient);
else setContactRecipientTitle(recipient);
}
}
@SuppressLint("SetTextI18n")
private void setNonContactRecipientTitle(Recipient recipient) {
this.title.setText(Util.getFirstNonEmpty(recipient.getE164().orNull(), recipient.getUuid().transform(UUID::toString).orNull()));
if (TextUtils.isEmpty(recipient.getProfileName())) {
this.subtitle.setText(null);
this.subtitle.setVisibility(View.GONE);
} else {
this.subtitle.setText("~" + recipient.getProfileName());
this.subtitle.setVisibility(View.VISIBLE);
}
}
private void setContactRecipientTitle(Recipient recipient) {
this.title.setText(recipient.getName(getContext()));
if (TextUtils.isEmpty(recipient.getCustomLabel())) {
this.subtitle.setText(null);
this.subtitle.setVisibility(View.GONE);
} else {
this.subtitle.setText(recipient.getCustomLabel());
this.subtitle.setVisibility(View.VISIBLE);
}
}
private void setGroupRecipientTitle(Recipient recipient) {
String localNumber = TextSecurePreferences.getLocalNumber(getContext());
this.title.setText(recipient.getDisplayName(getContext()));
if (FeatureFlags.PROFILE_DISPLAY) {
this.title.setText(recipient.getDisplayName(getContext()));
} else {
this.title.setText(recipient.getName(getContext()));
}
this.subtitle.setText(Stream.of(recipient.getParticipants())
.filterNot(Recipient::isLocalNumber)
.map(r -> r.getDisplayName(getContext()))
.map(r -> r.toShortString(getContext()))
.collect(Collectors.joining(", ")));
this.subtitle.setVisibility(View.VISIBLE);

View File

@ -96,32 +96,32 @@ public abstract class MessageRecord extends DisplayRecord {
} else if (isGroupQuit() && isOutgoing()) {
return new SpannableString(context.getString(R.string.MessageRecord_left_group));
} else if (isGroupQuit()) {
return new SpannableString(context.getString(R.string.ConversationItem_group_action_left, getIndividualRecipient().getDisplayName(context)));
return new SpannableString(context.getString(R.string.ConversationItem_group_action_left, getIndividualRecipient().toShortString(context)));
} else if (isIncomingCall()) {
return new SpannableString(context.getString(R.string.MessageRecord_s_called_you, getIndividualRecipient().getDisplayName(context)));
return new SpannableString(context.getString(R.string.MessageRecord_s_called_you, getIndividualRecipient().toShortString(context)));
} else if (isOutgoingCall()) {
return new SpannableString(context.getString(R.string.MessageRecord_you_called));
} else if (isMissedCall()) {
return new SpannableString(context.getString(R.string.MessageRecord_missed_call));
} else if (isJoined()) {
return new SpannableString(context.getString(R.string.MessageRecord_s_joined_signal, getIndividualRecipient().getDisplayName(context)));
return new SpannableString(context.getString(R.string.MessageRecord_s_joined_signal, getIndividualRecipient().toShortString(context)));
} else if (isExpirationTimerUpdate()) {
int seconds = (int)(getExpiresIn() / 1000);
if (seconds <= 0) {
return isOutgoing() ? new SpannableString(context.getString(R.string.MessageRecord_you_disabled_disappearing_messages))
: new SpannableString(context.getString(R.string.MessageRecord_s_disabled_disappearing_messages, getIndividualRecipient().getDisplayName(context)));
: new SpannableString(context.getString(R.string.MessageRecord_s_disabled_disappearing_messages, getIndividualRecipient().toShortString(context)));
}
String time = ExpirationUtil.getExpirationDisplayValue(context, seconds);
return isOutgoing() ? new SpannableString(context.getString(R.string.MessageRecord_you_set_disappearing_message_time_to_s, time))
: new SpannableString(context.getString(R.string.MessageRecord_s_set_disappearing_message_time_to_s, getIndividualRecipient().getDisplayName(context), time));
: new SpannableString(context.getString(R.string.MessageRecord_s_set_disappearing_message_time_to_s, getIndividualRecipient().toShortString(context), time));
} else if (isIdentityUpdate()) {
return new SpannableString(context.getString(R.string.MessageRecord_your_safety_number_with_s_has_changed, getIndividualRecipient().getDisplayName(context)));
return new SpannableString(context.getString(R.string.MessageRecord_your_safety_number_with_s_has_changed, getIndividualRecipient().toShortString(context)));
} else if (isIdentityVerified()) {
if (isOutgoing()) return new SpannableString(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_verified, getIndividualRecipient().getDisplayName(context)));
else return new SpannableString(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_verified_from_another_device, getIndividualRecipient().getDisplayName(context)));
if (isOutgoing()) return new SpannableString(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_verified, getIndividualRecipient().toShortString(context)));
else return new SpannableString(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_verified_from_another_device, getIndividualRecipient().toShortString(context)));
} else if (isIdentityDefault()) {
if (isOutgoing()) return new SpannableString(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_unverified, getIndividualRecipient().getDisplayName(context)));
else return new SpannableString(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_unverified_from_another_device, getIndividualRecipient().getDisplayName(context)));
if (isOutgoing()) return new SpannableString(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_unverified, getIndividualRecipient().toShortString(context)));
else return new SpannableString(context.getString(R.string.MessageRecord_you_marked_your_safety_number_with_s_unverified_from_another_device, getIndividualRecipient().toShortString(context)));
}
return new SpannableString(getBody());

View File

@ -83,7 +83,7 @@ public class SmsMessageRecord extends MessageRecord {
} else if (isEndSession() && isOutgoing()) {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_secure_session_reset));
} else if (isEndSession()) {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_secure_session_reset_s, getIndividualRecipient().getDisplayName(context)));
return emphasisAdded(context.getString(R.string.SmsMessageRecord_secure_session_reset_s, getIndividualRecipient().toShortString(context)));
} else if (SmsDatabase.Types.isUnsupportedMessageType(type)) {
return emphasisAdded(context.getString(R.string.SmsMessageRecord_this_message_could_not_be_processed_because_it_was_sent_from_a_newer_version));
} else if (SmsDatabase.Types.isInvalidMessageType(type)) {

View File

@ -101,7 +101,7 @@ public class ThreadRecord extends DisplayRecord {
} else if (SmsDatabase.Types.isMissedCall(type)) {
return emphasisAdded(context.getString(org.thoughtcrime.securesms.R.string.ThreadRecord_missed_call));
} else if (SmsDatabase.Types.isJoinedType(type)) {
return emphasisAdded(context.getString(R.string.ThreadRecord_s_is_on_signal, getRecipient().getDisplayName(context)));
return emphasisAdded(context.getString(R.string.ThreadRecord_s_is_on_signal, getRecipient().toShortString(context)));
} else if (SmsDatabase.Types.isExpirationTimerUpdate(type)) {
int seconds = (int)(getExpiresIn() / 1000);
if (seconds <= 0) {
@ -111,7 +111,7 @@ public class ThreadRecord extends DisplayRecord {
return emphasisAdded(context.getString(R.string.ThreadRecord_disappearing_message_time_updated_to_s, time));
} else if (SmsDatabase.Types.isIdentityUpdate(type)) {
if (getRecipient().isGroup()) return emphasisAdded(context.getString(R.string.ThreadRecord_safety_number_changed));
else return emphasisAdded(context.getString(R.string.ThreadRecord_your_safety_number_with_s_has_changed, getRecipient().getDisplayName(context)));
else return emphasisAdded(context.getString(R.string.ThreadRecord_your_safety_number_with_s_has_changed, getRecipient().toShortString(context)));
} else if (SmsDatabase.Types.isIdentityVerified(type)) {
return emphasisAdded(context.getString(R.string.ThreadRecord_you_marked_verified));
} else if (SmsDatabase.Types.isIdentityDefault(type)) {

View File

@ -39,7 +39,7 @@ public abstract class AbstractNotificationBuilder extends NotificationCompat.Bui
protected CharSequence getStyledMessage(@NonNull Recipient recipient, @Nullable CharSequence message) {
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(Util.getBoldedString(recipient.getDisplayName(context)));
builder.append(Util.getBoldedString(recipient.toShortString(context)));
builder.append(": ");
builder.append(message == null ? "" : message);

View File

@ -47,7 +47,7 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
public void setMostRecentSender(Recipient recipient) {
if (privacy.isDisplayContact()) {
setContentText(context.getString(R.string.MessageNotifier_most_recent_from_s,
recipient.getDisplayName(context)));
recipient.toShortString(context)));
}
if (recipient.getNotificationChannel() != null) {
@ -67,7 +67,7 @@ public class MultipleRecipientNotificationBuilder extends AbstractNotificationBu
if (privacy.isDisplayMessage()) {
messageBodies.add(getStyledMessage(sender, body));
} else if (privacy.isDisplayContact()) {
messageBodies.add(Util.getBoldedString(sender.getDisplayName(context)));
messageBodies.add(Util.getBoldedString(sender.toShortString(context)));
}
if (privacy.isDisplayContact() && sender.getContactUri() != null) {

View File

@ -66,7 +66,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
setChannelId(channelId != null ? channelId : NotificationChannels.getMessagesChannel(context));
if (privacy.isDisplayContact()) {
setContentTitle(recipient.getDisplayName(context));
setContentTitle(recipient.toShortString(context));
if (recipient.getContactUri() != null) {
addPerson(recipient.getContactUri().toString());
@ -111,7 +111,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
if (privacy.isDisplayContact() && threadRecipients.isGroup()) {
stringBuilder.append(Util.getBoldedString(individualRecipient.getDisplayName(context) + ": "));
stringBuilder.append(Util.getBoldedString(individualRecipient.toShortString(context) + ": "));
}
if (privacy.isDisplayMessage()) {
@ -203,7 +203,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
if (privacy.isDisplayContact() && threadRecipient.isGroup()) {
stringBuilder.append(Util.getBoldedString(individualRecipient.getDisplayName(context) + ": "));
stringBuilder.append(Util.getBoldedString(individualRecipient.toShortString(context) + ": "));
}
if (privacy.isDisplayMessage()) {

View File

@ -63,7 +63,7 @@ public class BlockedContactListItem extends RelativeLayout implements RecipientF
final TextView nameView = this.nameView;
contactPhotoImage.setAvatar(glideRequests, recipient, false);
nameView.setText(recipient.getDisplayName(getContext()));
nameView.setText(recipient.toShortString(getContext()));
}
public Recipient getRecipient() {

View File

@ -40,7 +40,7 @@ public class UnknownSenderView extends FrameLayout {
new AlertDialog.Builder(getContext())
.setIconAttribute(R.attr.dialog_alert_icon)
.setTitle(getContext().getString(R.string.UnknownSenderView_block_s, recipient.getDisplayName(context)))
.setTitle(getContext().getString(R.string.UnknownSenderView_block_s, recipient.toShortString(context)))
.setMessage(R.string.UnknownSenderView_blocked_contacts_will_no_longer_be_able_to_send_you_messages_or_call_you)
.setPositiveButton(R.string.UnknownSenderView_block, (dialog, which) -> {
new AsyncTask<Void, Void, Void>() {
@ -66,7 +66,7 @@ public class UnknownSenderView extends FrameLayout {
new AlertDialog.Builder(getContext())
.setIconAttribute(R.attr.dialog_info_icon)
.setTitle(getContext().getString(R.string.UnknownSenderView_share_profile_with_s, recipient.getDisplayName(context)))
.setTitle(getContext().getString(R.string.UnknownSenderView_share_profile_with_s, recipient.toShortString(context)))
.setMessage(R.string.UnknownSenderView_the_easiest_way_to_share_your_profile_information_is_to_add_the_sender_to_your_contacts)
.setPositiveButton(R.string.UnknownSenderView_share_profile, (dialog, which) -> {
new AsyncTask<Void, Void, Void>() {

View File

@ -300,7 +300,7 @@ public class Recipient {
List<String> names = new LinkedList<>();
for (Recipient recipient : participants) {
names.add(recipient.getDisplayName(context));
names.add(recipient.toShortString(context));
}
return Util.join(names, ", ");
@ -309,6 +309,15 @@ public class Recipient {
return this.name;
}
/**
* TODO [UUID] -- Remove once UUID Feature Flag is removed
*/
@Deprecated
public @NonNull String toShortString(@NonNull Context context) {
if (FeatureFlags.PROFILE_DISPLAY) return getDisplayName(context);
else return Optional.fromNullable(getName(context)).or(getSmsAddress()).or("");
}
public @NonNull String getDisplayName(@NonNull Context context) {
return Util.getFirstNonEmpty(getName(context),
getProfileName(),
@ -425,10 +434,6 @@ public class Recipient {
}
}
public @Nullable String getCustomLabel() {
return customLabel;
}
/**
* @return A single string to represent the recipient, in order of precedence:
*
@ -454,6 +459,11 @@ public class Recipient {
return profileName;
}
public @Nullable String getCustomLabel() {
if (FeatureFlags.PROFILE_DISPLAY) throw new AssertionError("This method should never be called if PROFILE_DISPLAY is enabled.");
return customLabel;
}
public @Nullable String getProfileAvatar() {
return profileAvatar;
}

View File

@ -50,7 +50,7 @@ public class DirectShareService extends ChooserTargetService {
while ((record = reader.getNext()) != null) {
Recipient recipient = Recipient.resolved(record.getRecipient().getId());
String name = recipient.getDisplayName(this);
String name = recipient.toShortString(this);
Bitmap avatar;

View File

@ -35,10 +35,10 @@ public class CommunicationActions {
Permissions.with(activity)
.request(Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA)
.ifNecessary()
.withRationaleDialog(activity.getString(R.string.ConversationActivity_to_call_s_signal_needs_access_to_your_microphone_and_camera, recipient.getDisplayName(activity)),
.withRationaleDialog(activity.getString(R.string.ConversationActivity_to_call_s_signal_needs_access_to_your_microphone_and_camera, recipient.toShortString(activity)),
R.drawable.ic_mic_solid_24,
R.drawable.ic_videocam_white_48dp)
.withPermanentDenialDialog(activity.getString(R.string.ConversationActivity_signal_needs_the_microphone_and_camera_permissions_in_order_to_call_s, recipient.getDisplayName(activity)))
.withPermanentDenialDialog(activity.getString(R.string.ConversationActivity_signal_needs_the_microphone_and_camera_permissions_in_order_to_call_s, recipient.toShortString(activity)))
.onAllGranted(() -> {
Intent intent = new Intent(activity, WebRtcCallService.class);
intent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL);

View File

@ -13,4 +13,7 @@ public class FeatureFlags {
/** Usernames. */
public static final boolean USERNAMES = false;
/** New Profile Display */
public static final boolean PROFILE_DISPLAY = UUIDS;
}

View File

@ -117,7 +117,7 @@ public class GroupUtil {
public String toString(Recipient sender) {
StringBuilder description = new StringBuilder();
description.append(context.getString(R.string.MessageRecord_s_updated_group, sender.getDisplayName(context)));
description.append(context.getString(R.string.MessageRecord_s_updated_group, sender.toShortString(context)));
if (groupContext == null) {
return description.toString();
@ -160,7 +160,7 @@ public class GroupUtil {
String result = "";
for (int i=0;i<recipients.size();i++) {
result += recipients.get(i).getDisplayName(context);
result += recipients.get(i).toShortString(context);
if (i != recipients.size() -1 )
result += ", ";

View File

@ -231,11 +231,11 @@ public class IdentityUtil {
if (recipients.isEmpty()) return null;
if (recipients.size() == 1) {
String name = recipients.get(0).getDisplayName(context);
String name = recipients.get(0).toShortString(context);
return context.getString(resourceOne, name);
} else {
String firstName = recipients.get(0).getDisplayName(context);
String secondName = recipients.get(1).getDisplayName(context);
String firstName = recipients.get(0).toShortString(context);
String secondName = recipients.get(1).toShortString(context);
if (recipients.size() == 2) {
return context.getString(resourceTwo, firstName, secondName);