Skip to content

Commit

Permalink
Show Note to Self for local number recipient preferences.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-signal committed Jun 17, 2020
1 parent 0fbc6ac commit 891a1af
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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));
}
}
});
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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()),
Expand Down
Expand Up @@ -45,7 +45,7 @@ public final class ManageRecipientViewModel extends ViewModel {

private final Context context;
private final ManageRecipientRepository manageRecipientRepository;
private final LiveData<String> name;
private final LiveData<String> title;
private final LiveData<String> subtitle;
private final LiveData<String> disappearingMessageTimer;
private final MutableLiveData<IdentityDatabase.IdentityRecord> identity;
Expand All @@ -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<>();

Expand Down Expand Up @@ -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 {
Expand All @@ -112,15 +120,15 @@ private void onThreadIdLoaded(long threadId) {
() -> new ThreadMediaLoader(context, threadId, MediaLoader.MediaType.GALLERY, MediaDatabase.Sorting.Newest).getCursor()));
}

public LiveData<String> getName() {
return name;
LiveData<String> getTitle() {
return title;
}

public LiveData<String> getSubtitle() {
LiveData<String> getSubtitle() {
return subtitle;
}

public LiveData<Recipient> getRecipient() {
LiveData<Recipient> getRecipient() {
return recipient;
}

Expand Down

0 comments on commit 891a1af

Please sign in to comment.