Trying to fix crashes seen on PlayStore due to friends being created in coroutine IO dispatcher
This commit is contained in:
parent
37a6c3968e
commit
dcf91ddef3
1 changed files with 77 additions and 67 deletions
|
@ -128,81 +128,91 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
previousId = id
|
previousId = id
|
||||||
}
|
}
|
||||||
|
|
||||||
val friend = friends[id] ?: core.createFriend()
|
withContext(Dispatchers.Main) {
|
||||||
friend.refKey = id
|
val friend = friends[id] ?: core.createFriend()
|
||||||
if (friend.name.isNullOrEmpty()) {
|
friend.refKey = id
|
||||||
friend.name = displayName
|
if (friend.name.isNullOrEmpty()) {
|
||||||
friend.photo = Uri.withAppendedPath(
|
friend.name = displayName
|
||||||
ContentUris.withAppendedId(
|
friend.photo = Uri.withAppendedPath(
|
||||||
ContactsContract.Contacts.CONTENT_URI,
|
ContentUris.withAppendedId(
|
||||||
id.toLong()
|
ContactsContract.Contacts.CONTENT_URI,
|
||||||
),
|
id.toLong()
|
||||||
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY
|
),
|
||||||
).toString()
|
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY
|
||||||
friend.starred = starred
|
).toString()
|
||||||
friend.nativeUri =
|
friend.starred = starred
|
||||||
"${ContactsContract.Contacts.CONTENT_LOOKUP_URI}/$lookupKey"
|
friend.nativeUri =
|
||||||
|
"${ContactsContract.Contacts.CONTENT_LOOKUP_URI}/$lookupKey"
|
||||||
|
|
||||||
// Disable short term presence
|
// Disable short term presence
|
||||||
friend.isSubscribesEnabled = false
|
friend.isSubscribesEnabled = false
|
||||||
friend.incSubscribePolicy = SubscribePolicy.SPDeny
|
friend.incSubscribePolicy = SubscribePolicy.SPDeny
|
||||||
}
|
}
|
||||||
|
|
||||||
when (mime) {
|
when (mime) {
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE -> {
|
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE -> {
|
||||||
val label = PhoneNumberUtils.addressBookLabelTypeToVcardParamString(
|
val label =
|
||||||
data2?.toInt() ?: ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM,
|
PhoneNumberUtils.addressBookLabelTypeToVcardParamString(
|
||||||
data3
|
data2?.toInt()
|
||||||
)
|
?: ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM,
|
||||||
|
data3
|
||||||
|
)
|
||||||
|
|
||||||
val number =
|
val number =
|
||||||
if (corePreferences.preferNormalizedPhoneNumbersFromAddressBook ||
|
if (corePreferences.preferNormalizedPhoneNumbersFromAddressBook ||
|
||||||
data1.isNullOrEmpty() ||
|
data1.isNullOrEmpty() ||
|
||||||
!Patterns.PHONE.matcher(data1).matches()
|
!Patterns.PHONE.matcher(data1).matches()
|
||||||
) {
|
) {
|
||||||
data4 ?: data1
|
data4 ?: data1
|
||||||
} else {
|
} else {
|
||||||
data1
|
data1
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number != null) {
|
||||||
|
if (
|
||||||
|
friendsPhoneNumbers.find {
|
||||||
|
PhoneNumberUtils.arePhoneNumberWeakEqual(
|
||||||
|
it,
|
||||||
|
number
|
||||||
|
)
|
||||||
|
} == null
|
||||||
|
) {
|
||||||
|
val phoneNumber = Factory.instance()
|
||||||
|
.createFriendPhoneNumber(number, label)
|
||||||
|
friend.addPhoneNumberWithLabel(phoneNumber)
|
||||||
|
friendsPhoneNumbers.add(number)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (number != null) {
|
linphoneMime, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> {
|
||||||
if (
|
if (data1 != null) {
|
||||||
friendsPhoneNumbers.find {
|
val address = core.interpretUrl(data1, true)
|
||||||
PhoneNumberUtils.arePhoneNumberWeakEqual(it, number)
|
if (address != null &&
|
||||||
} == null
|
friendsAddresses.find {
|
||||||
) {
|
it.weakEqual(address)
|
||||||
val phoneNumber = Factory.instance()
|
} == null
|
||||||
.createFriendPhoneNumber(number, label)
|
) {
|
||||||
friend.addPhoneNumberWithLabel(phoneNumber)
|
friend.addAddress(address)
|
||||||
friendsPhoneNumbers.add(number)
|
friendsAddresses.add(address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE -> {
|
||||||
|
if (data1 != null) {
|
||||||
|
friend.organization = data1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE -> {
|
||||||
|
if (data2 != null && data3 != null) {
|
||||||
|
val vCard = friend.vcard
|
||||||
|
vCard?.givenName = data2
|
||||||
|
vCard?.familyName = data3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
linphoneMime, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> {
|
|
||||||
if (data1 == null) continue
|
|
||||||
val address = core.interpretUrl(data1, true) ?: continue
|
|
||||||
if (
|
|
||||||
friendsAddresses.find {
|
|
||||||
it.weakEqual(address)
|
|
||||||
} == null
|
|
||||||
) {
|
|
||||||
friend.addAddress(address)
|
|
||||||
friendsAddresses.add(address)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE -> {
|
|
||||||
if (data1 == null) continue
|
|
||||||
friend.organization = data1
|
|
||||||
}
|
|
||||||
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE -> {
|
|
||||||
if (data2 == null && data3 == null) continue
|
|
||||||
val vCard = friend.vcard
|
|
||||||
vCard?.givenName = data2
|
|
||||||
vCard?.familyName = data3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
friends[id] = friend
|
friends[id] = friend
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("[Contacts Loader] Exception: $e")
|
Log.e("[Contacts Loader] Exception: $e")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue