From feece9b90c87390c23bb7f45df2732543a70a628 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 3 Apr 2020 23:43:53 +0200 Subject: [PATCH] show the date/time above the messages at the thread view --- .../smsmessenger/activities/ThreadActivity.kt | 14 +++++++++++++- .../smsmessenger/adapters/ThreadAdapter.kt | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index e876f789..62432a65 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -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 + + val items = ArrayList() + 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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt index 77d34f28..987cb88b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt @@ -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 {