split messages between received and sent

This commit is contained in:
tibbi 2020-04-03 21:44:18 +02:00
parent 4b16fde919
commit fc3e72d390
5 changed files with 45 additions and 4 deletions

View File

@ -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>

View File

@ -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

View File

@ -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
}

View File

@ -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>

View File

@ -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>