2015-06-09 14:37:20 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2017-09-13 05:48:30 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.AttributeSet;
|
2017-09-13 05:48:30 +00:00
|
|
|
import android.util.Log;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.view.View;
|
2017-06-07 01:03:09 +00:00
|
|
|
import android.widget.ImageView;
|
2017-09-13 05:48:30 +00:00
|
|
|
import android.widget.RelativeLayout;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
import com.annimon.stream.Collectors;
|
|
|
|
import com.annimon.stream.Stream;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.components.AvatarImageView;
|
2015-06-09 14:37:20 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2017-09-13 05:48:30 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2015-11-26 18:04:27 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
|
|
|
|
public class ConversationTitleView extends RelativeLayout {
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
private static final String TAG = ConversationTitleView.class.getSimpleName();
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
private View content;
|
|
|
|
private ImageView back;
|
|
|
|
private AvatarImageView avatar;
|
|
|
|
private TextView title;
|
|
|
|
private TextView subtitle;
|
|
|
|
private ImageView verified;
|
2015-06-09 14:37:20 +00: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-13 05:48:30 +00: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 14:37:20 +00:00
|
|
|
|
2015-11-26 18:04:27 +00:00
|
|
|
ViewUtil.setTextViewGravityStart(this.title, getContext());
|
|
|
|
ViewUtil.setTextViewGravityStart(this.subtitle, getContext());
|
|
|
|
}
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
public void setTitle(@Nullable Recipient recipient) {
|
|
|
|
if (recipient == null) setComposeTitle();
|
|
|
|
else setRecipientTitle(recipient);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient != null && recipient.isBlocked()) {
|
2015-06-09 14:37:20 +00:00
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_white_18dp, 0, 0, 0);
|
2017-08-01 15:56:00 +00:00
|
|
|
} else if (recipient != null && recipient.isMuted()) {
|
2015-06-09 14:37:20 +00:00
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_white_18dp, 0, 0, 0);
|
|
|
|
} else {
|
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
|
|
}
|
2017-09-13 05:48:30 +00:00
|
|
|
|
|
|
|
if (recipient != null) {
|
|
|
|
this.avatar.setAvatar(recipient, false);
|
|
|
|
}
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 01:03:09 +00:00
|
|
|
public void setVerified(boolean verified) {
|
|
|
|
this.verified.setVisibility(verified ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
@Override
|
|
|
|
public void setOnClickListener(@Nullable OnClickListener listener) {
|
|
|
|
this.content.setOnClickListener(listener);
|
2017-10-04 21:04:04 +00:00
|
|
|
this.avatar.setOnClickListener(listener);
|
2017-09-13 05:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnBackClickedListener(@Nullable OnClickListener listener) {
|
|
|
|
this.back.setOnClickListener(listener);
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00: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-16 02:23:42 +00:00
|
|
|
if (recipient.isGroupRecipient()) setGroupRecipientTitle(recipient);
|
|
|
|
else if (TextUtils.isEmpty(recipient.getName())) setNonContactRecipientTitle(recipient);
|
|
|
|
else setContactRecipientTitle(recipient);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setGroupRecipientTitle(Recipient recipient) {
|
2017-09-13 05:48:30 +00:00
|
|
|
String localNumber = TextSecurePreferences.getLocalNumber(getContext());
|
|
|
|
|
2017-08-16 02:23:42 +00:00
|
|
|
this.title.setText(recipient.getName());
|
2017-09-13 05:48:30 +00:00
|
|
|
this.subtitle.setText(Stream.of(recipient.getParticipants())
|
|
|
|
.filter(r -> !r.getAddress().serialize().equals(localNumber))
|
|
|
|
.map(Recipient::toShortString)
|
|
|
|
.collect(Collectors.joining(",")));
|
|
|
|
|
|
|
|
this.subtitle.setVisibility(View.VISIBLE);
|
2017-08-16 02:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setNonContactRecipientTitle(Recipient recipient) {
|
|
|
|
this.title.setText(recipient.getAddress().serialize());
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(recipient.getProfileName())) {
|
2015-06-09 14:37:20 +00:00
|
|
|
this.subtitle.setText(null);
|
|
|
|
this.subtitle.setVisibility(View.GONE);
|
2017-08-16 02:23:42 +00:00
|
|
|
} else {
|
|
|
|
this.subtitle.setText("~" + recipient.getProfileName());
|
|
|
|
this.subtitle.setVisibility(View.VISIBLE);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-16 02:23:42 +00: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 14:37:20 +00:00
|
|
|
}
|