adding a helper function for updating conversations, if necessary
This commit is contained in:
parent
7a7b1aab32
commit
a013c110ec
|
@ -165,16 +165,7 @@ class MainActivity : SimpleActivity() {
|
|||
conversations_list.beVisibleIf(hasConversations)
|
||||
no_conversations_placeholder.beVisibleIf(!hasConversations)
|
||||
no_conversations_placeholder_2.beVisibleIf(!hasConversations)
|
||||
|
||||
ConversationsAdapter(this, conversations, conversations_list, conversations_fastscroller) {
|
||||
Intent(this, ThreadActivity::class.java).apply {
|
||||
putExtra(THREAD_ID, (it as Conversation).system_id)
|
||||
putExtra(THREAD_TITLE, it.title)
|
||||
startActivity(this)
|
||||
}
|
||||
}.apply {
|
||||
conversations_list.adapter = this
|
||||
}
|
||||
updateConversations(conversations)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,6 +178,23 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun updateConversations(conversations: ArrayList<Conversation>) {
|
||||
val currAdapter = conversations_list.adapter
|
||||
if (currAdapter == null) {
|
||||
ConversationsAdapter(this, conversations, conversations_list, conversations_fastscroller) {
|
||||
Intent(this, ThreadActivity::class.java).apply {
|
||||
putExtra(THREAD_ID, (it as Conversation).system_id)
|
||||
putExtra(THREAD_TITLE, it.title)
|
||||
startActivity(this)
|
||||
}
|
||||
}.apply {
|
||||
conversations_list.adapter = this
|
||||
}
|
||||
} else {
|
||||
(currAdapter as ConversationsAdapter).updateConversations(conversations)
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchNewConversation() {
|
||||
Intent(this, NewConversationActivity::class.java).apply {
|
||||
startActivity(this)
|
||||
|
|
|
@ -173,6 +173,15 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis
|
|||
}
|
||||
}
|
||||
|
||||
fun updateConversations(newConversations: ArrayList<Conversation>) {
|
||||
val oldHashCode = conversations.hashCode()
|
||||
val newHashCode = newConversations.hashCode()
|
||||
if (newHashCode != oldHashCode) {
|
||||
conversations = newConversations
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupView(view: View, conversation: Conversation) {
|
||||
view.apply {
|
||||
conversation_frame.isSelected = selectedKeys.contains(conversation.system_id)
|
||||
|
|
Loading…
Reference in New Issue