This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreateViewHolder(parent: ViewGroup, itemViewType: Int): MessageViewHolder { | |
val messageParent = LinearLayout(parent.context) | |
messageParent.orientation = LinearLayout.VERTICAL | |
messageParent.setPadding(0,0,0,80) | |
if (itemViewType and 1 >= 1){ | |
// here, you should add ImageView | |
// for the sake of easiness, let me add simple textview | |
val tvPhoto = TextView(parent.context) | |
tvPhoto.layoutParams = LinearLayout.LayoutParams(WRAP_CONTENT,WRAP_CONTENT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun getItemViewType(position: Int): Int { | |
val message = list[position] | |
var flags = 0 | |
if (message.attachment.isPhoto()) | |
flags = flags or 1 | |
if (message.attachment.isMusic()) | |
flags = flags or 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Message(val id: Long = 0L, | |
val fromId: Long = 0L, | |
val text: String = "", | |
val attachment: Attachment = Attachment()) | |
data class Attachment(val type: Int = 0) { | |
companion object { | |
val TYPE_PHOTO = 1 | |
val TYPE_MUSIC = 2 | |
val TYPE_CONTACT = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageUI(val flags: Int){ | |
fun createMessageUI(context: Context):View{ | |
val verticalLayout = LinearLayout(context) | |
verticalLayout.layoutParams = ViewGroup.LayoutParams(matchParent, wrapContent) | |
verticalLayout.orientation = LinearLayout.VERTICAL | |
if (flags and 1 >= 0){ | |
// add reply preview | |
val tvReply = TextView(context) | |
tvReply.text = "Reply" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Message(var id: Long = 0L, | |
var fromId: Long = 0L, // message owner -> Account.id | |
var date: Long = 0L, // sent date | |
var text: String = "", // message content | |
var replyId: Long = 0L, // id of replied message | |
var replyMessage: Message? = null, // replied message | |
var attachment: Attachment? = null | |
){ | |
companion object { | |
// statuses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun getItemViewType(position: Int): Int { | |
val message = list[position] | |
when(message.type){ | |
TEXT -> return 0 | |
IMAGE -> return 1 | |
VIDEO -> return 2 | |
/// and many more | |
} | |
return super.getItemViewType(position) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageAdapter() : RecyclerView.Adapter<MessageAdapter.MessageViewHolder>() { | |
private var list: MultiSortedList<Message> | |
init { | |
val updateCallback = object : MultiSortedList.UpdateCallback<Message> { | |
override fun sortBy(i1: Message, i2: Message): Int { | |
return i2.date.compareTo(i1.date) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Message(var id: Long, var date: Long, var text: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.v7.widget.RecyclerView | |
/** | |
* Created by abduaziz on 6/14/18. | |
* | |
* MultiSortedList is a wrapper component to ArrayList that keeps its elements in a sorted order | |
* using UpdateCallbackInterface. It is intended to be used inside recycler view adapters. | |
* | |
* */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" android:layout_height="match_parent"> | |
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1" /> | |
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2" /> | |
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3" /> | |
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="4" /> | |
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5" /> | |
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="6" /> | |
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="7" /> |