diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/AvatarImageView.java b/app/src/main/java/org/thoughtcrime/securesms/components/AvatarImageView.java index 95d4fea29ae..1748fe58f70 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/AvatarImageView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/AvatarImageView.java @@ -112,6 +112,9 @@ public void setFallbackPhotoProvider(Recipient.FallbackPhotoProvider fallbackPho this.fallbackPhotoProvider = fallbackPhotoProvider; } + /** + * Shows self as the actual profile picture. + */ public void setRecipient(@NonNull Recipient recipient) { if (recipient.isLocalNumber()) { setAvatar(GlideApp.with(this), null, false); @@ -121,6 +124,13 @@ public void setRecipient(@NonNull Recipient recipient) { } } + /** + * Shows self as the note to self icon. + */ + public void setAvatar(@Nullable Recipient recipient) { + setAvatar(GlideApp.with(this), recipient, false); + } + public void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, boolean quickContactEnabled) { if (recipient != null) { RecipientContactPhoto photo = new RecipientContactPhoto(recipient); @@ -168,11 +178,12 @@ private void setAvatarClickHandler(@NonNull final Recipient recipient, boolean q context.startActivity(ManageGroupActivity.newIntent(context, recipient.requireGroupId().requirePush()), ManageGroupActivity.createTransitionBundle(context, this)); } else { - if (context instanceof FragmentActivity) { + if (context instanceof FragmentActivity && !recipient.isLocalNumber()) { RecipientBottomSheetDialogFragment.create(recipient.getId(), null) .show(((FragmentActivity) context).getSupportFragmentManager(), "BOTTOM"); } else { - context.startActivity(ManageRecipientActivity.newIntent(context, recipient.getId())); + context.startActivity(ManageRecipientActivity.newIntent(context, recipient.getId()), + ManageRecipientActivity.createTransitionBundle(context, this)); } } }); diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientBottomSheetDialogFragment.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientBottomSheetDialogFragment.java index 1d21f0b3a8a..dd3619bb994 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientBottomSheetDialogFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientBottomSheetDialogFragment.java @@ -23,7 +23,10 @@ import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.components.AvatarImageView; +import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto; +import org.thoughtcrime.securesms.contacts.avatars.FallbackPhoto80dp; import org.thoughtcrime.securesms.groups.GroupId; +import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientExporter; import org.thoughtcrime.securesms.recipients.RecipientId; import org.thoughtcrime.securesms.util.ServiceUtil; @@ -119,13 +122,20 @@ public void onViewCreated(@NonNull View fragmentView, @Nullable Bundle savedInst viewModel = ViewModelProviders.of(this, factory).get(RecipientDialogViewModel.class); viewModel.getRecipient().observe(getViewLifecycleOwner(), recipient -> { - avatar.setRecipient(recipient); + avatar.setFallbackPhotoProvider(new Recipient.FallbackPhotoProvider() { + @Override + public @NonNull FallbackContactPhoto getPhotoForLocalNumber() { + return new FallbackPhoto80dp(R.drawable.ic_note_80, recipient.getColor()); + } + }); + avatar.setAvatar(recipient); - String name = recipient.getDisplayName(requireContext()); + String name = recipient.isLocalNumber() ? requireContext().getString(R.string.note_to_self) + : recipient.getDisplayName(requireContext()); fullName.setText(name); fullName.setVisibility(TextUtils.isEmpty(name) ? View.GONE : View.VISIBLE); - String usernameNumberString = recipient.hasAUserSetDisplayName(requireContext()) + String usernameNumberString = recipient.hasAUserSetDisplayName(requireContext()) && !recipient.isLocalNumber() ? String.format("%s %s", recipient.getUsername().or(""), recipient.getSmsAddress().or("")).trim() : ""; usernameNumber.setText(usernameNumberString); 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 8ffd7102f9f..1ccb17726fe 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 @@ -62,8 +62,8 @@ public class ManageRecipientFragment extends Fragment { private ManageRecipientViewModel viewModel; private GroupMemberListView sharedGroupList; private Toolbar toolbar; - private TextView name; - private TextView usernameNumber; + private TextView title; + private TextView subtitle; private AvatarImageView avatar; private ThreadPhotoRailView threadPhotoRailView; private View mediaCard; @@ -112,8 +112,8 @@ static ManageRecipientFragment newInstance(@NonNull RecipientId recipientId) { avatar = view.findViewById(R.id.recipient_avatar); toolbar = view.findViewById(R.id.toolbar); - name = view.findViewById(R.id.name); - usernameNumber = view.findViewById(R.id.username_number); + title = view.findViewById(R.id.name); + subtitle = view.findViewById(R.id.username_number); sharedGroupList = view.findViewById(R.id.shared_group_list); groupsInCommonCount = view.findViewById(R.id.groups_in_common_count); threadPhotoRailView = view.findViewById(R.id.recent_photos); @@ -176,7 +176,6 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { toolbar.inflateMenu(R.menu.manage_recipient_fragment); if (recipientId.equals(Recipient.self().getId())) { - toolbar.getMenu().findItem(R.id.action_edit).setVisible(true); notificationsCard.setVisibility(View.GONE); groupMembershipCard.setVisibility(View.GONE); blockUnblockCard.setVisibility(View.GONE); @@ -188,13 +187,13 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { sharedGroupList.setOverScrollMode(View.OVER_SCROLL_NEVER); } - viewModel.getName().observe(getViewLifecycleOwner(), name::setText); + viewModel.getTitle().observe(getViewLifecycleOwner(), title::setText); viewModel.getSubtitle().observe(getViewLifecycleOwner(), text -> { - usernameNumber.setText(text); - usernameNumber.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE); - usernameNumber.setOnLongClickListener(null); - name.setOnLongClickListener(null); - setCopyToClipboardOnLongPress(TextUtils.isEmpty(text) ? name : usernameNumber); + subtitle.setText(text); + subtitle.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE); + subtitle.setOnLongClickListener(null); + title.setOnLongClickListener(null); + setCopyToClipboardOnLongPress(TextUtils.isEmpty(text) ? title : subtitle); }); viewModel.getDisappearingMessageTimer().observe(getViewLifecycleOwner(), string -> disappearingMessages.setText(string)); viewModel.getRecipient().observe(getViewLifecycleOwner(), this::presentRecipient); @@ -252,8 +251,13 @@ private void presentRecipient(@NonNull Recipient recipient) { public @NonNull FallbackContactPhoto getPhotoForRecipientWithoutName() { return new FallbackPhoto80dp(R.drawable.ic_profile_80, recipientColor); } + + @Override + public @NonNull FallbackContactPhoto getPhotoForLocalNumber() { + return new FallbackPhoto80dp(R.drawable.ic_note_80, recipientColor); + } }); - avatar.setRecipient(recipient); + avatar.setAvatar(recipient); avatar.setOnClickListener(v -> { FragmentActivity activity = requireActivity(); activity.startActivity(AvatarPreviewActivity.intentFromRecipientId(activity, recipient.getId()), 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 404487f0ebe..e91a31c99a8 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 @@ -45,7 +45,7 @@ public final class ManageRecipientViewModel extends ViewModel { private final Context context; private final ManageRecipientRepository manageRecipientRepository; - private final LiveData name; + private final LiveData title; private final LiveData subtitle; private final LiveData disappearingMessageTimer; private final MutableLiveData identity; @@ -66,7 +66,7 @@ private ManageRecipientViewModel(@NonNull Context context, @NonNull ManageRecipi manageRecipientRepository.getThreadId(this::onThreadIdLoaded); this.recipient = Recipient.live(manageRecipientRepository.getRecipientId()).getLiveData(); - this.name = Transformations.map(recipient, r -> r.getDisplayName(context)); + this.title = Transformations.map(recipient, r -> getDisplayTitle(r, context)); this.subtitle = Transformations.map(recipient, r -> getDisplaySubtitle(r, context)); this.identity = new MutableLiveData<>(); @@ -97,8 +97,16 @@ private ManageRecipientViewModel(@NonNull Context context, @NonNull ManageRecipi } } + private static @NonNull String getDisplayTitle(@NonNull Recipient recipient, @NonNull Context context) { + if (recipient.isLocalNumber()) { + return context.getString(R.string.note_to_self); + } else { + return recipient.getDisplayName(context); + } + } + private static @NonNull String getDisplaySubtitle(@NonNull Recipient recipient, @NonNull Context context) { - if (recipient.hasAUserSetDisplayName(context)) { + if (!recipient.isLocalNumber() && recipient.hasAUserSetDisplayName(context)) { return String.format("%s %s", recipient.getUsername().or(""), recipient.getSmsAddress().or("")) .trim(); } else { @@ -112,15 +120,15 @@ private void onThreadIdLoaded(long threadId) { () -> new ThreadMediaLoader(context, threadId, MediaLoader.MediaType.GALLERY, MediaDatabase.Sorting.Newest).getCursor())); } - public LiveData getName() { - return name; + LiveData getTitle() { + return title; } - public LiveData getSubtitle() { + LiveData getSubtitle() { return subtitle; } - public LiveData getRecipient() { + LiveData getRecipient() { return recipient; }