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