Show Note to Self for local number recipient preferences.

This commit is contained in:
Alan Evans 2020-06-17 17:37:23 -03:00
parent 0fbc6ac151
commit 891a1af995
4 changed files with 57 additions and 24 deletions

View File

@ -112,6 +112,9 @@ public final class AvatarImageView extends AppCompatImageView {
this.fallbackPhotoProvider = fallbackPhotoProvider; this.fallbackPhotoProvider = fallbackPhotoProvider;
} }
/**
* Shows self as the actual profile picture.
*/
public void setRecipient(@NonNull Recipient recipient) { public void setRecipient(@NonNull Recipient recipient) {
if (recipient.isLocalNumber()) { if (recipient.isLocalNumber()) {
setAvatar(GlideApp.with(this), null, false); setAvatar(GlideApp.with(this), null, false);
@ -121,6 +124,13 @@ public final class AvatarImageView extends AppCompatImageView {
} }
} }
/**
* 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) { public void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, boolean quickContactEnabled) {
if (recipient != null) { if (recipient != null) {
RecipientContactPhoto photo = new RecipientContactPhoto(recipient); RecipientContactPhoto photo = new RecipientContactPhoto(recipient);
@ -168,11 +178,12 @@ public final class AvatarImageView extends AppCompatImageView {
context.startActivity(ManageGroupActivity.newIntent(context, recipient.requireGroupId().requirePush()), context.startActivity(ManageGroupActivity.newIntent(context, recipient.requireGroupId().requirePush()),
ManageGroupActivity.createTransitionBundle(context, this)); ManageGroupActivity.createTransitionBundle(context, this));
} else { } else {
if (context instanceof FragmentActivity) { if (context instanceof FragmentActivity && !recipient.isLocalNumber()) {
RecipientBottomSheetDialogFragment.create(recipient.getId(), null) RecipientBottomSheetDialogFragment.create(recipient.getId(), null)
.show(((FragmentActivity) context).getSupportFragmentManager(), "BOTTOM"); .show(((FragmentActivity) context).getSupportFragmentManager(), "BOTTOM");
} else { } else {
context.startActivity(ManageRecipientActivity.newIntent(context, recipient.getId())); context.startActivity(ManageRecipientActivity.newIntent(context, recipient.getId()),
ManageRecipientActivity.createTransitionBundle(context, this));
} }
} }
}); });

View File

@ -23,7 +23,10 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.AvatarImageView; 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.groups.GroupId;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientExporter; import org.thoughtcrime.securesms.recipients.RecipientExporter;
import org.thoughtcrime.securesms.recipients.RecipientId; import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.util.ServiceUtil; import org.thoughtcrime.securesms.util.ServiceUtil;
@ -119,13 +122,20 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
viewModel = ViewModelProviders.of(this, factory).get(RecipientDialogViewModel.class); viewModel = ViewModelProviders.of(this, factory).get(RecipientDialogViewModel.class);
viewModel.getRecipient().observe(getViewLifecycleOwner(), recipient -> { 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.setText(name);
fullName.setVisibility(TextUtils.isEmpty(name) ? View.GONE : View.VISIBLE); 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() ? String.format("%s %s", recipient.getUsername().or(""), recipient.getSmsAddress().or("")).trim()
: ""; : "";
usernameNumber.setText(usernameNumberString); usernameNumber.setText(usernameNumberString);

View File

@ -62,8 +62,8 @@ public class ManageRecipientFragment extends Fragment {
private ManageRecipientViewModel viewModel; private ManageRecipientViewModel viewModel;
private GroupMemberListView sharedGroupList; private GroupMemberListView sharedGroupList;
private Toolbar toolbar; private Toolbar toolbar;
private TextView name; private TextView title;
private TextView usernameNumber; private TextView subtitle;
private AvatarImageView avatar; private AvatarImageView avatar;
private ThreadPhotoRailView threadPhotoRailView; private ThreadPhotoRailView threadPhotoRailView;
private View mediaCard; private View mediaCard;
@ -112,8 +112,8 @@ public class ManageRecipientFragment extends Fragment {
avatar = view.findViewById(R.id.recipient_avatar); avatar = view.findViewById(R.id.recipient_avatar);
toolbar = view.findViewById(R.id.toolbar); toolbar = view.findViewById(R.id.toolbar);
name = view.findViewById(R.id.name); title = view.findViewById(R.id.name);
usernameNumber = view.findViewById(R.id.username_number); subtitle = view.findViewById(R.id.username_number);
sharedGroupList = view.findViewById(R.id.shared_group_list); sharedGroupList = view.findViewById(R.id.shared_group_list);
groupsInCommonCount = view.findViewById(R.id.groups_in_common_count); groupsInCommonCount = view.findViewById(R.id.groups_in_common_count);
threadPhotoRailView = view.findViewById(R.id.recent_photos); threadPhotoRailView = view.findViewById(R.id.recent_photos);
@ -176,7 +176,6 @@ public class ManageRecipientFragment extends Fragment {
toolbar.inflateMenu(R.menu.manage_recipient_fragment); toolbar.inflateMenu(R.menu.manage_recipient_fragment);
if (recipientId.equals(Recipient.self().getId())) { if (recipientId.equals(Recipient.self().getId())) {
toolbar.getMenu().findItem(R.id.action_edit).setVisible(true);
notificationsCard.setVisibility(View.GONE); notificationsCard.setVisibility(View.GONE);
groupMembershipCard.setVisibility(View.GONE); groupMembershipCard.setVisibility(View.GONE);
blockUnblockCard.setVisibility(View.GONE); blockUnblockCard.setVisibility(View.GONE);
@ -188,13 +187,13 @@ public class ManageRecipientFragment extends Fragment {
sharedGroupList.setOverScrollMode(View.OVER_SCROLL_NEVER); sharedGroupList.setOverScrollMode(View.OVER_SCROLL_NEVER);
} }
viewModel.getName().observe(getViewLifecycleOwner(), name::setText); viewModel.getTitle().observe(getViewLifecycleOwner(), title::setText);
viewModel.getSubtitle().observe(getViewLifecycleOwner(), text -> { viewModel.getSubtitle().observe(getViewLifecycleOwner(), text -> {
usernameNumber.setText(text); subtitle.setText(text);
usernameNumber.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE); subtitle.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE);
usernameNumber.setOnLongClickListener(null); subtitle.setOnLongClickListener(null);
name.setOnLongClickListener(null); title.setOnLongClickListener(null);
setCopyToClipboardOnLongPress(TextUtils.isEmpty(text) ? name : usernameNumber); setCopyToClipboardOnLongPress(TextUtils.isEmpty(text) ? title : subtitle);
}); });
viewModel.getDisappearingMessageTimer().observe(getViewLifecycleOwner(), string -> disappearingMessages.setText(string)); viewModel.getDisappearingMessageTimer().observe(getViewLifecycleOwner(), string -> disappearingMessages.setText(string));
viewModel.getRecipient().observe(getViewLifecycleOwner(), this::presentRecipient); viewModel.getRecipient().observe(getViewLifecycleOwner(), this::presentRecipient);
@ -252,8 +251,13 @@ public class ManageRecipientFragment extends Fragment {
public @NonNull FallbackContactPhoto getPhotoForRecipientWithoutName() { public @NonNull FallbackContactPhoto getPhotoForRecipientWithoutName() {
return new FallbackPhoto80dp(R.drawable.ic_profile_80, recipientColor); 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 -> { avatar.setOnClickListener(v -> {
FragmentActivity activity = requireActivity(); FragmentActivity activity = requireActivity();
activity.startActivity(AvatarPreviewActivity.intentFromRecipientId(activity, recipient.getId()), activity.startActivity(AvatarPreviewActivity.intentFromRecipientId(activity, recipient.getId()),

View File

@ -45,7 +45,7 @@ public final class ManageRecipientViewModel extends ViewModel {
private final Context context; private final Context context;
private final ManageRecipientRepository manageRecipientRepository; private final ManageRecipientRepository manageRecipientRepository;
private final LiveData<String> name; private final LiveData<String> title;
private final LiveData<String> subtitle; private final LiveData<String> subtitle;
private final LiveData<String> disappearingMessageTimer; private final LiveData<String> disappearingMessageTimer;
private final MutableLiveData<IdentityDatabase.IdentityRecord> identity; private final MutableLiveData<IdentityDatabase.IdentityRecord> identity;
@ -66,7 +66,7 @@ public final class ManageRecipientViewModel extends ViewModel {
manageRecipientRepository.getThreadId(this::onThreadIdLoaded); manageRecipientRepository.getThreadId(this::onThreadIdLoaded);
this.recipient = Recipient.live(manageRecipientRepository.getRecipientId()).getLiveData(); 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.subtitle = Transformations.map(recipient, r -> getDisplaySubtitle(r, context));
this.identity = new MutableLiveData<>(); this.identity = new MutableLiveData<>();
@ -97,8 +97,16 @@ public final class ManageRecipientViewModel extends ViewModel {
} }
} }
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) { 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("")) return String.format("%s %s", recipient.getUsername().or(""), recipient.getSmsAddress().or(""))
.trim(); .trim();
} else { } else {
@ -112,15 +120,15 @@ public final class ManageRecipientViewModel extends ViewModel {
() -> new ThreadMediaLoader(context, threadId, MediaLoader.MediaType.GALLERY, MediaDatabase.Sorting.Newest).getCursor())); () -> new ThreadMediaLoader(context, threadId, MediaLoader.MediaType.GALLERY, MediaDatabase.Sorting.Newest).getCursor()));
} }
public LiveData<String> getName() { LiveData<String> getTitle() {
return name; return title;
} }
public LiveData<String> getSubtitle() { LiveData<String> getSubtitle() {
return subtitle; return subtitle;
} }
public LiveData<Recipient> getRecipient() { LiveData<Recipient> getRecipient() {
return recipient; return recipient;
} }