split messages between received and sent
This commit is contained in:
parent
4b16fde919
commit
fc3e72d390
|
@ -8,8 +8,10 @@ import com.simplemobiletools.commons.views.FastScroller
|
|||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||
import com.simplemobiletools.smsmessenger.helpers.RECEIVED_MESSAGE
|
||||
import com.simplemobiletools.smsmessenger.helpers.SENT_MESSAGE
|
||||
import com.simplemobiletools.smsmessenger.models.Message
|
||||
import kotlinx.android.synthetic.main.item_thread_message.view.*
|
||||
import kotlinx.android.synthetic.main.item_received_message.view.*
|
||||
|
||||
class ThreadAdapter(
|
||||
activity: SimpleActivity, var messages: ArrayList<Message>,
|
||||
|
@ -48,7 +50,14 @@ class ThreadAdapter(
|
|||
|
||||
override fun onActionModeDestroyed() {}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_thread_message, parent)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val layout = if (viewType == RECEIVED_MESSAGE) {
|
||||
R.layout.item_received_message
|
||||
} else {
|
||||
R.layout.item_sent_message
|
||||
}
|
||||
return createViewHolder(layout, parent)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val message = messages[position]
|
||||
|
@ -60,6 +69,14 @@ class ThreadAdapter(
|
|||
|
||||
override fun getItemCount() = messages.size
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return if (messages[position].isReceivedMessage()) {
|
||||
RECEIVED_MESSAGE
|
||||
} else {
|
||||
SENT_MESSAGE
|
||||
}
|
||||
}
|
||||
|
||||
private fun getItemWithKey(key: Int): Message? = messages.firstOrNull { it.id == key }
|
||||
|
||||
private fun getSelectedItems() = messages.filter { selectedKeys.contains(it.id) } as ArrayList<Message>
|
||||
|
|
|
@ -2,3 +2,7 @@ package com.simplemobiletools.smsmessenger.helpers
|
|||
|
||||
const val THREAD_ID = "thread_id"
|
||||
const val THREAD_NAME = "thread_name"
|
||||
|
||||
// message types for the thread list view
|
||||
const val RECEIVED_MESSAGE = 1
|
||||
const val SENT_MESSAGE = 2
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package com.simplemobiletools.smsmessenger.models
|
||||
|
||||
import android.provider.Telephony
|
||||
|
||||
data class Message(
|
||||
val id: Int, val subject: String, val body: String, val type: Int, val address: String, val date: Int, val read: Boolean,
|
||||
val thread: Int
|
||||
)
|
||||
) {
|
||||
fun isReceivedMessage() = type == Telephony.Sms.MESSAGE_TYPE_INBOX
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/thread_message_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/thread_message_body"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
tools:text="Received message" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -11,6 +11,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
tools:text="Hey buddy!" />
|
||||
tools:text="Sent message" />
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in New Issue