forked from upstream-mirrors/quik
Create base adapter for messagelist
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
package com.moez.QKSMS.model
|
||||||
|
|
||||||
|
import io.realm.RealmObject
|
||||||
|
import io.realm.annotations.PrimaryKey
|
||||||
|
|
||||||
|
open class Message(
|
||||||
|
|
||||||
|
@PrimaryKey var id: Long = 0,
|
||||||
|
var body: String = ""
|
||||||
|
|
||||||
|
) : RealmObject()
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.moez.QKSMS.ui.messages
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.model.Message
|
||||||
|
import io.realm.OrderedRealmCollection
|
||||||
|
import io.realm.RealmRecyclerViewAdapter
|
||||||
|
|
||||||
|
class MessageAdapter(context: Context, data: OrderedRealmCollection<Message>?) :
|
||||||
|
RealmRecyclerViewAdapter<Message, MessageViewHolder>(context, data, true) {
|
||||||
|
|
||||||
|
val mContext = context
|
||||||
|
|
||||||
|
override fun onBindViewHolder(viewHolder: MessageViewHolder, position: Int) {
|
||||||
|
viewHolder.body.text = getItem(position)?.body
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MessageViewHolder {
|
||||||
|
val layoutInflater = mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
|
return MessageViewHolder(layoutInflater.inflate(R.layout.message_list_item, parent, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.moez.QKSMS.ui.messages
|
||||||
|
|
||||||
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.TextView
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
|
||||||
|
class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
||||||
|
val body = view.findViewById(R.id.message_body) as TextView
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/message_body"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user