mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-18 12:40:46 +01:00
update the conversation if something changes, avoid recreating it
This commit is contained in:
parent
ac7d2afbb6
commit
71d7085ddb
@ -41,6 +41,7 @@ import com.simplemobiletools.smsmessenger.helpers.*
|
|||||||
import com.simplemobiletools.smsmessenger.models.*
|
import com.simplemobiletools.smsmessenger.models.*
|
||||||
import com.simplemobiletools.smsmessenger.receivers.SmsStatusDeliveredReceiver
|
import com.simplemobiletools.smsmessenger.receivers.SmsStatusDeliveredReceiver
|
||||||
import com.simplemobiletools.smsmessenger.receivers.SmsStatusSentReceiver
|
import com.simplemobiletools.smsmessenger.receivers.SmsStatusSentReceiver
|
||||||
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import kotlinx.android.synthetic.main.activity_thread.*
|
import kotlinx.android.synthetic.main.activity_thread.*
|
||||||
import kotlinx.android.synthetic.main.item_attachment.view.*
|
import kotlinx.android.synthetic.main.item_attachment.view.*
|
||||||
import kotlinx.android.synthetic.main.item_selected_contact.view.*
|
import kotlinx.android.synthetic.main.item_selected_contact.view.*
|
||||||
@ -221,8 +222,13 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
val adapter = ThreadAdapter(this, threadItems, thread_messages_list, thread_messages_fastscroller) {}
|
val currAdapter = thread_messages_list.adapter
|
||||||
thread_messages_list.adapter = adapter
|
if (currAdapter == null) {
|
||||||
|
val adapter = ThreadAdapter(this, threadItems, thread_messages_list, thread_messages_fastscroller) {}
|
||||||
|
thread_messages_list.adapter = adapter
|
||||||
|
} else {
|
||||||
|
(currAdapter as ThreadAdapter).updateMessages(threadItems)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleContactsHelper(this).getAvailableContacts(false) { contacts ->
|
SimpleContactsHelper(this).getAvailableContacts(false) { contacts ->
|
||||||
|
@ -195,10 +195,13 @@ class ThreadAdapter(activity: SimpleActivity, var messages: ArrayList<ThreadItem
|
|||||||
|
|
||||||
private fun isThreadDateTime(position: Int) = messages.getOrNull(position) is ThreadDateTime
|
private fun isThreadDateTime(position: Int) = messages.getOrNull(position) is ThreadDateTime
|
||||||
|
|
||||||
override fun onViewRecycled(holder: ViewHolder) {
|
fun updateMessages(newMessages: ArrayList<ThreadItem>) {
|
||||||
super.onViewRecycled(holder)
|
val oldHashCode = messages.hashCode()
|
||||||
if (!activity.isDestroyed && !activity.isFinishing && holder.itemView.thread_message_sender_photo != null) {
|
val newHashCode = newMessages.hashCode()
|
||||||
Glide.with(activity).clear(holder.itemView.thread_message_sender_photo)
|
if (newHashCode != oldHashCode) {
|
||||||
|
messages = newMessages
|
||||||
|
notifyDataSetChanged()
|
||||||
|
recyclerView.scrollToPosition(messages.size-1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,4 +350,11 @@ class ThreadAdapter(activity: SimpleActivity, var messages: ArrayList<ThreadItem
|
|||||||
setTextColor(textColor)
|
setTextColor(textColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onViewRecycled(holder: ViewHolder) {
|
||||||
|
super.onViewRecycled(holder)
|
||||||
|
if (!activity.isDestroyed && !activity.isFinishing && holder.itemView.thread_message_sender_photo != null) {
|
||||||
|
Glide.with(activity).clear(holder.itemView.thread_message_sender_photo)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user