bright background for unread messages

Closes #3909
// FREEBIE
This commit is contained in:
Jake McGinty
2015-08-06 16:28:51 -07:00
committed by Moxie Marlinspike
parent 06e137aee9
commit ae17b4b24a
7 changed files with 59 additions and 12 deletions

View File

@@ -24,8 +24,8 @@ import android.graphics.drawable.RippleDrawable;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Handler;
import android.support.annotation.DrawableRes;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
@@ -34,6 +34,7 @@ import org.thoughtcrime.securesms.components.FromTextView;
import org.thoughtcrime.securesms.database.model.ThreadRecord;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.ResUtil;
import java.util.Locale;
import java.util.Set;
@@ -55,7 +56,6 @@ public class ConversationListItem extends RelativeLayout
private final static Typeface BOLD_TYPEFACE = Typeface.create("sans-serif", Typeface.BOLD);
private final static Typeface LIGHT_TYPEFACE = Typeface.create("sans-serif-light", Typeface.NORMAL);
private Context context;
private Set<Long> selectedThreads;
private Recipients recipients;
private long threadId;
@@ -65,25 +65,28 @@ public class ConversationListItem extends RelativeLayout
private boolean read;
private AvatarImageView contactPhotoImage;
private final @DrawableRes int readBackground;
private final @DrawableRes int unreadBackround;
private final Handler handler = new Handler();
private int distributionType;
public ConversationListItem(Context context) {
super(context);
this.context = context;
this(context, null);
}
public ConversationListItem(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
readBackground = ResUtil.getDrawableRes(context, R.attr.conversation_list_item_background_read);
unreadBackround = ResUtil.getDrawableRes(context, R.attr.conversation_list_item_background_unread);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
this.subjectView = (TextView) findViewById(R.id.subject);
this.fromView = (FromTextView) findViewById(R.id.from);
this.dateView = (TextView) findViewById(R.id.date);
this.subjectView = (TextView) findViewById(R.id.subject);
this.fromView = (FromTextView) findViewById(R.id.from);
this.dateView = (TextView) findViewById(R.id.date);
this.contactPhotoImage = (AvatarImageView) findViewById(R.id.contact_photo_image);
}
@@ -101,12 +104,13 @@ public class ConversationListItem extends RelativeLayout
this.subjectView.setTypeface(read ? LIGHT_TYPEFACE : BOLD_TYPEFACE);
if (thread.getDate() > 0) {
CharSequence date = DateUtils.getBriefRelativeTimeSpanString(context, locale, thread.getDate());
CharSequence date = DateUtils.getBriefRelativeTimeSpanString(getContext(), locale, thread.getDate());
dateView.setText(read ? date : color(getResources().getColor(R.color.textsecure_primary), date));
dateView.setTypeface(read ? LIGHT_TYPEFACE : BOLD_TYPEFACE);
}
setBatchState(batchMode);
setBackground(thread);
setRippleColor(recipients);
this.contactPhotoImage.setAvatar(recipients, true);
}
@@ -132,11 +136,16 @@ public class ConversationListItem extends RelativeLayout
return distributionType;
}
private void setBackground(ThreadRecord thread) {
if (thread.isRead()) setBackgroundResource(readBackground);
else setBackgroundResource(unreadBackround);
}
@TargetApi(VERSION_CODES.LOLLIPOP)
public void setRippleColor(Recipients recipients) {
private void setRippleColor(Recipients recipients) {
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
((RippleDrawable)(getBackground()).mutate())
.setColor(ColorStateList.valueOf(recipients.getColor().toConversationColor(context)));
.setColor(ColorStateList.valueOf(recipients.getColor().toConversationColor(getContext())));
}
}