forked from upstream-mirrors/quik
create separate avatarviews for showing single or multiple contacts
This commit is contained in:
@@ -13,24 +13,23 @@ import io.realm.RealmRecyclerViewAdapter
|
|||||||
class ConversationAdapter(context: Context, data: OrderedRealmCollection<Conversation>?) :
|
class ConversationAdapter(context: Context, data: OrderedRealmCollection<Conversation>?) :
|
||||||
RealmRecyclerViewAdapter<Conversation, ConversationViewHolder>(context, data, true) {
|
RealmRecyclerViewAdapter<Conversation, ConversationViewHolder>(context, data, true) {
|
||||||
|
|
||||||
val mContext = context
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ConversationViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ConversationViewHolder {
|
||||||
val layoutInflater = mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
return ConversationViewHolder(layoutInflater.inflate(R.layout.conversation_list_item, parent, false))
|
return ConversationViewHolder(layoutInflater.inflate(R.layout.conversation_list_item, parent, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(viewHolder: ConversationViewHolder, position: Int) {
|
override fun onBindViewHolder(viewHolder: ConversationViewHolder, position: Int) {
|
||||||
val conversation = getItem(position)
|
val conversation = getItem(position)!!
|
||||||
|
|
||||||
viewHolder.itemView.setOnClickListener {
|
viewHolder.itemView.setOnClickListener {
|
||||||
val intent = Intent(mContext, MessageListActivity::class.java)
|
val intent = Intent(context, MessageListActivity::class.java)
|
||||||
intent.putExtra("thread_id", conversation?.id)
|
intent.putExtra("thread_id", conversation.id)
|
||||||
|
|
||||||
mContext.startActivity(intent)
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewHolder.title.text = conversation?.getTitle()
|
viewHolder.avatar.contacts = conversation.contacts
|
||||||
viewHolder.snippet.text = conversation?.snippet
|
viewHolder.title.text = conversation.getTitle()
|
||||||
|
viewHolder.snippet.text = conversation.snippet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,11 @@ import android.support.v7.widget.RecyclerView
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.ui.view.GroupAvatarView
|
||||||
|
|
||||||
class ConversationViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
class ConversationViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
||||||
|
val avatar: GroupAvatarView = view.findViewById(R.id.avatars)
|
||||||
val title: TextView = view.findViewById(R.id.title)
|
val title: TextView = view.findViewById(R.id.title)
|
||||||
val snippet: TextView = view.findViewById(R.id.snippet)
|
val snippet: TextView = view.findViewById(R.id.snippet)
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.dagger.AppComponentManager
|
import com.moez.QKSMS.dagger.AppComponentManager
|
||||||
|
import com.moez.QKSMS.data.model.Contact
|
||||||
import com.moez.QKSMS.data.model.Message
|
import com.moez.QKSMS.data.model.Message
|
||||||
import com.moez.QKSMS.util.DateFormatter
|
import com.moez.QKSMS.util.DateFormatter
|
||||||
import io.realm.OrderedRealmCollection
|
import io.realm.OrderedRealmCollection
|
||||||
@@ -38,6 +39,7 @@ class MessageAdapter(context: Context, data: OrderedRealmCollection<Message>?) :
|
|||||||
Log.i(TAG, message.toString())
|
Log.i(TAG, message.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewHolder.avatar.contact = Contact()
|
||||||
viewHolder.body.text = message.body
|
viewHolder.body.text = message.body
|
||||||
viewHolder.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
viewHolder.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import android.support.v7.widget.RecyclerView
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.ui.view.AvatarView
|
||||||
|
|
||||||
class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
||||||
|
val avatar: AvatarView = view.findViewById(R.id.avatar)
|
||||||
val body: TextView = view.findViewById(R.id.body)
|
val body: TextView = view.findViewById(R.id.body)
|
||||||
val timestamp: TextView = view.findViewById(R.id.timestamp)
|
val timestamp: TextView = view.findViewById(R.id.timestamp)
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,36 @@ package com.moez.QKSMS.ui.view
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.widget.ImageView
|
import android.view.View
|
||||||
|
import android.widget.FrameLayout
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.data.model.Contact
|
||||||
|
import kotlinx.android.synthetic.main.avatar_view.view.*
|
||||||
|
|
||||||
class AvatarView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : ImageView(context, attrs, defStyleAttr) {
|
class AvatarView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : FrameLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
var contact: Contact? = null
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
updateView()
|
||||||
|
}
|
||||||
|
|
||||||
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||||
constructor(context: Context) : this(context, null, 0)
|
constructor(context: Context) : this(context, null, 0)
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (!isInEditMode) {
|
||||||
|
View.inflate(context, R.layout.avatar_view, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFinishInflate() {
|
||||||
|
super.onFinishInflate()
|
||||||
|
updateView()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateView() {
|
||||||
|
initial.text = if (contact?.name?.length ?: 0 > 0) contact?.name?.substring(0, 1) else "?"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.moez.QKSMS.ui.view
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.support.constraint.ConstraintLayout
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.data.model.Contact
|
||||||
|
import io.realm.RealmList
|
||||||
|
import kotlinx.android.synthetic.main.group_avatar_view.view.*
|
||||||
|
|
||||||
|
class GroupAvatarView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : ConstraintLayout(context, attrs, defStyleAttr) {
|
||||||
|
|
||||||
|
var contacts: RealmList<Contact> = RealmList()
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
updateView()
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||||
|
constructor(context: Context) : this(context, null, 0)
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (!isInEditMode) {
|
||||||
|
View.inflate(context, R.layout.group_avatar_view, this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFinishInflate() {
|
||||||
|
super.onFinishInflate()
|
||||||
|
updateView()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateView() {
|
||||||
|
avatar1.visibility = if (contacts.size > 0) View.VISIBLE else View.GONE
|
||||||
|
avatar1.contact = if (contacts.size > 0) contacts[0] else null
|
||||||
|
avatar2.visibility = if (contacts.size > 1) View.VISIBLE else View.GONE
|
||||||
|
avatar2.contact = if (contacts.size > 1) contacts[1] else null
|
||||||
|
avatar3.visibility = if (contacts.size > 2) View.VISIBLE else View.GONE
|
||||||
|
avatar3.contact = if (contacts.size > 2) contacts[2] else null
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge android:id="@+id/avatar"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/textSecondary"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:parentTag="com.moez.QKSMS.ui.view.AvatarView">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/photo"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/initial"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
tools:text="M" />
|
||||||
|
|
||||||
|
</merge>
|
||||||
@@ -10,12 +10,11 @@
|
|||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingTop="8dp">
|
android:paddingTop="8dp">
|
||||||
|
|
||||||
<com.moez.QKSMS.ui.view.AvatarView
|
<com.moez.QKSMS.ui.view.GroupAvatarView
|
||||||
android:id="@+id/avatar"
|
android:id="@+id/avatars"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_gravity="top"
|
android:layout_gravity="top" />
|
||||||
android:background="@color/textSecondary" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
tools:parentTag="com.moez.QKSMS.ui.view.GroupAvatarView">
|
||||||
|
|
||||||
|
<com.moez.QKSMS.ui.view.AvatarView
|
||||||
|
android:id="@+id/avatar1"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/avatar2"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<com.moez.QKSMS.ui.view.AvatarView
|
||||||
|
android:id="@+id/avatar2"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/avatar3"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/avatar1"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<com.moez.QKSMS.ui.view.AvatarView
|
||||||
|
android:id="@+id/avatar3"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/avatar2"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/avatar2" />
|
||||||
|
|
||||||
|
</merge>
|
||||||
@@ -3,26 +3,41 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:gravity="start|bottom"
|
||||||
android:padding="16dp">
|
android:orientation="horizontal"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:paddingEnd="56dp"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="16dp">
|
||||||
|
|
||||||
<TextView
|
<com.moez.QKSMS.ui.view.AvatarView
|
||||||
android:id="@+id/body"
|
android:id="@+id/avatar"
|
||||||
style="@style/TextPrimary"
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginEnd="16dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="56dp"
|
android:orientation="vertical">
|
||||||
android:layout_gravity="start"
|
|
||||||
android:gravity="start"
|
|
||||||
tools:text="Hey! How's it going?" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/timestamp"
|
android:id="@+id/body"
|
||||||
style="@style/TextSecondary"
|
style="@style/TextPrimary"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="56dp"
|
android:layout_gravity="start"
|
||||||
android:gravity="start"
|
android:gravity="start"
|
||||||
tools:text="2:50pm" />
|
tools:text="Hey! How's it going?" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timestamp"
|
||||||
|
style="@style/TextSecondary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="start"
|
||||||
|
tools:text="2:50pm" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -3,26 +3,41 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:gravity="end|bottom"
|
||||||
android:padding="16dp">
|
android:orientation="horizontal"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:paddingStart="56dp"
|
||||||
|
android:paddingTop="16dp">
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/body"
|
|
||||||
style="@style/TextPrimary"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:orientation="vertical">
|
||||||
android:layout_marginStart="56dp"
|
|
||||||
android:gravity="start"
|
|
||||||
tools:text="Hey! How's it going?" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/timestamp"
|
android:id="@+id/body"
|
||||||
style="@style/TextSecondary"
|
style="@style/TextPrimary"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="56dp"
|
android:layout_gravity="end"
|
||||||
android:gravity="end"
|
android:gravity="start"
|
||||||
tools:text="2:50pm" />
|
tools:text="Hey! How's it going?" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timestamp"
|
||||||
|
style="@style/TextSecondary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="end"
|
||||||
|
tools:text="2:50pm" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.moez.QKSMS.ui.view.AvatarView
|
||||||
|
android:id="@+id/avatar"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginStart="16dp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user