2019-01-31 19:28:40 -08:00
|
|
|
package org.thoughtcrime.securesms.conversation;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-12-08 14:58:42 -08:00
|
|
|
import android.annotation.SuppressLint;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.content.Context;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
2017-06-06 18:03:09 -07:00
|
|
|
import android.widget.ImageView;
|
2017-09-12 22:48:30 -07:00
|
|
|
import android.widget.RelativeLayout;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
import com.annimon.stream.Collectors;
|
|
|
|
import com.annimon.stream.Stream;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.components.AvatarImageView;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2017-09-12 22:48:30 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2015-11-26 19:04:27 +01:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2019-08-06 15:43:47 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
public class ConversationTitleView extends RelativeLayout {
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-12-08 14:58:42 -08:00
|
|
|
@SuppressWarnings("unused")
|
2015-06-09 07:37:20 -07:00
|
|
|
private static final String TAG = ConversationTitleView.class.getSimpleName();
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
private View content;
|
|
|
|
private AvatarImageView avatar;
|
|
|
|
private TextView title;
|
|
|
|
private TextView subtitle;
|
|
|
|
private ImageView verified;
|
2019-01-13 23:30:54 -08:00
|
|
|
private View subtitleContainer;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
public ConversationTitleView(Context context) {
|
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConversationTitleView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinishInflate() {
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
2019-01-13 23:30:54 -08:00
|
|
|
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.avatar = ViewUtil.findById(this, R.id.contact_photo_image);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2019-07-22 13:08:56 +10:00
|
|
|
this.avatar.setEnabled(false);
|
|
|
|
|
2015-11-26 19:04:27 +01:00
|
|
|
ViewUtil.setTextViewGravityStart(this.title, getContext());
|
|
|
|
ViewUtil.setTextViewGravityStart(this.subtitle, getContext());
|
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
public void setTitle(@NonNull GlideRequests glideRequests, @Nullable Recipient recipient) {
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient == null) setComposeTitle();
|
|
|
|
else setRecipientTitle(recipient);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient != null && recipient.isBlocked()) {
|
2015-06-09 07:37:20 -07:00
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_white_18dp, 0, 0, 0);
|
2017-08-01 08:56:00 -07:00
|
|
|
} else if (recipient != null && recipient.isMuted()) {
|
2015-06-09 07:37:20 -07:00
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_white_18dp, 0, 0, 0);
|
|
|
|
} else {
|
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
|
|
}
|
2017-09-12 22:48:30 -07:00
|
|
|
|
|
|
|
if (recipient != null) {
|
2017-10-16 13:11:42 -07:00
|
|
|
this.avatar.setAvatar(glideRequests, recipient, false);
|
2017-09-12 22:48:30 -07:00
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
public void setVerified(boolean verified) {
|
|
|
|
this.verified.setVisibility(verified ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
@Override
|
|
|
|
public void setOnClickListener(@Nullable OnClickListener listener) {
|
|
|
|
this.content.setOnClickListener(listener);
|
2017-10-04 14:04:04 -07:00
|
|
|
this.avatar.setOnClickListener(listener);
|
2017-09-12 22:48:30 -07:00
|
|
|
}
|
|
|
|
|
2017-10-05 20:07:44 +02:00
|
|
|
@Override
|
|
|
|
public void setOnLongClickListener(@Nullable OnLongClickListener listener) {
|
|
|
|
this.content.setOnLongClickListener(listener);
|
|
|
|
this.avatar.setOnLongClickListener(listener);
|
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
private void setComposeTitle() {
|
|
|
|
this.title.setText(R.string.ConversationActivity_compose_message);
|
|
|
|
this.subtitle.setText(null);
|
|
|
|
this.subtitle.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setRecipientTitle(Recipient recipient) {
|
2017-08-15 19:23:42 -07:00
|
|
|
if (recipient.isGroupRecipient()) setGroupRecipientTitle(recipient);
|
2019-01-13 23:30:54 -08:00
|
|
|
else if (recipient.isLocalNumber()) setSelfTitle();
|
2017-08-15 19:23:42 -07:00
|
|
|
else if (TextUtils.isEmpty(recipient.getName())) setNonContactRecipientTitle(recipient);
|
|
|
|
else setContactRecipientTitle(recipient);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setGroupRecipientTitle(Recipient recipient) {
|
2017-09-12 22:48:30 -07:00
|
|
|
String localNumber = TextSecurePreferences.getLocalNumber(getContext());
|
|
|
|
|
2017-08-15 19:23:42 -07:00
|
|
|
this.title.setText(recipient.getName());
|
2017-09-12 22:48:30 -07:00
|
|
|
this.subtitle.setText(Stream.of(recipient.getParticipants())
|
|
|
|
.filter(r -> !r.getAddress().serialize().equals(localNumber))
|
|
|
|
.map(Recipient::toShortString)
|
2017-10-06 18:36:25 -04:00
|
|
|
.collect(Collectors.joining(", ")));
|
2017-09-12 22:48:30 -07:00
|
|
|
|
2019-08-06 15:43:47 +10:00
|
|
|
this.subtitle.setVisibility(View.GONE);
|
2019-01-13 23:30:54 -08:00
|
|
|
this.subtitleContainer.setVisibility(VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSelfTitle() {
|
|
|
|
this.title.setText(R.string.note_to_self);
|
|
|
|
this.subtitleContainer.setVisibility(View.GONE);
|
2017-08-15 19:23:42 -07:00
|
|
|
}
|
|
|
|
|
2017-12-08 14:58:42 -08:00
|
|
|
@SuppressLint("SetTextI18n")
|
2017-08-15 19:23:42 -07:00
|
|
|
private void setNonContactRecipientTitle(Recipient recipient) {
|
|
|
|
this.title.setText(recipient.getAddress().serialize());
|
2019-01-13 23:30:54 -08:00
|
|
|
this.subtitleContainer.setVisibility(VISIBLE);
|
2017-08-15 19:23:42 -07:00
|
|
|
|
|
|
|
if (TextUtils.isEmpty(recipient.getProfileName())) {
|
2015-06-09 07:37:20 -07:00
|
|
|
this.subtitle.setText(null);
|
|
|
|
this.subtitle.setVisibility(View.GONE);
|
2017-08-15 19:23:42 -07:00
|
|
|
} else {
|
|
|
|
this.subtitle.setText("~" + recipient.getProfileName());
|
|
|
|
this.subtitle.setVisibility(View.VISIBLE);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-15 19:23:42 -07:00
|
|
|
|
|
|
|
private void setContactRecipientTitle(Recipient recipient) {
|
|
|
|
this.title.setText(recipient.getName());
|
|
|
|
|
2019-05-23 16:21:09 -03:00
|
|
|
if (TextUtils.isEmpty(recipient.getCustomLabel())) {
|
|
|
|
this.subtitle.setText(null);
|
|
|
|
this.subtitle.setVisibility(View.GONE);
|
|
|
|
this.subtitleContainer.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
this.subtitle.setText(recipient.getCustomLabel());
|
|
|
|
this.subtitle.setVisibility(View.VISIBLE);
|
|
|
|
this.subtitleContainer.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2017-08-15 19:23:42 -07:00
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|