From d1b61bfed356f816304203d423fa6e746b344e86 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 14 Jul 2020 07:37:09 -0700 Subject: [PATCH] Add indicator for system contacts. --- .../contacts/sync/DirectoryHelper.java | 2 +- .../conversation/ConversationTitleView.java | 34 +++++++----- .../ManageRecipientFragment.java | 31 +++++++++-- .../ManageRecipientRepository.java | 15 ++++++ .../ManageRecipientViewModel.java | 4 ++ .../drawable/ic_profile_circle_outline_16.xml | 9 ++++ .../drawable/ic_profile_circle_outline_24.xml | 9 ++++ .../res/layout/conversation_title_view.xml | 5 +- .../res/layout/recipient_manage_fragment.xml | 52 ++++++++++++++++++- app/src/main/res/values/strings.xml | 2 + 10 files changed, 142 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/drawable/ic_profile_circle_outline_16.xml create mode 100644 app/src/main/res/drawable/ic_profile_circle_outline_24.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/DirectoryHelper.java b/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/DirectoryHelper.java index 751e9dbd57..fac23c82e4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/DirectoryHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/DirectoryHelper.java @@ -159,7 +159,7 @@ public class DirectoryHelper { RegisteredState originalRegisteredState = recipient.resolve().getRegistered(); RegisteredState newRegisteredState = null; - if (recipient.getUuid().isPresent()) { + if (recipient.hasUuid() && !recipient.hasE164()) { boolean isRegistered = isUuidRegistered(context, recipient); if (isRegistered) { recipientDatabase.markRegistered(recipient.getId(), recipient.getUuid().get()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationTitleView.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationTitleView.java index e99eb88dc2..b7f6096899 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationTitleView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationTitleView.java @@ -54,15 +54,15 @@ public class ConversationTitleView extends RelativeLayout { public void onFinishInflate() { super.onFinishInflate(); - this.content = ViewUtil.findById(this, R.id.content); - this.title = ViewUtil.findById(this, R.id.title); - this.subtitle = ViewUtil.findById(this, R.id.subtitle); - this.verified = ViewUtil.findById(this, R.id.verified_indicator); - this.subtitleContainer = ViewUtil.findById(this, R.id.subtitle_container); - this.verifiedSubtitle = ViewUtil.findById(this, R.id.verified_subtitle); - this.avatar = ViewUtil.findById(this, R.id.contact_photo_image); - this.expirationBadgeContainer = ViewUtil.findById(this, R.id.expiration_badge_container); - this.expirationBadgeTime = ViewUtil.findById(this, R.id.expiration_badge); + this.content = findViewById(R.id.content); + this.title = findViewById(R.id.title); + this.subtitle = findViewById(R.id.subtitle); + this.verified = findViewById(R.id.verified_indicator); + this.subtitleContainer = findViewById(R.id.subtitle_container); + this.verifiedSubtitle = findViewById(R.id.verified_subtitle); + this.avatar = findViewById(R.id.contact_photo_image); + this.expirationBadgeContainer = findViewById(R.id.expiration_badge_container); + this.expirationBadgeTime = findViewById(R.id.expiration_badge); ViewUtil.setTextViewGravityStart(this.title, getContext()); ViewUtil.setTextViewGravityStart(this.subtitle, getContext()); @@ -85,14 +85,22 @@ public class ConversationTitleView extends RelativeLayout { if (recipient == null) setComposeTitle(); else setRecipientTitle(recipient); + int startDrawable = 0; + int endDrawable = 0; + if (recipient != null && recipient.isBlocked()) { - title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_white_18dp, 0, 0, 0); + startDrawable = R.drawable.ic_block_white_18dp; } else if (recipient != null && recipient.isMuted()) { - title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_white_18dp, 0, 0, 0); - } else { - title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + startDrawable = R.drawable.ic_volume_off_white_18dp; } + if (recipient != null && recipient.isSystemContact() && !recipient.isLocalNumber()) { + endDrawable = R.drawable.ic_profile_circle_outline_16; + } + + title.setCompoundDrawablesRelativeWithIntrinsicBounds(startDrawable, 0, endDrawable, 0); + + if (recipient != null) { this.avatar.setAvatar(glideRequests, recipient, false); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientFragment.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientFragment.java index 2d01358888..7aad945f76 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientFragment.java @@ -44,6 +44,7 @@ import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.profiles.edit.EditProfileActivity; import org.thoughtcrime.securesms.recipients.Recipient; +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; @@ -58,13 +59,17 @@ public class ManageRecipientFragment extends LoggingFragment { private static final String RECIPIENT_ID = "RECIPIENT_ID"; private static final String FROM_CONVERSATION = "FROM_CONVERSATION"; - private static final int RETURN_FROM_MEDIA = 405; + private static final int REQUEST_CODE_RETURN_FROM_MEDIA = 405; + private static final int REQUEST_CODE_ADD_CONTACT = 588; private ManageRecipientViewModel viewModel; private GroupMemberListView sharedGroupList; private Toolbar toolbar; private TextView title; private TextView subtitle; + private View contactRow; + private TextView contactText; + private ImageView contactIcon; private AvatarImageView avatar; private ThreadPhotoRailView threadPhotoRailView; private View mediaCard; @@ -114,6 +119,9 @@ public class ManageRecipientFragment extends LoggingFragment { avatar = view.findViewById(R.id.recipient_avatar); toolbar = view.findViewById(R.id.toolbar); + contactRow = view.findViewById(R.id.recipient_contact_row); + contactText = view.findViewById(R.id.recipient_contact_text); + contactIcon = view.findViewById(R.id.recipient_contact_icon); title = view.findViewById(R.id.name); subtitle = view.findViewById(R.id.username_number); sharedGroupList = view.findViewById(R.id.shared_group_list); @@ -182,6 +190,7 @@ public class ManageRecipientFragment extends LoggingFragment { notificationsCard.setVisibility(View.GONE); groupMembershipCard.setVisibility(View.GONE); blockUnblockCard.setVisibility(View.GONE); + contactRow.setVisibility(View.GONE); } else { viewModel.getVisibleSharedGroups().observe(getViewLifecycleOwner(), members -> sharedGroupList.setMembers(members)); viewModel.getSharedGroupsCountSummary().observe(getViewLifecycleOwner(), members -> groupsInCommonCount.setText(members)); @@ -246,12 +255,28 @@ public class ManageRecipientFragment extends LoggingFragment { @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == RETURN_FROM_MEDIA) { + if (requestCode == REQUEST_CODE_RETURN_FROM_MEDIA) { applyMediaCursorFactory(); + } else if (requestCode == REQUEST_CODE_ADD_CONTACT) { + viewModel.onAddedToContacts(); } } private void presentRecipient(@NonNull Recipient recipient) { + if (recipient.isSystemContact()) { + contactText.setText(R.string.ManageRecipientActivity_this_person_is_in_your_contacts); + contactIcon.setVisibility(View.VISIBLE); + contactRow.setOnClickListener(v -> { + startActivity(new Intent(Intent.ACTION_VIEW, recipient.getContactUri())); + }); + } else { + contactText.setText(R.string.ManageRecipientActivity_add_to_system_contacts); + contactIcon.setVisibility(View.GONE); + contactRow.setOnClickListener(v -> { + startActivityForResult(RecipientExporter.export(recipient).asAddContactIntent(), REQUEST_CODE_ADD_CONTACT); + }); + } + disappearingMessagesCard.setVisibility(recipient.isRegistered() ? View.VISIBLE : View.GONE); addToAGroup.setVisibility(recipient.isRegistered() ? View.VISIBLE : View.GONE); @@ -294,7 +319,7 @@ public class ManageRecipientFragment extends LoggingFragment { startActivityForResult(MediaPreviewActivity.intentFromMediaRecord(requireContext(), mediaRecord, ViewCompat.getLayoutDirection(threadPhotoRailView) == ViewCompat.LAYOUT_DIRECTION_LTR), - RETURN_FROM_MEDIA)); + REQUEST_CODE_RETURN_FROM_MEDIA)); } private void presentMuteState(@NonNull ManageRecipientViewModel.MuteState muteState) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientRepository.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientRepository.java index fe0b4f6a48..1edfdeaf8a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientRepository.java @@ -10,10 +10,12 @@ import com.annimon.stream.Stream; import org.thoughtcrime.securesms.color.MaterialColor; import org.thoughtcrime.securesms.color.MaterialColors; +import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.GroupDatabase; import org.thoughtcrime.securesms.database.IdentityDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase; +import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientId; @@ -21,11 +23,14 @@ import org.thoughtcrime.securesms.sms.MessageSender; import org.thoughtcrime.securesms.util.concurrent.SignalExecutors; import org.thoughtcrime.securesms.util.concurrent.SimpleTask; +import java.io.IOException; import java.util.ArrayList; import java.util.List; final class ManageRecipientRepository { + private static final String TAG = Log.tag(ManageRecipientRepository.class); + private final Context context; private final RecipientId recipientId; @@ -95,6 +100,16 @@ final class ManageRecipientRepository { }); } + void refreshRecipient() { + SignalExecutors.UNBOUNDED.execute(() -> { + try { + DirectoryHelper.refreshDirectoryFor(context, Recipient.resolved(recipientId), false); + } catch (IOException e) { + Log.w(TAG, "Failed to refresh user after adding to contacts."); + } + }); + } + @WorkerThread @NonNull List getSharedGroups(@NonNull RecipientId recipientId) { return Stream.of(DatabaseFactory.getGroupDatabase(context) diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientViewModel.java index 5b228b6c9c..1310426b47 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientViewModel.java @@ -257,6 +257,10 @@ public final class ManageRecipientViewModel extends ViewModel { withRecipient(r -> CommunicationActions.startVideoCall(activity, r)); } + void onAddedToContacts() { + manageRecipientRepository.refreshRecipient(); + } + static final class MediaCursor { private final long threadId; @NonNull private final CursorFactory mediaCursorFactory; diff --git a/app/src/main/res/drawable/ic_profile_circle_outline_16.xml b/app/src/main/res/drawable/ic_profile_circle_outline_16.xml new file mode 100644 index 0000000000..496142068b --- /dev/null +++ b/app/src/main/res/drawable/ic_profile_circle_outline_16.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_profile_circle_outline_24.xml b/app/src/main/res/drawable/ic_profile_circle_outline_24.xml new file mode 100644 index 0000000000..ad989a3526 --- /dev/null +++ b/app/src/main/res/drawable/ic_profile_circle_outline_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/conversation_title_view.xml b/app/src/main/res/layout/conversation_title_view.xml index 64a4300772..2344a7c1fc 100644 --- a/app/src/main/res/layout/conversation_title_view.xml +++ b/app/src/main/res/layout/conversation_title_view.xml @@ -39,13 +39,14 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|start" - android:drawablePadding="5dp" + android:drawablePadding="3dp" android:ellipsize="end" android:gravity="center_vertical" android:maxLines="1" android:transitionName="recipient_name" + android:drawableTint="@color/transparent_white_90" tools:ignore="UnusedAttribute" - tools:text="Contact name" /> + tools:text="J. Jonah Jameson" /> + tools:text="Gwen Stacy" /> + + + + + + + + + + + + + Add to system contacts + This person is in your contacts Disappearing messages Chat color Block