forked from upstream-mirrors/quik
Improve readability for unread state
This commit is contained in:
@@ -10,6 +10,7 @@ import com.moez.QKSMS.data.model.Message
|
||||
import com.moez.QKSMS.data.repository.MessageRepository
|
||||
import com.moez.QKSMS.ui.messages.MessageListActivity
|
||||
import com.moez.QKSMS.util.DateFormatter
|
||||
import com.moez.QKSMS.util.ThemeManager
|
||||
import com.moez.QKSMS.util.extensions.getColorCompat
|
||||
import io.realm.OrderedRealmCollection
|
||||
import io.realm.RealmList
|
||||
@@ -21,14 +22,24 @@ class ConversationAdapter(data: OrderedRealmCollection<Message>?) : RealmRecycle
|
||||
@Inject lateinit var context: Context
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var dateFormatter: DateFormatter
|
||||
@Inject lateinit var themeManager: ThemeManager
|
||||
|
||||
init {
|
||||
AppComponentManager.appComponent.inject(this)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ConversationViewHolder {
|
||||
val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
return ConversationViewHolder(layoutInflater.inflate(R.layout.conversation_list_item, parent, false))
|
||||
val layoutRes = when(viewType) {
|
||||
0 -> R.layout.conversation_list_item
|
||||
else -> R.layout.conversation_list_item_unread
|
||||
}
|
||||
|
||||
val layoutInflater = LayoutInflater.from(context)
|
||||
val viewHolder = ConversationViewHolder(layoutInflater.inflate(layoutRes, parent, false))
|
||||
|
||||
if (viewType == 1) viewHolder.date.setTextColor(themeManager.color)
|
||||
|
||||
return viewHolder
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ConversationViewHolder, position: Int) {
|
||||
@@ -40,14 +51,21 @@ class ConversationAdapter(data: OrderedRealmCollection<Message>?) : RealmRecycle
|
||||
.putExtra("threadId", message.threadId))
|
||||
}
|
||||
|
||||
val textColor = context.getColorCompat(if (message.read) R.color.textTertiary else R.color.textPrimary)
|
||||
val dateColor = if (message.read) context.getColorCompat(R.color.textTertiary) else themeManager.color
|
||||
val snippetColor = context.getColorCompat(if (message.read) R.color.textTertiary else R.color.textPrimary)
|
||||
|
||||
viewHolder.avatar.contacts = conversation?.contacts ?: RealmList()
|
||||
viewHolder.title.text = conversation?.getTitle()
|
||||
|
||||
viewHolder.date.text = dateFormatter.getMessageTimestamp(message.date)
|
||||
viewHolder.date.setTextColor(textColor)
|
||||
viewHolder.date.setTextColor(dateColor)
|
||||
|
||||
viewHolder.snippet.text = message.body
|
||||
viewHolder.snippet.setTextColor(textColor)
|
||||
viewHolder.snippet.setTextColor(snippetColor)
|
||||
viewHolder.snippet.maxLines = if (message.read) 1 else 3
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (getItem(position)!!.read) 0 else 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<com.moez.QKSMS.ui.view.GroupAvatarView
|
||||
android:id="@+id/avatars"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="top" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
style="@style/TextPrimary"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_weight="1"
|
||||
android:textStyle="bold"
|
||||
tools:text="Moez Bhatti" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date"
|
||||
style="@style/TextTertiary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/textPrimary"
|
||||
android:textStyle="bold"
|
||||
tools:text="Oct 11" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/snippet"
|
||||
style="@style/TextSecondary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:ellipsize="end"
|
||||
android:textColor="@color/textPrimary"
|
||||
android:textStyle="bold"
|
||||
tools:text="Hey! How's it going?" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user