show the date/time above the messages at the thread view

This commit is contained in:
tibbi 2020-04-03 23:43:53 +02:00
parent 4c66a31370
commit feece9b90c
2 changed files with 14 additions and 2 deletions

View File

@ -6,10 +6,12 @@ import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
import com.simplemobiletools.smsmessenger.extensions.getMessages
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME
import com.simplemobiletools.smsmessenger.models.ThreadDateTime
import com.simplemobiletools.smsmessenger.models.ThreadItem
import kotlinx.android.synthetic.main.activity_thread.*
class ThreadActivity : SimpleActivity() {
private val MIN_DATE_TIME_DIFF_SECS = 3600
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -19,7 +21,17 @@ class ThreadActivity : SimpleActivity() {
val threadID = intent.getIntExtra(THREAD_ID, 0)
val messages = getMessages(threadID)
messages.sortBy { it.id }
val items = messages.toMutableList() as ArrayList<ThreadItem>
val items = ArrayList<ThreadItem>()
var prevDateTime = 0
messages.forEach {
// do not show the date/time above every message, only if the difference between the 2 messages is at least MIN_DATE_TIME_DIFF_SECS
if (it.date - prevDateTime > MIN_DATE_TIME_DIFF_SECS) {
items.add(ThreadDateTime(it.date))
prevDateTime = it.date
}
items.add(it)
}
ThreadAdapter(this, items, thread_messages_list, thread_messages_fastscroller) {

View File

@ -69,7 +69,7 @@ class ThreadAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = messages[position]
holder.bindView(item, true, true) { itemView, layoutPosition ->
holder.bindView(item, true, item is Message) { itemView, layoutPosition ->
if (item is ThreadDateTime) {
setupDateTime(itemView, item)
} else {