Prevent blinking in chat rooms list

This commit is contained in:
Sylvain Berfini 2023-03-27 13:01:48 +02:00
parent b2a7ae7629
commit 455165f00b
4 changed files with 16 additions and 4 deletions

View file

@ -33,6 +33,7 @@ import org.linphone.activities.main.viewmodels.ListTopBarViewModel
import org.linphone.core.ChatRoom
import org.linphone.databinding.ChatRoomListCellBinding
import org.linphone.utils.Event
import org.linphone.utils.LinphoneUtils
class ChatRoomsListAdapter(
selectionVM: ListTopBarViewModel,
@ -56,6 +57,11 @@ class ChatRoomsListAdapter(
(holder as ViewHolder).bind(getItem(position))
}
override fun getItemId(position: Int): Long {
val room = getItem(position)
return LinphoneUtils.getChatRoomId(room).hashCode().toLong()
}
fun forwardPending(pending: Boolean) {
isForwardPending = pending
notifyItemRangeChanged(0, itemCount)

View file

@ -156,7 +156,9 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
_adapter = ChatRoomsListAdapter(listSelectionViewModel, viewLifecycleOwner)
// SubmitList is done on a background thread
// We need this adapter data observer to know when to scroll
adapter.setHasStableIds(true)
adapter.registerAdapterDataObserver(observer)
binding.chatList.setHasFixedSize(true)
binding.chatList.adapter = adapter

View file

@ -192,7 +192,7 @@ class NotificationsManager(private val context: Context) {
dismissChatNotification(chatRoom)
}
} else {
val notificationId = chatRoom.creationTime.toInt()
val notificationId = getNotificationIdForChat(chatRoom)
if (chatBubbleNotifications.contains(notificationId)) {
Log.i("[Notifications Manager] Chat room [$chatRoom] has been marked as read but no notifiable found, not removing notification because of a chat bubble")
} else {
@ -635,7 +635,7 @@ class NotificationsManager(private val context: Context) {
/* Chat related */
private fun getNotificationIdForChat(chatRoom: ChatRoom): Int {
return chatRoom.creationTime.toInt()
return LinphoneUtils.getChatRoomId(chatRoom).hashCode()
}
private fun displayChatNotifiable(room: ChatRoom, notifiable: Notifiable) {
@ -784,7 +784,7 @@ class NotificationsManager(private val context: Context) {
cancel(notifiable.notificationId, CHAT_TAG)
return true
} else {
val previousNotificationId = previousChatNotifications.find { id -> id == room.creationTime.toInt() }
val previousNotificationId = previousChatNotifications.find { id -> id == getNotificationIdForChat(room) }
if (previousNotificationId != null) {
if (chatBubbleNotifications.contains(previousNotificationId)) {
Log.i("[Notifications Manager] Found previous notification with same ID [$previousNotificationId] but not cancelling it as it's ID is in chat bubbles list")
@ -799,7 +799,7 @@ class NotificationsManager(private val context: Context) {
}
fun changeDismissNotificationUponReadForChatRoom(chatRoom: ChatRoom, dismiss: Boolean) {
val notificationId = chatRoom.creationTime.toInt()
val notificationId = getNotificationIdForChat(chatRoom)
if (dismiss) {
Log.i("[Notifications Manager] Allow notification with id [$notificationId] to be dismissed when chat room will be marked as read, used for chat bubble")
chatBubbleNotifications.add(notificationId)

View file

@ -229,6 +229,10 @@ class LinphoneUtils {
chatRoom1.peerAddress.weakEqual(chatRoom2.peerAddress)
}
fun getChatRoomId(room: ChatRoom): String {
return getChatRoomId(room.localAddress, room.peerAddress)
}
fun getChatRoomId(localAddress: Address, remoteAddress: Address): String {
val localSipUri = localAddress.clone()
localSipUri.clean()