forked from upstream-mirrors/quik
separate layout file for each message viewtype
This commit is contained in:
@@ -2,7 +2,6 @@ package com.moez.QKSMS.ui.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
@@ -14,9 +13,13 @@ class MessageAdapter(context: Context, data: OrderedRealmCollection<Message>?) :
|
||||
RealmRecyclerViewAdapter<Message, MessageViewHolder>(context, data, true) {
|
||||
val TAG = "MessageAdapter"
|
||||
|
||||
val VIEWTYPE_IN = 0
|
||||
val VIEWTYPE_OUT = 1
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MessageViewHolder {
|
||||
val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
return MessageViewHolder(layoutInflater.inflate(R.layout.message_list_item, parent, false))
|
||||
val layoutRes = if (viewType == VIEWTYPE_IN) R.layout.message_list_item_in else R.layout.message_list_item_out
|
||||
return MessageViewHolder(layoutInflater.inflate(layoutRes, parent, false))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: MessageViewHolder, position: Int) {
|
||||
@@ -27,6 +30,10 @@ class MessageAdapter(context: Context, data: OrderedRealmCollection<Message>?) :
|
||||
}
|
||||
|
||||
viewHolder.body.text = message.body
|
||||
viewHolder.body.gravity = if (message.isMe()) Gravity.RIGHT else Gravity.LEFT
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
val message = getItem(position)!!
|
||||
return if (message.isMe()) VIEWTYPE_OUT else VIEWTYPE_IN
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingTop="8dp"
|
||||
tools:listitem="@layout/message_list_item" />
|
||||
tools:listitem="@layout/message_list_item_out" />
|
||||
|
||||
</LinearLayout>
|
||||
+1
@@ -8,6 +8,7 @@
|
||||
<TextView
|
||||
android:id="@+id/message_body"
|
||||
android:padding="16dp"
|
||||
android:layout_marginEnd="56dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Hey! How's it going?" />
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message_body"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="56dp"
|
||||
android:gravity="right"
|
||||
android:padding="16dp"
|
||||
tools:text="Hey! How's it going?" />
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user