Fixed unecessary refresh in lists, causing blinking
This commit is contained in:
parent
5dfc18a78d
commit
6537e5fc23
4 changed files with 2 additions and 24 deletions
|
@ -219,14 +219,6 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
||||||
adapter.submitList(chatRooms)
|
adapter.submitList(chatRooms)
|
||||||
}
|
}
|
||||||
|
|
||||||
listViewModel.contactsUpdatedEvent.observe(
|
|
||||||
viewLifecycleOwner
|
|
||||||
) {
|
|
||||||
it.consume {
|
|
||||||
adapter.notifyItemRangeChanged(0, adapter.itemCount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
adapter.selectedChatRoomEvent.observe(
|
adapter.selectedChatRoomEvent.observe(
|
||||||
viewLifecycleOwner
|
viewLifecycleOwner
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.main.viewmodels.MessageNotifierViewModel
|
import org.linphone.activities.main.viewmodels.MessageNotifierViewModel
|
||||||
import org.linphone.compatibility.Compatibility
|
import org.linphone.compatibility.Compatibility
|
||||||
import org.linphone.contact.ContactsUpdatedListenerStub
|
|
||||||
import org.linphone.core.*
|
import org.linphone.core.*
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
|
@ -33,10 +32,6 @@ import org.linphone.utils.LinphoneUtils
|
||||||
class ChatRoomsListViewModel : MessageNotifierViewModel() {
|
class ChatRoomsListViewModel : MessageNotifierViewModel() {
|
||||||
val chatRooms = MutableLiveData<ArrayList<ChatRoomViewModel>>()
|
val chatRooms = MutableLiveData<ArrayList<ChatRoomViewModel>>()
|
||||||
|
|
||||||
val contactsUpdatedEvent: MutableLiveData<Event<Boolean>> by lazy {
|
|
||||||
MutableLiveData<Event<Boolean>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
val fileSharingPending = MutableLiveData<Boolean>()
|
val fileSharingPending = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
val textSharingPending = MutableLiveData<Boolean>()
|
val textSharingPending = MutableLiveData<Boolean>()
|
||||||
|
@ -45,13 +40,6 @@ class ChatRoomsListViewModel : MessageNotifierViewModel() {
|
||||||
|
|
||||||
val groupChatAvailable: Boolean = LinphoneUtils.isGroupChatAvailable()
|
val groupChatAvailable: Boolean = LinphoneUtils.isGroupChatAvailable()
|
||||||
|
|
||||||
private val contactsUpdatedListener = object : ContactsUpdatedListenerStub() {
|
|
||||||
override fun onContactsUpdated() {
|
|
||||||
Log.i("[Chat Rooms] Contacts have changed")
|
|
||||||
contactsUpdatedEvent.value = Event(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
||||||
override fun onChatRoomStateChanged(core: Core, chatRoom: ChatRoom, state: ChatRoom.State) {
|
override fun onChatRoomStateChanged(core: Core, chatRoom: ChatRoom, state: ChatRoom.State) {
|
||||||
if (state == ChatRoom.State.Created) {
|
if (state == ChatRoom.State.Created) {
|
||||||
|
@ -102,12 +90,10 @@ class ChatRoomsListViewModel : MessageNotifierViewModel() {
|
||||||
init {
|
init {
|
||||||
updateChatRooms()
|
updateChatRooms()
|
||||||
coreContext.core.addListener(listener)
|
coreContext.core.addListener(listener)
|
||||||
coreContext.contactsManager.addListener(contactsUpdatedListener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
chatRooms.value.orEmpty().forEach(ChatRoomViewModel::destroy)
|
chatRooms.value.orEmpty().forEach(ChatRoomViewModel::destroy)
|
||||||
coreContext.contactsManager.removeListener(contactsUpdatedListener)
|
|
||||||
coreContext.core.removeListener(listener)
|
coreContext.core.removeListener(listener)
|
||||||
|
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
|
|
|
@ -136,6 +136,6 @@ private class ContactDiffCallback : DiffUtil.ItemCallback<ContactViewModel>() {
|
||||||
oldItem: ContactViewModel,
|
oldItem: ContactViewModel,
|
||||||
newItem: ContactViewModel
|
newItem: ContactViewModel
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return false // For headers
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,6 +152,6 @@ private class CallLogDiffCallback : DiffUtil.ItemCallback<GroupedCallLogData>()
|
||||||
oldItem: GroupedCallLogData,
|
oldItem: GroupedCallLogData,
|
||||||
newItem: GroupedCallLogData
|
newItem: GroupedCallLogData
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return false // For headers
|
return oldItem.callLogs.size == newItem.callLogs.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue