Consolidate profile display labels.

This commit is contained in:
alex-signal 2019-10-09 13:57:36 -03:00 committed by Alan Evans
parent c60909272b
commit 55a8bd86de
47 changed files with 114 additions and 188 deletions

View File

@ -91,20 +91,6 @@
tools:text="+14152222222" tools:text="+14152222222"
tools:visibility="visible" /> 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> </LinearLayout>
<org.thoughtcrime.securesms.components.QuoteView <org.thoughtcrime.securesms.components.QuoteView

View File

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

View File

@ -1633,6 +1633,7 @@
<string name="prompt_passphrase_activity__tap_to_unlock">TAP TO UNLOCK</string> <string name="prompt_passphrase_activity__tap_to_unlock">TAP TO UNLOCK</string>
<string name="RegistrationLockDialog_reminder">Reminder:</string> <string name="RegistrationLockDialog_reminder">Reminder:</string>
<string name="recipient_preferences__about">About</string> <string name="recipient_preferences__about">About</string>
<string name="Recipient_unknown">Unknown</string>
<!-- EOF --> <!-- EOF -->
</resources> </resources>

View File

@ -193,8 +193,7 @@
<style name="ViewOnceVideo.Duration" parent="@android:style/TextAppearance"> <style name="ViewOnceVideo.Duration" parent="@android:style/TextAppearance">
<item name="android:textSize">16sp</item> <item name="android:textSize">16sp</item>
<item name="android:textColor">@color/white</item> <item name="android:textColor">@color/white</item>
<!-- TODO: change to transparent_black_60 after color swap --> <item name="android:shadowColor">@color/transparent_black_60</item>
<item name="android:shadowColor">#99000000</item>
<item name="android:shadowDx">0</item> <item name="android:shadowDx">0</item>
<item name="android:shadowDy">0</item> <item name="android:shadowDy">0</item>
<item name="android:shadowRadius">2</item> <item name="android:shadowRadius">2</item>

View File

