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;
|
2017-09-12 22:48:30 -07:00
|
|
|
import android.support.annotation.NonNull;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
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;
|
|
|
|
|
2019-01-31 19:28:40 -08:00
|
|
|
import org.thoughtcrime.securesms.R;
|
2017-09-12 22:48:30 -07:00
|
|
|
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
|
|
|
|
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 ImageView back;
|
|
|
|
private AvatarImageView avatar;
|
|
|
|
private TextView title;
|
|
|
|
private TextView subtitle;
|
|
|
|
private ImageView verified;
|
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();
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
this.back = ViewUtil.findById(this, R.id.up_button);
|
|
|
|
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.avatar = ViewUtil.findById(this, R.id.contact_photo_image);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
public void setOnBackClickedListener(@Nullable OnClickListener listener) {
|
|
|
|
this.back.setOnClickListener(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);
|
|
|
|
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
|
|
|
|
|
|
|
this.subtitle.setVisibility(View.VISIBLE);
|
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());
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
if (recipient.getCustomLabel() != null) this.subtitle.setText(recipient.getCustomLabel());
|
|
|
|
else this.subtitle.setText(recipient.getAddress().serialize());
|
|
|
|
|
|
|
|
this.subtitle.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|