Add support for an 'About' field on your profile.

This commit is contained in:
Greyson Parrelli
2021-01-21 12:35:00 -05:00
parent e80033c287
commit 7db16e6156
42 changed files with 709 additions and 119 deletions

View File

@@ -108,6 +108,8 @@ public class Recipient {
private final byte[] storageId;
private final MentionSetting mentionSetting;
private final ChatWallpaper wallpaper;
private final String about;
private final String aboutEmoji;
/**
@@ -342,6 +344,8 @@ public class Recipient {
this.storageId = null;
this.mentionSetting = MentionSetting.ALWAYS_NOTIFY;
this.wallpaper = null;
this.about = null;
this.aboutEmoji = null;
}
public Recipient(@NonNull RecipientId id, @NonNull RecipientDetails details, boolean resolved) {
@@ -385,6 +389,8 @@ public class Recipient {
this.storageId = details.storageId;
this.mentionSetting = details.mentionSetting;
this.wallpaper = details.wallpaper;
this.about = details.about;
this.aboutEmoji = details.aboutEmoji;
}
public @NonNull RecipientId getId() {
@@ -870,6 +876,28 @@ public class Recipient {
return contactUri != null;
}
public @Nullable String getAbout() {
return about;
}
public @Nullable String getAboutEmoji() {
return aboutEmoji;
}
public @Nullable String getCombinedAboutAndEmoji() {
if (aboutEmoji != null) {
if (about != null) {
return aboutEmoji + " " + about;
} else {
return aboutEmoji;
}
} else if (about != null) {
return about;
} else {
return null;
}
}
/**
* If this recipient is missing crucial data, this will return a populated copy. Otherwise it
* returns itself.
@@ -985,7 +1013,9 @@ public class Recipient {
insightsBannerTier == other.insightsBannerTier &&
Arrays.equals(storageId, other.storageId) &&
mentionSetting == other.mentionSetting &&
Objects.equals(wallpaper, other.wallpaper);
Objects.equals(wallpaper, other.wallpaper) &&
Objects.equals(about, other.about) &&
Objects.equals(aboutEmoji, other.aboutEmoji);
}
private static boolean allContentsAreTheSame(@NonNull List<Recipient> a, @NonNull List<Recipient> b) {

View File

@@ -67,6 +67,8 @@ public class RecipientDetails {
final byte[] storageId;
final MentionSetting mentionSetting;
final ChatWallpaper wallpaper;
final String about;
final String aboutEmoji;
public RecipientDetails(@Nullable String name,
@NonNull Optional<Long> groupAvatarId,
@@ -113,6 +115,8 @@ public class RecipientDetails {
this.storageId = settings.getStorageId();
this.mentionSetting = settings.getMentionSetting();
this.wallpaper = settings.getWallpaper();
this.about = settings.getAbout();
this.aboutEmoji = settings.getAboutEmoji();
if (name == null) this.name = settings.getSystemDisplayName();
else this.name = name;
@@ -161,6 +165,8 @@ public class RecipientDetails {
this.storageId = null;
this.mentionSetting = MentionSetting.ALWAYS_NOTIFY;
this.wallpaper = null;
this.about = null;
this.aboutEmoji = null;
}
public static @NonNull RecipientDetails forIndividual(@NonNull Context context, @NonNull RecipientSettings settings) {

View File

@@ -34,6 +34,7 @@ import org.thoughtcrime.securesms.recipients.RecipientExporter;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.recipients.RecipientUtil;
import org.thoughtcrime.securesms.util.BottomSheetUtil;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.Util;
@@ -55,6 +56,7 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
private RecipientDialogViewModel viewModel;
private AvatarImageView avatar;
private TextView fullName;
private TextView about;
private TextView usernameNumber;
private Button messageButton;
private Button secureCallButton;
@@ -102,6 +104,7 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
avatar = view.findViewById(R.id.rbs_recipient_avatar);
fullName = view.findViewById(R.id.rbs_full_name);
about = view.findViewById(R.id.rbs_about);
usernameNumber = view.findViewById(R.id.rbs_username_number);
messageButton = view.findViewById(R.id.rbs_message_button);
secureCallButton = view.findViewById(R.id.rbs_secure_call_button);
@@ -158,6 +161,14 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
TextViewCompat.setCompoundDrawableTintList(fullName, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.signal_text_primary)));
}
String aboutText = recipient.getCombinedAboutAndEmoji();
if (!Util.isEmpty(aboutText)) {
about.setText(aboutText);
about.setVisibility(View.VISIBLE);
} else {
about.setVisibility(View.GONE);
}
String usernameNumberString = recipient.hasAUserSetDisplayName(requireContext()) && !recipient.isSelf()
? recipient.getSmsAddress().transform(PhoneNumberFormatter::prettyPrint).or("").trim()
: "";

View File

@@ -51,6 +51,7 @@ import org.thoughtcrime.securesms.recipients.RecipientExporter;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.recipients.ui.notifications.CustomNotificationsDialogFragment;
import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.LifecycleCursorWrapper;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.Util;
@@ -71,6 +72,7 @@ public class ManageRecipientFragment extends LoggingFragment {
private GroupMemberListView sharedGroupList;
private Toolbar toolbar;
private TextView title;
private TextView about;
private TextView subtitle;
private ViewGroup internalDetails;
private TextView internalDetailsText;
@@ -132,6 +134,7 @@ public class ManageRecipientFragment extends LoggingFragment {
contactText = view.findViewById(R.id.recipient_contact_text);
contactIcon = view.findViewById(R.id.recipient_contact_icon);
title = view.findViewById(R.id.name);
about = view.findViewById(R.id.about);
subtitle = view.findViewById(R.id.username_number);
internalDetails = view.findViewById(R.id.recipient_internal_details);
internalDetailsText = view.findViewById(R.id.recipient_internal_details_text);
@@ -303,6 +306,10 @@ public class ManageRecipientFragment extends LoggingFragment {
});
}
String aboutText = recipient.getCombinedAboutAndEmoji();
about.setText(aboutText);
about.setVisibility(Util.isEmpty(aboutText) ? View.GONE : View.VISIBLE);
disappearingMessagesCard.setVisibility(recipient.isRegistered() ? View.VISIBLE : View.GONE);
addToAGroup.setVisibility(recipient.isRegistered() ? View.VISIBLE : View.GONE);