@ -49,7 +49,7 @@ public class ConfirmIdentityDialog extends AlertDialog {
super(context); super(context);
Recipient recipient = Recipient.resolved(mismatch.getRecipientId(context)); Recipient recipient = Recipient.resolved(mismatch.getRecipientId(context));
String name = recipient.toShortString(); String name = recipient.getDisplayName(context);
String introduction = context.getString(R.string.ConfirmIdentityDialog_your_safety_number_with_s_has_changed, name, name); String introduction = context.getString(R.string.ConfirmIdentityDialog_your_safety_number_with_s_has_changed, name, name);
SpannableString spannableString = new SpannableString(introduction + " " + SpannableString spannableString = new SpannableString(introduction + " " +
context.getString(R.string.ConfirmIdentityDialog_you_may_wish_to_verify_your_safety_number_with_this_contact)); context.getString(R.string.ConfirmIdentityDialog_you_may_wish_to_verify_your_safety_number_with_this_contact));

View File

@ -183,7 +183,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
private void initializeProfileIcon(@NonNull Recipient recipient) { private void initializeProfileIcon(@NonNull Recipient recipient) {
ImageView icon = findViewById(R.id.toolbar_icon); ImageView icon = findViewById(R.id.toolbar_icon);
String name = Optional.fromNullable(recipient.getName()).or(Optional.fromNullable(TextSecurePreferences.getProfileName(this))).or(""); String name = Optional.fromNullable(recipient.getDisplayName(this)).or(Optional.fromNullable(TextSecurePreferences.getProfileName(this))).or("");
MaterialColor fallbackColor = recipient.getColor(); MaterialColor fallbackColor = recipient.getColor();
if (fallbackColor == ContactColors.UNKNOWN_COLOR && !TextUtils.isEmpty(name)) { if (fallbackColor == ContactColors.UNKNOWN_COLOR && !TextUtils.isEmpty(name)) {

View File

@ -145,7 +145,7 @@ public class ConversationListItem extends RelativeLayout
this.recipient.observeForever(this); this.recipient.observeForever(this);
if (highlightSubstring != null) { if (highlightSubstring != null) {
String name = recipient.get().isLocalNumber() ? getContext().getString(R.string.note_to_self) : recipient.get().getName(); String name = recipient.get().isLocalNumber() ? getContext().getString(R.string.note_to_self) : recipient.get().getDisplayName(getContext());
this.fromView.setText(SearchUtil.getHighlightedSpan(locale, () -> new StyleSpan(Typeface.BOLD), name, highlightSubstring)); this.fromView.setText(SearchUtil.getHighlightedSpan(locale, () -> new StyleSpan(Typeface.BOLD), name, highlightSubstring));
} else { } else {

View File

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

View File

@ -105,12 +105,7 @@ public class GroupMembersDialog extends AsyncTask<Void, Void, List<Recipient>> {
if (recipient.isLocalNumber()) { if (recipient.isLocalNumber()) {
recipientStrings.add(context.getString(R.string.GroupMembersDialog_me)); recipientStrings.add(context.getString(R.string.GroupMembersDialog_me));
} else { } else {
String name = recipient.toShortString(); String name = recipient.getDisplayName(context);
if (recipient.getName() == null && !TextUtils.isEmpty(recipient.getProfileName())) {
name += " ~" + recipient.getProfileName();
}
recipientStrings.add(name); recipientStrings.add(name);
} }
} }

View File

@ -139,9 +139,9 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity {
private void initializeToolbar() { private void initializeToolbar() {
setSupportActionBar(this.toolbar); setSupportActionBar(this.toolbar);
getSupportActionBar().setTitle(recipient.get().toShortString()); getSupportActionBar().setTitle(recipient.get().getDisplayName(this));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
this.recipient.observe(this, recipient -> getSupportActionBar().setTitle(recipient.toShortString())); this.recipient.observe(this, recipient -> getSupportActionBar().setTitle(recipient.getDisplayName(this)));
} }
public void onEnterMultiSelect() { 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)); if (mediaItem.outgoing) getSupportActionBar().setTitle(getString(R.string.MediaPreviewActivity_you));
else if (mediaItem.recipient != null) getSupportActionBar().setTitle(mediaItem.recipient.toShortString()); else if (mediaItem.recipient != null) getSupportActionBar().setTitle(mediaItem.recipient.getDisplayName(this));
else getSupportActionBar().setTitle(""); else getSupportActionBar().setTitle("");
getSupportActionBar().setSubtitle(relativeTimeSpan); getSupportActionBar().setSubtitle(relativeTimeSpan);

View File

@ -17,7 +17,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.loader.app.LoaderManager; import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader; import androidx.loader.content.Loader;
@ -30,8 +29,6 @@ import androidx.preference.PreferenceCategory;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.telephony.PhoneNumberUtils;
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat; import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto; import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto; import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto;
@ -228,7 +225,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP); else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP);
this.avatar.setBackgroundColor(recipient.getColor().toActionBarColor(this)); this.avatar.setBackgroundColor(recipient.getColor().toActionBarColor(this));
this.toolbarLayout.setTitle(recipient.toShortString()); this.toolbarLayout.setTitle(recipient.getDisplayName(this));
this.toolbarLayout.setContentScrimColor(recipient.getColor().toActionBarColor(this)); this.toolbarLayout.setContentScrimColor(recipient.getColor().toActionBarColor(this));
} }
@ -423,8 +420,9 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(requireActivity())); colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(requireActivity()));
colorPreference.setColor(recipient.getColor().toActionBarColor(requireActivity())); colorPreference.setColor(recipient.getColor().toActionBarColor(requireActivity()));
aboutPreference.setTitle(formatRecipient(recipient)); aboutPreference.setTitle(recipient.getDisplayName(requireContext()));
aboutPreference.setSummary(recipient.getCustomLabel());
aboutPreference.setSummary(recipient.resolve().getE164().or(""));
aboutPreference.setSecure(recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED); aboutPreference.setSecure(recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED);
if (recipient.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock); if (recipient.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
@ -452,12 +450,6 @@ 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) { private @NonNull String getRingtoneSummary(@NonNull Context context, @Nullable Uri ringtone) {
if (ringtone == null) { if (ringtone == null) {
return context.getString(R.string.preferences__default); return context.getString(R.string.preferences__default);

View File

@ -445,7 +445,7 @@ public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity
} }
private void setRecipientText(Recipient recipient) { 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.toShortString()))); 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.setMovementMethod(LinkMovementMethod.getInstance()); description.setMovementMethod(LinkMovementMethod.getInstance());
} }

