Add/remove friend list listener when created/destroyed while app is alive
This commit is contained in:
parent
a2535cef56
commit
e8f94a489f
1 changed files with 12 additions and 0 deletions
|
@ -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 {
|
||||
initSyncAccount()
|
||||
|
||||
|
@ -109,6 +119,7 @@ class ContactsManager(private val context: Context) {
|
|||
)
|
||||
|
||||
val core = coreContext.core
|
||||
core.addListener(coreListener)
|
||||
for (list in core.friendsLists) {
|
||||
list.addListener(friendListListener)
|
||||
}
|
||||
|
@ -236,6 +247,7 @@ class ContactsManager(private val context: Context) {
|
|||
fun destroy() {
|
||||
val core = coreContext.core
|
||||
for (list in core.friendsLists) list.removeListener(friendListListener)
|
||||
core.removeListener(coreListener)
|
||||
}
|
||||
|
||||
private fun initSyncAccount() {
|
||||
|
|
Loading…
Reference in a new issue