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,6 +128,7 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
previousId = id
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
val friend = friends[id] ?: core.createFriend()
|
||||
friend.refKey = id
|
||||
if (friend.name.isNullOrEmpty()) {
|
||||
|
@ -150,8 +151,10 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
|
||||
when (mime) {
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE -> {
|
||||
val label = PhoneNumberUtils.addressBookLabelTypeToVcardParamString(
|
||||
data2?.toInt() ?: ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM,
|
||||
val label =
|
||||
PhoneNumberUtils.addressBookLabelTypeToVcardParamString(
|
||||
data2?.toInt()
|
||||
?: ContactsContract.CommonDataKinds.BaseTypes.TYPE_CUSTOM,
|
||||
data3
|
||||
)
|
||||
|
||||
|
@ -168,7 +171,10 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
if (number != null) {
|
||||
if (
|
||||
friendsPhoneNumbers.find {
|
||||
PhoneNumberUtils.arePhoneNumberWeakEqual(it, number)
|
||||
PhoneNumberUtils.arePhoneNumberWeakEqual(
|
||||
it,
|
||||
number
|
||||
)
|
||||
} == null
|
||||
) {
|
||||
val phoneNumber = Factory.instance()
|
||||
|
@ -179,9 +185,9 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
}
|
||||
}
|
||||
linphoneMime, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE -> {
|
||||
if (data1 == null) continue
|
||||
val address = core.interpretUrl(data1, true) ?: continue
|
||||
if (
|
||||
if (data1 != null) {
|
||||
val address = core.interpretUrl(data1, true)
|
||||
if (address != null &&
|
||||
friendsAddresses.find {
|
||||
it.weakEqual(address)
|
||||
} == null
|
||||
|
@ -190,19 +196,23 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
|
|||
friendsAddresses.add(address)
|
||||
}
|
||||
}
|
||||
}
|
||||
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE -> {
|
||||
if (data1 == null) continue
|
||||
if (data1 != null) {
|
||||
friend.organization = data1
|
||||
}
|
||||
}
|
||||
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE -> {
|
||||
if (data2 == null && data3 == null) continue
|
||||
if (data2 != null && data3 != null) {
|
||||
val vCard = friend.vcard
|
||||
vCard?.givenName = data2
|
||||
vCard?.familyName = data3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
friends[id] = friend
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("[Contacts Loader] Exception: $e")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue