2015-05-04 11:36:18 -07:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.graphics.Typeface;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.graphics.drawable.Drawable;
|
2015-05-04 11:36:18 -07:00
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.style.StyleSpan;
|
|
|
|
import android.util.AttributeSet;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.util.Log;
|
2015-05-04 11:36:18 -07:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
2015-05-14 15:54:07 -07:00
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
|
2015-05-04 11:36:18 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
2015-05-04 11:36:18 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
|
|
|
2015-05-14 15:54:07 -07:00
|
|
|
public class FromTextView extends EmojiTextView {
|
2015-05-04 11:36:18 -07:00
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
private static final String TAG = FromTextView.class.getSimpleName();
|
|
|
|
|
2015-05-04 11:36:18 -07:00
|
|
|
public FromTextView(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public FromTextView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setText(Recipient recipient) {
|
2015-06-09 07:37:20 -07:00
|
|
|
setText(RecipientFactory.getRecipientsFor(getContext(), recipient, true));
|
2015-05-04 11:36:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setText(Recipients recipients) {
|
|
|
|
setText(recipients, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setText(Recipients recipients, boolean read) {
|
|
|
|
int attributes[] = new int[]{R.attr.conversation_list_item_count_color};
|
|
|
|
TypedArray colors = getContext().obtainStyledAttributes(attributes);
|
|
|
|
boolean isUnnamedGroup = recipients.isGroupRecipient() && TextUtils.isEmpty(recipients.getPrimaryRecipient().getName());
|
|
|
|
|
|
|
|
String fromString;
|
|
|
|
|
|
|
|
if (isUnnamedGroup) {
|
|
|
|
fromString = getContext().getString(R.string.ConversationActivity_unnamed_group);
|
|
|
|
} else {
|
|
|
|
fromString = recipients.toShortString();
|
|
|
|
}
|
|
|
|
|
|
|
|
int typeface;
|
|
|
|
|
|
|
|
if (isUnnamedGroup) {
|
|
|
|
if (!read) typeface = Typeface.BOLD_ITALIC;
|
|
|
|
else typeface = Typeface.ITALIC;
|
|
|
|
} else if (!read) {
|
|
|
|
typeface = Typeface.BOLD;
|
|
|
|
} else {
|
|
|
|
typeface = Typeface.NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SpannableStringBuilder builder = new SpannableStringBuilder(fromString);
|
|
|
|
builder.setSpan(new StyleSpan(typeface), 0, builder.length(),
|
|
|
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
|
|
|
|
colors.recycle();
|
|
|
|
|
|
|
|
setText(builder);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
if (recipients.isBlocked()) setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_grey600_18dp, 0, 0, 0);
|
|
|
|
else if (recipients.isMuted()) setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_volume_off_grey600_18dp, 0, 0, 0);
|
|
|
|
else setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
2015-05-04 11:36:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|