View File

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

View File

@ -43,7 +43,7 @@ public class FromTextView extends EmojiTextView {
} }
public void setText(Recipient recipient, boolean read, @Nullable String suffix) { public void setText(Recipient recipient, boolean read, @Nullable String suffix) {
String fromString = recipient.toShortString(); String fromString = recipient.getDisplayName(getContext());
int typeface; int typeface;
@ -62,19 +62,6 @@ public class FromTextView extends EmojiTextView {
if (recipient.isLocalNumber()) { if (recipient.isLocalNumber()) {
builder.append(getContext().getString(R.string.note_to_self)); builder.append(getContext().getString(R.string.note_to_self));
} else if (recipient.getName() == 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 { } else {
builder.append(fromSpan); builder.append(fromSpan);
} }

View File

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

View File

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

View File

@ -124,7 +124,7 @@ public class WebRtcCallScreen extends FrameLayout implements RecipientForeverObs
} }
public void setUntrustedIdentity(Recipient personInfo, IdentityKey untrustedIdentity) { public void setUntrustedIdentity(Recipient personInfo, IdentityKey untrustedIdentity) {
String name = recipient.get().toShortString(); String name = recipient.get().getDisplayName(getContext());
String introduction = String.format(getContext().getString(R.string.WebRtcCallScreen_new_safety_numbers), name, name); 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)); SpannableString spannableString = new SpannableString(introduction + " " + getContext().getString(R.string.WebRtcCallScreen_you_may_wish_to_verify_this_contact));
@ -305,13 +305,13 @@ public class WebRtcCallScreen extends FrameLayout implements RecipientForeverObs
.diskCacheStrategy(DiskCacheStrategy.ALL) .diskCacheStrategy(DiskCacheStrategy.ALL)
.into(this.photo); .into(this.photo);
this.name.setText(recipient.getName()); this.name.setText(recipient.getDisplayName(getContext()));
if (recipient.getName() == null && !TextUtils.isEmpty(recipient.getProfileName())) { if (recipient.getE164().isPresent()) {
// TODO [greyson] This will need to change in UI PR?
this.phoneNumber.setText(recipient.requireE164() + " (~" + recipient.getProfileName() + ")");
} else {
this.phoneNumber.setText(recipient.requireE164()); this.phoneNumber.setText(recipient.requireE164());
this.phoneNumber.setVisibility(View.VISIBLE);
} else {
this.phoneNumber.setVisibility(View.GONE);
} }
} }

View File

