Fixed duplicated contacts in SIP list after contact added or removed
This commit is contained in:
parent
06731726c5
commit
7e81f775c3
4 changed files with 20 additions and 27 deletions
|
@ -63,15 +63,15 @@ class AsyncContactsLoader(private val context: Context) :
|
|||
}
|
||||
|
||||
override fun doInBackground(vararg args: Void): AsyncContactsData {
|
||||
Log.i("[Contacts Loader] Background synchronization started")
|
||||
|
||||
val data = AsyncContactsData()
|
||||
val core: Core = coreContext.core
|
||||
if (isCancelled) return data
|
||||
|
||||
Log.i("[Contacts Loader] Background synchronization started")
|
||||
val core: Core = coreContext.core
|
||||
val androidContactsCache: HashMap<String, Contact> = HashMap()
|
||||
val nativeIds = arrayListOf<String>()
|
||||
|
||||
val friendLists = core.friendsLists
|
||||
|
||||
for (list in friendLists) {
|
||||
val friends = list.friends
|
||||
for (friend in friends) {
|
||||
|
@ -133,6 +133,7 @@ class AsyncContactsLoader(private val context: Context) :
|
|||
while (cursor.moveToNext()) {
|
||||
if (isCancelled) {
|
||||
Log.w("[Contacts Loader] Task cancelled")
|
||||
cursor.close()
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -218,7 +219,6 @@ class AsyncContactsLoader(private val context: Context) :
|
|||
androidContactsCache.clear()
|
||||
|
||||
data.contacts.sort()
|
||||
data.sipContacts.sort()
|
||||
|
||||
Log.i("[Contacts Loader] Background synchronization finished")
|
||||
return data
|
||||
|
@ -232,11 +232,13 @@ class AsyncContactsLoader(private val context: Context) :
|
|||
if (contact is NativeContact) {
|
||||
contact.createOrUpdateFriendFromNativeContact()
|
||||
|
||||
if (contact.friend?.presenceModel?.basicStatus == PresenceBasicStatus.Open) {
|
||||
if (contact.friend?.presenceModel?.basicStatus == PresenceBasicStatus.Open && !data.sipContacts.contains(contact)) {
|
||||
Log.i("[Contacts Loader] Friend $contact has presence information, adding it to SIP list")
|
||||
data.sipContacts.add(contact)
|
||||
}
|
||||
}
|
||||
}
|
||||
data.sipContacts.sort()
|
||||
|
||||
// Now that contact fetching is asynchronous, this is required to ensure
|
||||
// presence subscription event will be sent with all friends
|
||||
|
|
|
@ -49,10 +49,12 @@ open class ContactsUpdatedListenerStub : ContactsUpdatedListener {
|
|||
class ContactsManager(private val context: Context) {
|
||||
private val contactsObserver: ContentObserver by lazy {
|
||||
object : ContentObserver(coreContext.handler) {
|
||||
@Synchronized
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
onChange(selfChange, null)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onChange(selfChange: Boolean, uri: Uri?) {
|
||||
Log.i("[Contacts Observer] At least one contact has changed")
|
||||
fetchContactsAsync()
|
||||
|
@ -61,9 +63,13 @@ class ContactsManager(private val context: Context) {
|
|||
}
|
||||
|
||||
var contacts = ArrayList<Contact>()
|
||||
@Synchronized
|
||||
get
|
||||
@Synchronized
|
||||
private set
|
||||
var sipContacts = ArrayList<Contact>()
|
||||
@Synchronized
|
||||
get
|
||||
@Synchronized
|
||||
private set
|
||||
|
||||
|
@ -111,8 +117,12 @@ class ContactsManager(private val context: Context) {
|
|||
Log.i("[Contacts Manager] Created")
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun fetchContactsAsync() {
|
||||
loadContactsTask?.cancel(true)
|
||||
if (loadContactsTask != null) {
|
||||
Log.w("[Contacts Manager] Cancelling existing async task")
|
||||
loadContactsTask?.cancel(true)
|
||||
}
|
||||
loadContactsTask = AsyncContactsLoader(context)
|
||||
loadContactsTask?.executeOnExecutor(THREAD_POOL_EXECUTOR)
|
||||
}
|
||||
|
@ -136,6 +146,7 @@ class ContactsManager(private val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun getAndroidContactIdFromUri(uri: Uri): String? {
|
||||
val projection = arrayOf(ContactsContract.Data.CONTACT_ID)
|
||||
val cursor = context.contentResolver.query(uri, projection, null, null, null)
|
||||
|
|
|
@ -80,11 +80,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dividerColor" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -101,11 +96,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dividerColor" />
|
||||
|
||||
<include
|
||||
layout="@layout/settings_widget_basic"
|
||||
linphone:listener="@{viewModel.tunnelSettingsListener}"
|
||||
|
|
|
@ -74,11 +74,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dividerColor" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -95,11 +90,6 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dividerColor" />
|
||||
|
||||
<include
|
||||
layout="@layout/settings_widget_basic"
|
||||
linphone:listener="@{viewModel.tunnelSettingsListener}"
|
||||
|
|
Loading…
Reference in a new issue