Hide recipient subtitle if no name/username set.
parent
08800c9faf
commit
fe89794505
|
@ -125,8 +125,9 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
|
|||
fullName.setText(name);
|
||||
fullName.setVisibility(TextUtils.isEmpty(name) ? View.GONE : View.VISIBLE);
|
||||
|
||||
String usernameNumberString = String.format("%s %s", recipient.getUsername().or(""), recipient.getSmsAddress().or(""))
|
||||
.trim();
|
||||
String usernameNumberString = recipient.hasAUserSetDisplayName(requireContext())
|
||||
? String.format("%s %s", recipient.getUsername().or(""), recipient.getSmsAddress().or("")).trim()
|
||||
: "";
|
||||
usernameNumber.setText(usernameNumberString);
|
||||
usernameNumber.setVisibility(TextUtils.isEmpty(usernameNumberString) ? View.GONE : View.VISIBLE);
|
||||
usernameNumber.setOnLongClickListener(v -> {
|
||||
|
|
|
@ -187,6 +187,13 @@ public class ManageRecipientFragment extends Fragment {
|
|||
}
|
||||
|
||||
viewModel.getName().observe(getViewLifecycleOwner(), name::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);
|
||||
});
|
||||
viewModel.getDisappearingMessageTimer().observe(getViewLifecycleOwner(), string -> disappearingMessages.setText(string));
|
||||
viewModel.getRecipient().observe(getViewLifecycleOwner(), this::presentRecipient);
|
||||
viewModel.getMediaCursor().observe(getViewLifecycleOwner(), this::presentMediaCursor);
|
||||
|
@ -255,17 +262,6 @@ public class ManageRecipientFragment extends Fragment {
|
|||
colorChip.setImageDrawable(new ColorStateDrawable(colorDrawable, color));
|
||||
colorRow.setOnClickListener(v -> handleColorSelection(color));
|
||||
|
||||
String usernameNumberString = String.format("%s %s", recipient.getUsername().or(""), recipient.getSmsAddress().or(""))
|
||||
.trim();
|
||||
usernameNumber.setText(usernameNumberString);
|
||||
usernameNumber.setVisibility(TextUtils.isEmpty(usernameNumberString) ? View.GONE : View.VISIBLE);
|
||||
usernameNumber.setOnLongClickListener(v -> {
|
||||
Util.copyToClipboard(v.getContext(), usernameNumber.getText().toString());
|
||||
ServiceUtil.getVibrator(v.getContext()).vibrate(250);
|
||||
Toast.makeText(v.getContext(), R.string.RecipientBottomSheet_copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
});
|
||||
|
||||
secureCallButton.setVisibility(recipient.isRegistered() && !recipient.isLocalNumber() ? View.VISIBLE : View.GONE);
|
||||
secureVideoCallButton.setVisibility(recipient.isRegistered() && !recipient.isLocalNumber() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
@ -353,4 +349,13 @@ public class ManageRecipientFragment extends Fragment {
|
|||
mediaCard.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setCopyToClipboardOnLongPress(@NonNull TextView textView) {
|
||||
textView.setOnLongClickListener(v -> {
|
||||
Util.copyToClipboard(v.getContext(), textView.getText().toString());
|
||||
ServiceUtil.getVibrator(v.getContext()).vibrate(250);
|
||||
Toast.makeText(v.getContext(), R.string.RecipientBottomSheet_copied_to_clipboard, Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public final class ManageRecipientViewModel extends ViewModel {
|
|||
private final Context context;
|
||||
private final ManageRecipientRepository manageRecipientRepository;
|
||||
private final LiveData<String> name;
|
||||
private final LiveData<String> subtitle;
|
||||
private final LiveData<String> disappearingMessageTimer;
|
||||
private final MutableLiveData<IdentityDatabase.IdentityRecord> identity;
|
||||
private final LiveData<Recipient> recipient;
|
||||
|
@ -66,6 +67,7 @@ public final class ManageRecipientViewModel extends ViewModel {
|
|||
|
||||
this.recipient = Recipient.live(manageRecipientRepository.getRecipientId()).getLiveData();
|
||||
this.name = Transformations.map(recipient, r -> r.getDisplayName(context));
|
||||
this.subtitle = Transformations.map(recipient, r -> getDisplaySubtitle(r, context));
|
||||
this.identity = new MutableLiveData<>();
|
||||
|
||||
LiveData<List<Recipient>> allSharedGroups = LiveDataUtil.mapAsync(this.recipient, r -> manageRecipientRepository.getSharedGroups(r.getId()));
|
||||
|
@ -95,6 +97,15 @@ public final class ManageRecipientViewModel extends ViewModel {
|
|||
}
|
||||
}
|
||||
|
||||
private static @NonNull String getDisplaySubtitle(@NonNull Recipient recipient, @NonNull Context context) {
|
||||
if (recipient.hasAUserSetDisplayName(context)) {
|
||||
return String.format("%s %s", recipient.getUsername().or(""), recipient.getSmsAddress().or(""))
|
||||
.trim();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private void onThreadIdLoaded(long threadId) {
|
||||
mediaCursor.postValue(new MediaCursor(threadId,
|
||||
|
@ -105,6 +116,10 @@ public final class ManageRecipientViewModel extends ViewModel {
|
|||
return name;
|
||||
}
|
||||
|
||||
public LiveData<String> getSubtitle() {
|
||||
return subtitle;
|
||||
}
|
||||
|
||||
public LiveData<Recipient> getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue