show the date/time above the messages at the thread view
This commit is contained in:
parent
4c66a31370
commit
feece9b90c
|
@ -6,10 +6,12 @@ import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
|
||||||
import com.simplemobiletools.smsmessenger.extensions.getMessages
|
import com.simplemobiletools.smsmessenger.extensions.getMessages
|
||||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME
|
import com.simplemobiletools.smsmessenger.helpers.THREAD_NAME
|
||||||
|
import com.simplemobiletools.smsmessenger.models.ThreadDateTime
|
||||||
import com.simplemobiletools.smsmessenger.models.ThreadItem
|
import com.simplemobiletools.smsmessenger.models.ThreadItem
|
||||||
import kotlinx.android.synthetic.main.activity_thread.*
|
import kotlinx.android.synthetic.main.activity_thread.*
|
||||||
|
|
||||||
class ThreadActivity : SimpleActivity() {
|
class ThreadActivity : SimpleActivity() {
|
||||||
|
private val MIN_DATE_TIME_DIFF_SECS = 3600
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
@ -19,7 +21,17 @@ class ThreadActivity : SimpleActivity() {
|
||||||
val threadID = intent.getIntExtra(THREAD_ID, 0)
|
val threadID = intent.getIntExtra(THREAD_ID, 0)
|
||||||
val messages = getMessages(threadID)
|
val messages = getMessages(threadID)
|
||||||
messages.sortBy { it.id }
|
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) {
|
ThreadAdapter(this, items, thread_messages_list, thread_messages_fastscroller) {
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ class ThreadAdapter(
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
val item = messages[position]
|
val item = messages[position]
|
||||||
holder.bindView(item, true, true) { itemView, layoutPosition ->
|
holder.bindView(item, true, item is Message) { itemView, layoutPosition ->
|
||||||
if (item is ThreadDateTime) {
|
if (item is ThreadDateTime) {
|
||||||
setupDateTime(itemView, item)
|
setupDateTime(itemView, item)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue