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;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
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;
|
|
|
|
|
|
|
|
public ConversationTitleView(Context context) {
|
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConversationTitleView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinishInflate() {
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
|
|
|
this.title = (TextView) findViewById(R.id.title);
|
|
|
|
this.subtitle = (TextView) findViewById(R.id.subtitle);
|
|
|
|
|
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
|
|
|
|
|
|
|
public void setTitle(@Nullable Recipients recipients) {
|
|
|
|
if (recipients == null) setComposeTitle();
|
|
|
|
else if (recipients.isSingleRecipient()) setRecipientTitle(recipients.getPrimaryRecipient());
|
|
|
|
else setRecipientsTitle(recipients);
|
|
|
|
|
|
|
|
if (recipients != null && recipients.isBlocked()) {
|
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_white_18dp, 0, 0, 0);
|
|
|
|
} else if (recipients != null && recipients.isMuted()) {
|
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_white_18dp, 0, 0, 0);
|
|
|
|
} else {
|
|
|
|
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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())) {
|
|
|
|
this.title.setText(recipient.getNumber());
|
|
|
|
this.subtitle.setText(null);
|
|
|
|
this.subtitle.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
this.title.setText(recipient.getName());
|
|
|
|
this.subtitle.setText(recipient.getNumber());
|
|
|
|
this.subtitle.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String groupName = (!TextUtils.isEmpty(recipient.getName())) ?
|
|
|
|
recipient.getName() :
|
|
|
|
getContext().getString(R.string.ConversationActivity_unnamed_group);
|
|
|
|
|
|
|
|
this.title.setText(groupName);
|
|
|
|
this.subtitle.setText(null);
|
|
|
|
this.subtitle.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setRecipientsTitle(Recipients recipients) {
|
|
|
|
int size = recipients.getRecipientsList().size();
|
|
|
|
|
|
|
|
title.setText(getContext().getString(R.string.ConversationActivity_group_conversation));
|
2015-12-05 16:27:09 +00:00
|
|
|
subtitle.setText(getContext().getResources().getQuantityString(R.plurals.ConversationActivity_d_recipients_in_group, size, size));
|
2015-06-09 14:37:20 +00:00
|
|
|
subtitle.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|