Improve loading on rotation

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-01-24 10:15:47 +01:00
parent e88b49b506
commit d74bc116ba
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
2 changed files with 17 additions and 3 deletions

View File

@ -67,7 +67,6 @@ class ContactsView<T : Any>(private val bundle: Bundle? = null) : BaseView() {
setHasOptionsMenu(true)
viewModel = viewModelProvider(factory).get(ContactsViewModel::class.java)
viewModel.conversationToken = bundle?.getString(BundleKeys.KEY_CONVERSATION_TOKEN)
val view = super.onCreateView(inflater, container)
// todo - change empty state magic
@ -137,7 +136,7 @@ class ContactsView<T : Any>(private val bundle: Bundle? = null) : BaseView() {
}
viewModel.loadContacts()
viewModel.initialize(bundle?.getString(BundleKeys.KEY_CONVERSATION_TOKEN))
return view
}

View File

@ -44,7 +44,15 @@ class ContactsViewModel constructor(
val contactsLiveData: MutableLiveData<List<Participant>> = MutableLiveData()
private var searchQuery: String? = null
var conversationToken: String? = null
private var conversationToken: String? = null
private var initialized = false
fun initialize(conversationToken: String?) {
if (!initialized || conversationToken != this.conversationToken) {
this.conversationToken = conversationToken
loadContacts()
}
}
fun setSearchQuery(query: String?) {
searchQuery = query
@ -77,6 +85,13 @@ class ContactsViewModel constructor(
it.displayName.toLowerCase()
}))
val selectedUserIds = selectedParticipants.map { it.userId }
for (participant in sortedList) {
if (participant.userId in selectedUserIds) {
participant.selected = true
}
}
contactsLiveData.postValue(sortedList)
}