2015-05-04 11:36:18 -07:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Typeface;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.core.view.ViewCompat;
|
2015-05-04 11:36:18 -07:00
|
|
|
import android.text.Spannable;
|
2017-08-15 19:23:42 -07:00
|
|
|
import android.text.SpannableString;
|
2015-05-04 11:36:18 -07:00
|
|
|
import android.text.SpannableStringBuilder;
|
2017-08-15 19:23:42 -07:00
|
|
|
import android.text.Spanned;
|
2017-10-01 15:36:15 -07:00
|
|
|
import android.text.TextUtils;
|
2017-08-15 19:23:42 -07:00
|
|
|
import android.text.style.ForegroundColorSpan;
|
2015-05-04 11:36:18 -07:00
|
|
|
import android.text.style.StyleSpan;
|
2017-08-15 19:23:42 -07:00
|
|
|
import android.text.style.TypefaceSpan;
|
2015-05-04 11:36:18 -07:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.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;
|
2017-08-15 19:23:42 -07:00
|
|
|
import org.thoughtcrime.securesms.util.ResUtil;
|
|
|
|
import org.thoughtcrime.securesms.util.spans.CenterAlignedRelativeSizeSpan;
|
2015-05-04 11:36:18 -07:00
|
|
|
|
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) {
|
2017-08-01 08:56:00 -07:00
|
|
|
setText(recipient, true);
|
2015-05-04 11:36:18 -07:00
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public void setText(Recipient recipient, boolean read) {
|
2017-11-12 19:14:57 -08:00
|
|
|
String fromString = recipient.toShortString();
|
2015-05-04 11:36:18 -07:00
|
|
|
|
|
|
|
int typeface;
|
|
|
|
|
2017-01-22 21:23:51 -08:00
|
|
|
if (!read) {
|
2015-05-04 11:36:18 -07:00
|
|
|
typeface = Typeface.BOLD;
|
|
|
|
} else {
|
|
|
|
typeface = Typeface.NORMAL;
|
|
|
|
}
|
|
|
|
|
2017-08-15 19:23:42 -07:00
|
|
|
SpannableStringBuilder builder = new SpannableStringBuilder();
|
|
|
|
|
|
|
|
SpannableString fromSpan = new SpannableString(fromString);
|
|
|
|
fromSpan.setSpan(new StyleSpan(typeface), 0, builder.length(),
|
|
|
|
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
|
|
|
|
2019-01-13 23:30:54 -08:00
|
|
|
|
|
|
|
if (recipient.isLocalNumber()) {
|
|
|
|
builder.append(getContext().getString(R.string.note_to_self));
|
|
|
|
} else if (recipient.getName() == null && !TextUtils.isEmpty(recipient.getProfileName())) {
|
2017-08-15 19:23:42 -07:00
|
|
|
SpannableString profileName = new SpannableString(" (~" + recipient.getProfileName() + ") ");
|
|
|
|
profileName.setSpan(new CenterAlignedRelativeSizeSpan(0.75f), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
profileName.setSpan(new TypefaceSpan("sans-serif-light"), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
profileName.setSpan(new ForegroundColorSpan(ResUtil.getColor(getContext(), R.attr.conversation_list_item_subject_color)), 0, profileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
2017-09-25 09:05:41 -07:00
|
|
|
if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL){
|
2017-08-15 19:23:42 -07:00
|
|
|
builder.append(profileName);
|
|
|
|
builder.append(fromSpan);
|
|
|
|
} else {
|
|
|
|
builder.append(fromSpan);
|
|
|
|
builder.append(profileName);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
builder.append(fromSpan);
|
|
|
|
}
|
2015-05-04 11:36:18 -07:00
|
|
|
|
|
|
|
setText(builder);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient.isBlocked()) setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_block_grey600_18dp, 0, 0, 0);
|
|
|
|
else if (recipient.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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|