2015-06-09 14:37:20 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
2017-06-07 01:03:09 +00:00
|
|
|
import android.widget.ImageView;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2015-11-26 18:04:27 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
public class ConversationTitleView extends LinearLayout {
|
|
|
|
|
|
|
|
private static final String TAG = ConversationTitleView.class.getSimpleName();
|
|
|
|
|
|
|
|
private TextView title;
|
|
|
|
private TextView subtitle;
|
2017-06-07 01:03:09 +00:00
|
|
|
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-06-07 01:03:09 +00:00
|
|
|
this.title = (TextView) findViewById(R.id.title);
|
|
|
|
this.subtitle = (TextView) findViewById(R.id.subtitle);
|
|
|
|
this.verified = (ImageView) findViewById(R.id.verified_indicator);
|
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-06-07 01:03:09 +00:00
|
|
|
public void setVerified(boolean verified) {
|
|
|
|
this.verified.setVisibility(verified ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if (!recipient.isGroupRecipient()) {
|
|
|
|
if (TextUtils.isEmpty(recipient.getName())) {
|
2017-07-26 16:59:15 +00:00
|
|
|
this.title.setText(recipient.getAddress().serialize());
|
2015-06-09 14:37:20 +00:00
|
|
|
this.subtitle.setText(null);
|
|
|
|
this.subtitle.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
this.title.setText(recipient.getName());
|
2017-02-20 15:48:55 +00:00
|
|
|
|
|
|
|
if (recipient.getCustomLabel() != null) this.subtitle.setText(recipient.getCustomLabel());
|
2017-07-26 16:59:15 +00:00
|
|
|
else this.subtitle.setText(recipient.getAddress().serialize());
|
2017-02-20 15:48:55 +00:00
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
this.subtitle.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
2017-01-23 05:23:51 +00:00
|
|
|
this.title.setText(recipient.getName());
|
2015-06-09 14:37:20 +00:00
|
|
|
this.subtitle.setText(null);
|
|
|
|
this.subtitle.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|