Add/remove friend list listener when created/destroyed while app is alive

This commit is contained in:
Sylvain Berfini 2023-04-26 16:31:29 +02:00
parent a2535cef56
commit e8f94a489f

View file

@ -92,6 +92,16 @@ class ContactsManager(private val context: Context) {
} }
} }
private val coreListener: CoreListenerStub = object : CoreListenerStub() {
override fun onFriendListCreated(core: Core, friendList: FriendList) {
friendList.addListener(friendListListener)
}
override fun onFriendListRemoved(core: Core, friendList: FriendList) {
friendList.removeListener(friendListListener)
}
}
init { init {
initSyncAccount() initSyncAccount()
@ -109,6 +119,7 @@ class ContactsManager(private val context: Context) {
) )
val core = coreContext.core val core = coreContext.core
core.addListener(coreListener)
for (list in core.friendsLists) { for (list in core.friendsLists) {
list.addListener(friendListListener) list.addListener(friendListListener)
} }
@ -236,6 +247,7 @@ class ContactsManager(private val context: Context) {
fun destroy() { fun destroy() {
val core = coreContext.core val core = coreContext.core
for (list in core.friendsLists) list.removeListener(friendListListener) for (list in core.friendsLists) list.removeListener(friendListListener)
core.removeListener(coreListener)
} }
private fun initSyncAccount() { private fun initSyncAccount() {