Prevent blinking in chat rooms list
This commit is contained in:
parent
b2a7ae7629
commit
455165f00b
4 changed files with 16 additions and 4 deletions
|
@ -33,6 +33,7 @@ import org.linphone.activities.main.viewmodels.ListTopBarViewModel
|
||||||
import org.linphone.core.ChatRoom
|
import org.linphone.core.ChatRoom
|
||||||
import org.linphone.databinding.ChatRoomListCellBinding
|
import org.linphone.databinding.ChatRoomListCellBinding
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
|
import org.linphone.utils.LinphoneUtils
|
||||||
|
|
||||||
class ChatRoomsListAdapter(
|
class ChatRoomsListAdapter(
|
||||||
selectionVM: ListTopBarViewModel,
|
selectionVM: ListTopBarViewModel,
|
||||||
|
@ -56,6 +57,11 @@ class ChatRoomsListAdapter(
|
||||||
(holder as ViewHolder).bind(getItem(position))
|
(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) {
|
fun forwardPending(pending: Boolean) {
|
||||||
isForwardPending = pending
|
isForwardPending = pending
|
||||||
notifyItemRangeChanged(0, itemCount)
|
notifyItemRangeChanged(0, itemCount)
|
||||||
|
|
|
@ -156,7 +156,9 @@ class MasterChatRoomsFragment : MasterFragment<ChatRoomMasterFragmentBinding, Ch
|
||||||
_adapter = ChatRoomsListAdapter(listSelectionViewModel, viewLifecycleOwner)
|
_adapter = ChatRoomsListAdapter(listSelectionViewModel, viewLifecycleOwner)
|
||||||
// SubmitList is done on a background thread
|
// SubmitList is done on a background thread
|
||||||
// We need this adapter data observer to know when to scroll
|
// We need this adapter data observer to know when to scroll
|
||||||
|
adapter.setHasStableIds(true)
|
||||||
adapter.registerAdapterDataObserver(observer)
|
adapter.registerAdapterDataObserver(observer)
|
||||||
|
|
||||||
binding.chatList.setHasFixedSize(true)
|
binding.chatList.setHasFixedSize(true)
|
||||||
binding.chatList.adapter = adapter
|
binding.chatList.adapter = adapter
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,7 @@ class NotificationsManager(private val context: Context) {
|
||||||
dismissChatNotification(chatRoom)
|
dismissChatNotification(chatRoom)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val notificationId = chatRoom.creationTime.toInt()
|
val notificationId = getNotificationIdForChat(chatRoom)
|
||||||
if (chatBubbleNotifications.contains(notificationId)) {
|
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")
|
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 {
|
} else {
|
||||||
|
@ -635,7 +635,7 @@ class NotificationsManager(private val context: Context) {
|
||||||
/* Chat related */
|
/* Chat related */
|
||||||
|
|
||||||
private fun getNotificationIdForChat(chatRoom: ChatRoom): Int {
|
private fun getNotificationIdForChat(chatRoom: ChatRoom): Int {
|
||||||
return chatRoom.creationTime.toInt()
|
return LinphoneUtils.getChatRoomId(chatRoom).hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun displayChatNotifiable(room: ChatRoom, notifiable: Notifiable) {
|
private fun displayChatNotifiable(room: ChatRoom, notifiable: Notifiable) {
|
||||||
|
@ -784,7 +784,7 @@ class NotificationsManager(private val context: Context) {
|
||||||
cancel(notifiable.notificationId, CHAT_TAG)
|
cancel(notifiable.notificationId, CHAT_TAG)
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
val previousNotificationId = previousChatNotifications.find { id -> id == room.creationTime.toInt() }
|
val previousNotificationId = previousChatNotifications.find { id -> id == getNotificationIdForChat(room) }
|
||||||
if (previousNotificationId != null) {
|
if (previousNotificationId != null) {
|
||||||
if (chatBubbleNotifications.contains(previousNotificationId)) {
|
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")
|
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) {
|
fun changeDismissNotificationUponReadForChatRoom(chatRoom: ChatRoom, dismiss: Boolean) {
|
||||||
val notificationId = chatRoom.creationTime.toInt()
|
val notificationId = getNotificationIdForChat(chatRoom)
|
||||||
if (dismiss) {
|
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")
|
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)
|
chatBubbleNotifications.add(notificationId)
|
||||||
|
|
|
@ -229,6 +229,10 @@ class LinphoneUtils {
|
||||||
chatRoom1.peerAddress.weakEqual(chatRoom2.peerAddress)
|
chatRoom1.peerAddress.weakEqual(chatRoom2.peerAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getChatRoomId(room: ChatRoom): String {
|
||||||
|
return getChatRoomId(room.localAddress, room.peerAddress)
|
||||||
|
}
|
||||||
|
|
||||||
fun getChatRoomId(localAddress: Address, remoteAddress: Address): String {
|
fun getChatRoomId(localAddress: Address, remoteAddress: Address): String {
|
||||||
val localSipUri = localAddress.clone()
|
val localSipUri = localAddress.clone()
|
||||||
localSipUri.clean()
|
localSipUri.clean()
|
||||||
|
|
Loading…
Reference in a new issue