diff --git a/res/drawable-v21/conversation_list_item_background.xml b/res/drawable-v21/conversation_list_item_background.xml index 7f73c13f0d..642879178e 100644 --- a/res/drawable-v21/conversation_list_item_background.xml +++ b/res/drawable-v21/conversation_list_item_background.xml @@ -7,4 +7,4 @@ - \ No newline at end of file + diff --git a/res/drawable-v21/conversation_list_item_unread_background.xml b/res/drawable-v21/conversation_list_item_unread_background.xml new file mode 100644 index 0000000000..06c7a5f786 --- /dev/null +++ b/res/drawable-v21/conversation_list_item_unread_background.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/res/drawable-v21/conversation_list_item_unread_background_dark.xml b/res/drawable-v21/conversation_list_item_unread_background_dark.xml new file mode 100644 index 0000000000..0b33205dee --- /dev/null +++ b/res/drawable-v21/conversation_list_item_unread_background_dark.xml @@ -0,0 +1,11 @@ + + + + + + + + + + diff --git a/res/drawable/conversation_list_item_unread_background.xml b/res/drawable/conversation_list_item_unread_background.xml new file mode 100644 index 0000000000..cede161f7c --- /dev/null +++ b/res/drawable/conversation_list_item_unread_background.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/res/drawable/conversation_list_item_unread_background_dark.xml b/res/drawable/conversation_list_item_unread_background_dark.xml new file mode 100644 index 0000000000..e6ae4638c8 --- /dev/null +++ b/res/drawable/conversation_list_item_unread_background_dark.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/res/values/themes.xml b/res/values/themes.xml index e2c4394ab2..26b8ed6262 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -79,6 +79,8 @@ @color/gray5 @drawable/list_selected_holo_light + @drawable/conversation_list_item_unread_background + @drawable/conversation_list_item_background #66333333 #FF333333 #FF444444 @@ -190,6 +192,8 @@ @color/black true @drawable/list_selected_holo_dark + @drawable/conversation_list_item_unread_background_dark + @drawable/conversation_list_item_background #66dddddd #ffdddddd #ffdddddd diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index d341e60d41..db943dfa70 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -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 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()))); } }