1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-18 21:06:45 -06:00

Use text color, font face and red dot to differentiate unread messages (#2027)

This commit is contained in:
Mikołaj Pich 2022-10-28 11:09:38 +02:00 committed by GitHub
parent 7bee10d5ce
commit 515a3973b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 11 deletions

View File

@ -1,15 +1,18 @@
package io.github.wulkanowy.ui.modules.message.tab
import android.content.res.ColorStateList
import android.graphics.Typeface
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.CompoundButton
import androidx.core.view.isVisible
import androidx.core.widget.ImageViewCompat
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import io.github.wulkanowy.R
import io.github.wulkanowy.databinding.ItemMessageBinding
import io.github.wulkanowy.databinding.ItemMessageChipsBinding
import io.github.wulkanowy.utils.getThemeAttrColor
import io.github.wulkanowy.utils.toFormattedString
import javax.inject.Inject
@ -85,21 +88,35 @@ class MessageTabAdapter @Inject constructor() :
val message = item.message
with(holder.binding) {
val style = if (message.unread) Typeface.BOLD else Typeface.NORMAL
val normalFont = Typeface.create("sans-serif", Typeface.NORMAL)
val boldFont = Typeface.create("sans-serif-black", Typeface.NORMAL)
val primaryColor = root.context.getThemeAttrColor(android.R.attr.textColorPrimary)
val secondaryColor = root.context.getThemeAttrColor(android.R.attr.textColorSecondary)
val currentFont = if (message.unread) boldFont else normalFont
val currentTextColor = if (message.unread) primaryColor else secondaryColor
with(messageItemAuthor) {
text = message.correspondents
setTypeface(null, style)
setTextColor(currentTextColor)
typeface = currentFont
}
messageItemSubject.run {
with(messageItemSubject) {
text = message.subject.ifBlank { context.getString(R.string.message_no_subject) }
setTypeface(null, style)
setTextColor(currentTextColor)
typeface = currentFont
}
messageItemDate.run {
with(messageItemDate) {
text = message.date.toFormattedString()
setTypeface(null, style)
setTextColor(currentTextColor)
typeface = currentFont
}
messageItemAttachmentIcon.isVisible = message.hasAttachments
with(messageItemAttachmentIcon) {
ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(currentTextColor))
isVisible = message.hasAttachments
}
messageItemUnreadIndicator.isVisible = message.unread
root.setOnClickListener {
holder.bindingAdapterPosition.let {
@ -111,7 +128,7 @@ class MessageTabAdapter @Inject constructor() :
root.setOnLongClickListener {
onLongItemClickListener(item)
return@setOnLongClickListener true
true
}
with(messageItemCheckbox) {

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorPrimary" />
<size
android:width="100dp"
android:height="100dp" />
</shape>

View File

@ -30,6 +30,7 @@
android:layout_marginEnd="10dp"
android:ellipsize="end"
android:singleLine="true"
android:textColor="?android:textColorSecondary"
android:textSize="15sp"
app:layout_constraintEnd_toStartOf="@+id/messageItemDate"
app:layout_constraintStart_toEndOf="@id/messageItemCheckbox"
@ -40,10 +41,13 @@
android:id="@+id/messageItemDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:gravity="end"
android:textColor="?android:textColorSecondary"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@id/messageItemUnreadIndicator"
app:layout_constraintTop_toTopOf="parent"
app:layout_goneMarginEnd="0dp"
tools:text="@tools:sample/date/ddmmyy" />
<TextView
@ -69,9 +73,21 @@
android:layout_height="16dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/messageItemSubject"
app:layout_constraintEnd_toEndOf="@id/messageItemDate"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_attachment"
app:tint="?colorOnBackground"
app:tint="?android:textColorSecondary"
tools:ignore="ContentDescription"
tools:visibility="visible" />
<ImageView
android:id="@+id/messageItemUnreadIndicator"
android:layout_width="10dp"
android:layout_height="10dp"
android:src="@drawable/ic_circle"
app:layout_constraintBottom_toBottomOf="@id/messageItemDate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/messageItemDate"
app:tint="?colorPrimary"
tools:ignore="ContentDescription"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>