@ -32,6 +32,7 @@ public class ContactRepository {
private final RecipientDatabase recipientDatabase; private final RecipientDatabase recipientDatabase;
private final String noteToSelfTitle; private final String noteToSelfTitle;
private final Context context;
public static final String ID_COLUMN = "id"; public static final String ID_COLUMN = "id";
static final String NAME_COLUMN = "name"; static final String NAME_COLUMN = "name";
@ -77,6 +78,7 @@ public class ContactRepository {
public ContactRepository(@NonNull Context context) { public ContactRepository(@NonNull Context context) {
this.recipientDatabase = DatabaseFactory.getRecipientDatabase(context); this.recipientDatabase = DatabaseFactory.getRecipientDatabase(context);
this.noteToSelfTitle = context.getString(R.string.note_to_self); this.noteToSelfTitle = context.getString(R.string.note_to_self);
this.context = context.getApplicationContext();
} }
@WorkerThread @WorkerThread
@ -87,7 +89,7 @@ public class ContactRepository {
if (noteToSelfTitle.toLowerCase().contains(query.toLowerCase())) { if (noteToSelfTitle.toLowerCase().contains(query.toLowerCase())) {
Recipient self = Recipient.self(); Recipient self = Recipient.self();
boolean nameMatch = self.getDisplayName().toLowerCase().contains(query.toLowerCase()); boolean nameMatch = self.getDisplayName(context).toLowerCase().contains(query.toLowerCase());
boolean numberMatch = self.getE164().isPresent() && self.requireE164().contains(query); boolean numberMatch = self.getE164().isPresent() && self.requireE164().contains(query);
boolean shouldAdd = !nameMatch && !numberMatch; boolean shouldAdd = !nameMatch && !numberMatch;

View File

@ -75,10 +75,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientF
} else if (recipientId != null) { } else if (recipientId != null) {
this.recipient = Recipient.live(recipientId); this.recipient = Recipient.live(recipientId);
this.recipient.observeForever(this); this.recipient.observeForever(this);
name = this.recipient.get().getDisplayName(getContext());
if (this.recipient.get().getName() != null) {
name = this.recipient.get().getName();
}
} }
Recipient recipientSnapshot = recipient != null ? recipient.get() : null; Recipient recipientSnapshot = recipient != null ? recipient.get() : null;

View File

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

View File

@ -18,6 +18,8 @@
package org.thoughtcrime.securesms.contacts; package org.thoughtcrime.securesms.contacts;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView; import androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView;
import android.telephony.PhoneNumberUtils; import android.telephony.PhoneNumberUtils;
import android.text.Annotation; import android.text.Annotation;
@ -185,8 +187,8 @@ public class RecipientsEditor extends AppCompatMultiAutoCompleteTextView {
return false; return false;
}*/ }*/
public static CharSequence contactToToken(Recipient c) { public static CharSequence contactToToken(@NonNull Context context, @NonNull Recipient c) {
String name = c.getName(); String name = c.getDisplayName(context);
String number = c.getE164().or(c.getEmail()).or(""); String number = c.getE164().or(c.getEmail()).or("");
SpannableString s = new SpannableString(RecipientsFormatter.formatNameAndNumber(name, number)); SpannableString s = new SpannableString(RecipientsFormatter.formatNameAndNumber(name, number));
int len = s.length(); int len = s.length();
@ -209,7 +211,7 @@ public class RecipientsEditor extends AppCompatMultiAutoCompleteTextView {
sb.append(", "); sb.append(", ");
} }
sb.append(contactToToken(c)); sb.append(contactToToken(mContext, c));
} }
setText(sb); setText(sb);

View File

@ -1014,9 +1014,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override @Override
protected void onPostExecute(IconCompat icon) { protected void onPostExecute(IconCompat icon) {
Context context = getApplicationContext(); Context context = getApplicationContext();
String name = Optional.fromNullable(recipient.get().getName()) String name = recipient.get().getDisplayName(ConversationActivity.this);
.or(Optional.fromNullable(recipient.get().getProfileName()))
.or(recipient.get().toShortString());
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(context, recipient.get().getId().serialize() + '-' + System.currentTimeMillis()) ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(context, recipient.get().getId().serialize() + '-' + System.currentTimeMillis())
.setShortLabel(name) .setShortLabel(name)
@ -2808,7 +2806,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
String[] unverifiedNames = new String[unverifiedIdentities.size()]; String[] unverifiedNames = new String[unverifiedIdentities.size()];
for (int i=0;i<unverifiedIdentities.size();i++) { for (int i=0;i<unverifiedIdentities.size();i++) {
unverifiedNames[i] = Recipient.resolved(unverifiedIdentities.get(i).getRecipientId()).toShortString(); unverifiedNames[i] = Recipient.resolved(unverifiedIdentities.get(i).getRecipientId()).getDisplayName(ConversationActivity.this);
} }
AlertDialog.Builder builder = new AlertDialog.Builder(ConversationActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(ConversationActivity.this);

View File

@ -153,7 +153,6 @@ public class ConversationItem extends LinearLayout implements BindableConversati
private ConversationItemFooter footer; private ConversationItemFooter footer;
private ConversationItemFooter stickerFooter; private ConversationItemFooter stickerFooter;
private TextView groupSender; private TextView groupSender;
private TextView groupSenderProfileName;
private View groupSenderHolder; private View groupSenderHolder;
private AvatarImageView contactPhoto; private AvatarImageView contactPhoto;
private AlertView alertView; private AlertView alertView;
@ -208,7 +207,6 @@ public class ConversationItem extends LinearLayout implements BindableConversati
this.footer = findViewById(R.id.conversation_item_footer); this.footer = findViewById(R.id.conversation_item_footer);
this.stickerFooter = findViewById(R.id.conversation_item_sticker_footer); this.stickerFooter = findViewById(R.id.conversation_item_sticker_footer);
this.groupSender = findViewById(R.id.group_message_sender); 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.alertView = findViewById(R.id.indicators_parent);
this.contactPhoto = findViewById(R.id.contact_photo); this.contactPhoto = findViewById(R.id.contact_photo);
this.contactPhotoHolder = findViewById(R.id.contact_photo_container); this.contactPhotoHolder = findViewById(R.id.contact_photo_container);
@ -944,28 +942,17 @@ public class ConversationItem extends LinearLayout implements BindableConversati
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private void setGroupMessageStatus(MessageRecord messageRecord, Recipient recipient) { private void setGroupMessageStatus(MessageRecord messageRecord, Recipient recipient) {
if (groupThread && !messageRecord.isOutgoing()) { if (groupThread && !messageRecord.isOutgoing()) {
this.groupSender.setText(recipient.toShortString()); this.groupSender.setText(recipient.getDisplayName(getContext()));
if (recipient.getName() == 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) { private void setGroupAuthorColor(@NonNull MessageRecord messageRecord) {
if (shouldDrawBodyBubbleOutline(messageRecord)) { if (shouldDrawBodyBubbleOutline(messageRecord)) {
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color)); 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)) { } else if (hasSticker(messageRecord)) {
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color)); groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color));
} else { } else {
groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color)); 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,10 +1,9 @@
package org.thoughtcrime.securesms.conversation; package org.thoughtcrime.securesms.conversation;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
@ -19,7 +18,6 @@ import org.thoughtcrime.securesms.components.AvatarImageView;
import org.thoughtcrime.securesms.mms.GlideRequests; import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.ViewUtil;
public class ConversationTitleView extends RelativeLayout { public class ConversationTitleView extends RelativeLayout {
@ -108,17 +106,16 @@ public class ConversationTitleView extends RelativeLayout {
private void setRecipientTitle(Recipient recipient) { private void setRecipientTitle(Recipient recipient) {
if (recipient.isGroup()) setGroupRecipientTitle(recipient); if (recipient.isGroup()) setGroupRecipientTitle(recipient);
else if (recipient.isLocalNumber()) setSelfTitle(); else if (recipient.isLocalNumber()) setSelfTitle();
else if (TextUtils.isEmpty(recipient.getName())) setNonContactRecipientTitle(recipient); else setIndividualRecipientTitle(recipient);
else setContactRecipientTitle(recipient);
} }
private void setGroupRecipientTitle(Recipient recipient) { private void setGroupRecipientTitle(Recipient recipient) {
String localNumber = TextSecurePreferences.getLocalNumber(getContext()); String localNumber = TextSecurePreferences.getLocalNumber(getContext());
this.title.setText(recipient.getName()); this.title.setText(recipient.getDisplayName(getContext()));
this.subtitle.setText(Stream.of(recipient.getParticipants()) this.subtitle.setText(Stream.of(recipient.getParticipants())
.filterNot(Recipient::isLocalNumber) .filterNot(Recipient::isLocalNumber)
.map(Recipient::toShortString) .map(r -> r.getDisplayName(getContext()))
.collect(Collectors.joining(", "))); .collect(Collectors.joining(", ")));
this.subtitle.setVisibility(View.VISIBLE); this.subtitle.setVisibility(View.VISIBLE);
@ -129,29 +126,11 @@ public class ConversationTitleView extends RelativeLayout {
this.subtitleContainer.setVisibility(View.GONE); this.subtitleContainer.setVisibility(View.GONE);
} }
@SuppressLint("SetTextI18n") private void setIndividualRecipientTitle(Recipient recipient) {
private void setNonContactRecipientTitle(Recipient recipient) { final String displayName = recipient.getDisplayName(getContext());
this.title.setText(Util.getFirstNonEmpty(recipient.getE164().orNull(), recipient.getUuid().orNull())); this.title.setText(displayName);
if (TextUtils.isEmpty(recipient.getProfileName())) {
this.subtitle.setText(null); this.subtitle.setText(null);
this.subtitle.setVisibility(View.GONE); 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());
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 updateVerifiedSubtitleVisibility() { private void updateVerifiedSubtitleVisibility() {

View File

@ -317,7 +317,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
String messageSound = cursor.getString(cursor.getColumnIndexOrThrow("notification")); String messageSound = cursor.getString(cursor.getColumnIndexOrThrow("notification"));
Uri messageSoundUri = messageSound != null ? Uri.parse(messageSound) : null; Uri messageSoundUri = messageSound != null ? Uri.parse(messageSound) : null;
int vibrateState = cursor.getInt(cursor.getColumnIndexOrThrow("vibrate")); int vibrateState = cursor.getInt(cursor.getColumnIndexOrThrow("vibrate"));
String displayName = NotificationChannels.getChannelDisplayNameFor(context, systemName, profileName, address); String displayName = NotificationChannels.getChannelDisplayNameFor(context, systemName, profileName, null, address);
boolean vibrateEnabled = vibrateState == 0 ? TextSecurePreferences.isNotificationVibrateEnabled(context) : vibrateState == 1; boolean vibrateEnabled = vibrateState == 0 ? TextSecurePreferences.isNotificationVibrateEnabled(context) : vibrateState == 1;
if (GroupUtil.isEncodedGroup(address)) { if (GroupUtil.isEncodedGroup(address)) {

View File

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

View File

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

View File

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

View File

@ -130,7 +130,7 @@ public class MultiDeviceContactUpdateJob extends BaseJob {
Optional<VerifiedMessage> verifiedMessage = getVerifiedMessage(recipient, identityRecord); Optional<VerifiedMessage> verifiedMessage = getVerifiedMessage(recipient, identityRecord);
out.write(new DeviceContact(RecipientUtil.toSignalServiceAddress(context, recipient), out.write(new DeviceContact(RecipientUtil.toSignalServiceAddress(context, recipient),
Optional.fromNullable(recipient.getName()), Optional.of(recipient.getDisplayName(context)),
getAvatar(recipient.getContactUri()), getAvatar(recipient.getContactUri()),
Optional.fromNullable(recipient.getColor().serialize()), Optional.fromNullable(recipient.getColor().serialize()),
verifiedMessage, verifiedMessage,

View File

@ -131,7 +131,7 @@ public class LongMessageActivity extends PassphraseRequiredActionBarActivity {
getSupportActionBar().setTitle(getString(R.string.LongMessageActivity_your_message)); getSupportActionBar().setTitle(getString(R.string.LongMessageActivity_your_message));
} else { } else {
Recipient recipient = message.get().getMessageRecord().getRecipient(); Recipient recipient = message.get().getMessageRecord().getRecipient();
String name = Util.getFirstNonEmpty(recipient.getName(), recipient.getProfileName(), recipient.getE164().orNull(), recipient.getEmail().orNull()) ; String name = recipient.getDisplayName(this);
getSupportActionBar().setTitle(getString(R.string.LongMessageActivity_message_from_s, name)); getSupportActionBar().setTitle(getString(R.string.LongMessageActivity_message_from_s, name));
} }

View File

@ -39,9 +39,7 @@ public class MediaPickerFolderFragment extends Fragment implements MediaPickerFo
String toolbarTitle; String toolbarTitle;
if (recipient != null) { if (recipient != null) {
String name = Optional.fromNullable(recipient.getName()) String name = recipient.getDisplayName(context);
.or(Optional.fromNullable(recipient.getProfileName()))
.or(recipient.toShortString());
toolbarTitle = context.getString(R.string.MediaPickerActivity_send_to, name); toolbarTitle = context.getString(R.string.MediaPickerActivity_send_to, name);
} else { } else {
toolbarTitle = ""; toolbarTitle = "";

View File

@ -704,8 +704,7 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
} else if (recipient.isLocalNumber()) { } else if (recipient.isLocalNumber()) {
composeText.setHint(getString(R.string.note_to_self), null); composeText.setHint(getString(R.string.note_to_self), null);
} else { } else {
String displayName = Util.getFirstNonEmpty(recipient.getName(), recipient.getProfileName(), recipient.getE164().orNull(), recipient.getEmail().orNull()); composeText.setHint(getString(R.string.MediaSendActivity_message_to_s, recipient.getDisplayName(this)), null);
composeText.setHint(getString(R.string.MediaSendActivity_message_to_s, displayName), null);
} }
} }

View File

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

View File

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

View File

@ -125,11 +125,18 @@ public class NotificationChannels {
/** /**
* @return A name suitable to be displayed as the notification channel title. * @return A name suitable to be displayed as the notification channel title.
*/ */
public static @NonNull String getChannelDisplayNameFor(@NonNull Context context, @Nullable String systemName, @Nullable String profileName, @NonNull String address) { public static @NonNull String getChannelDisplayNameFor(@NonNull Context context,
@Nullable String systemName,
@Nullable String profileName,
@Nullable String username,
@NonNull String address)
{
if (!TextUtils.isEmpty(systemName)) { if (!TextUtils.isEmpty(systemName)) {
return systemName; return systemName;
} else if (!TextUtils.isEmpty(profileName)) { } else if (!TextUtils.isEmpty(profileName)) {
return profileName; return profileName;
} else if (!TextUtils.isEmpty(username)) {
return username;
} else if (!TextUtils.isEmpty(address)) { } else if (!TextUtils.isEmpty(address)) {
return address; return address;
} else { } else {
@ -147,7 +154,7 @@ public class NotificationChannels {
VibrateState vibrateState = recipient.getMessageVibrate(); VibrateState vibrateState = recipient.getMessageVibrate();
boolean vibrationEnabled = vibrateState == VibrateState.DEFAULT ? TextSecurePreferences.isNotificationVibrateEnabled(context) : vibrateState == VibrateState.ENABLED; boolean vibrationEnabled = vibrateState == VibrateState.DEFAULT ? TextSecurePreferences.isNotificationVibrateEnabled(context) : vibrateState == VibrateState.ENABLED;
Uri messageRingtone = recipient.getMessageRingtone() != null ? recipient.getMessageRingtone() : getMessageRingtone(context); Uri messageRingtone = recipient.getMessageRingtone() != null ? recipient.getMessageRingtone() : getMessageRingtone(context);
String displayName = getChannelDisplayNameFor(context, recipient.getName(), recipient.getProfileName(), recipient.getSmsAddress().or("")); String displayName = recipient.getDisplayName(context);
return createChannelFor(context, generateChannelIdFor(recipient), displayName, messageRingtone, vibrationEnabled); return createChannelFor(context, generateChannelIdFor(recipient), displayName, messageRingtone, vibrationEnabled);
} }
@ -384,7 +391,7 @@ public class NotificationChannels {
} }
NotificationChannel channel = new NotificationChannel(recipient.getNotificationChannel(), NotificationChannel channel = new NotificationChannel(recipient.getNotificationChannel(),
getChannelDisplayNameFor(context, recipient.getName(), recipient.getProfileName(), recipient.getSmsAddress().or("")), recipient.getDisplayName(context),
NotificationManager.IMPORTANCE_HIGH); NotificationManager.IMPORTANCE_HIGH);
channel.setGroup(CATEGORY_MESSAGES); channel.setGroup(CATEGORY_MESSAGES);
notificationManager.createNotificationChannel(channel); notificationManager.createNotificationChannel(channel);

View File

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

View File

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

View File

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

View File

@ -32,6 +32,7 @@ import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.phonenumbers.NumberUtil; import org.thoughtcrime.securesms.phonenumbers.NumberUtil;
import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter; import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.GroupUtil; import org.thoughtcrime.securesms.util.GroupUtil;
import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.libsignal.util.guava.Optional;
@ -294,12 +295,12 @@ public class Recipient {
return contactUri; return contactUri;
} }
public @Nullable String getName() { public @Nullable String getName(@NonNull Context context) {
if (this.name == null && groupId != null && GroupUtil.isMmsGroup(groupId)) { if (this.name == null && groupId != null && GroupUtil.isMmsGroup(groupId)) {
List<String> names = new LinkedList<>(); List<String> names = new LinkedList<>();
for (Recipient recipient : participants) { for (Recipient recipient : participants) {
names.add(recipient.toShortString()); names.add(recipient.getDisplayName(context));
} }
return Util.join(names, ", "); return Util.join(names, ", ");
@ -308,18 +309,21 @@ public class Recipient {
return this.name; return this.name;
} }
public @NonNull String getDisplayName() { public @NonNull String getDisplayName(@NonNull Context context) {
String name = getName(); return Util.getFirstNonEmpty(getName(context),
if (!TextUtils.isEmpty(name)) { getProfileName(),
return name; getUsername(),
e164,
email,
context.getString(R.string.Recipient_unknown));
} }
String profileName = getProfileName(); private @NonNull String getUsername() {
if (!TextUtils.isEmpty(profileName)) { if (FeatureFlags.USERNAMES) {
return profileName; // TODO [greyson] Replace with actual username
return "@caycepollard";
} }
return "";
return getSmsAddress().or("");
} }
public @NonNull MaterialColor getColor() { public @NonNull MaterialColor getColor() {
@ -480,10 +484,6 @@ public class Recipient {
return new ArrayList<>(participants); return new ArrayList<>(participants);
} }
public @NonNull String toShortString() {
return Optional.fromNullable(getName()).or(getE164()).or(getEmail()).or("");
}
public @NonNull Drawable getFallbackContactPhotoDrawable(Context context, boolean inverted) { public @NonNull Drawable getFallbackContactPhotoDrawable(Context context, boolean inverted) {
return getFallbackContactPhoto().asDrawable(context, getColor().toAvatarColor(context), inverted); return getFallbackContactPhoto().asDrawable(context, getColor().toAvatarColor(context), inverted);
} }

View File

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

View File

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

View File

@ -10,4 +10,7 @@ public class FeatureFlags {
/** UUID-related stuff that shouldn't be activated until the user-facing launch. */ /** UUID-related stuff that shouldn't be activated until the user-facing launch. */
public static final boolean UUIDS = false; public static final boolean UUIDS = false;
/** Usernames. */
public static final boolean USERNAMES = false;
} }

View File

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

View File

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

View File

@ -105,7 +105,7 @@ public class SelectedRecipientsAdapter extends BaseAdapter {
TextView phone = (TextView) v.findViewById(R.id.phone); TextView phone = (TextView) v.findViewById(R.id.phone);
ImageButton delete = (ImageButton) v.findViewById(R.id.delete); ImageButton delete = (ImageButton) v.findViewById(R.id.delete);
name.setText(p.getName()); name.setText(p.getDisplayName(v.getContext()));
phone.setText(p.getE164().or("")); phone.setText(p.getE164().or(""));
delete.setVisibility(modifiable ? View.VISIBLE : View.GONE); delete.setVisibility(modifiable ? View.VISIBLE : View.GONE);
delete.setOnClickListener(new View.OnClickListener() { delete.setOnClickListener(new View.OnClickListener() {

View File

@ -46,7 +46,7 @@ public class CallNotificationBuilder {
.setSmallIcon(R.drawable.ic_call_secure_white_24dp) .setSmallIcon(R.drawable.ic_call_secure_white_24dp)
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setOngoing(true) .setOngoing(true)
.setContentTitle(recipient.getName()); .setContentTitle(recipient.getDisplayName(context));
if (type == TYPE_INCOMING_CONNECTING) { if (type == TYPE_INCOMING_CONNECTING) {
builder.setContentText(context.getString(R.string.CallNotificationBuilder_connecting)); builder.setContentText(context.getString(R.string.CallNotificationBuilder_connecting));