mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-02-19 13:00:37 +01:00
fixing some crashes and ANRs
This commit is contained in:
parent
b42fc83f8c
commit
ad9710cef0
@ -189,7 +189,9 @@ class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList<SimpleCo
|
||||
|
||||
}
|
||||
|
||||
SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.name)
|
||||
if (!activity.isDestroyed) {
|
||||
SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,9 +124,13 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val lookupKey = SimpleContactsHelper(activity!!).getContactLookupKey((contact).rawId.toString())
|
||||
val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||
activity!!.launchViewContactIntent(publicUri)
|
||||
ensureBackgroundThread {
|
||||
val lookupKey = SimpleContactsHelper(activity!!).getContactLookupKey((contact).rawId.toString())
|
||||
val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||
activity?.runOnUiThread {
|
||||
activity!!.launchViewContactIntent(publicUri)
|
||||
}
|
||||
}
|
||||
}
|
||||
}.apply {
|
||||
fragment_list.adapter = this
|
||||
|
@ -3,6 +3,8 @@ package com.simplemobiletools.dialer.helpers
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.telecom.Call
|
||||
import android.telecom.InCallService
|
||||
import android.telecom.VideoProfile
|
||||
@ -55,30 +57,34 @@ class CallManager {
|
||||
}
|
||||
|
||||
fun getCallContact(context: Context, callback: (CallContact?) -> Unit) {
|
||||
val callContact = CallContact("", "", "")
|
||||
if (call == null || call!!.details == null || call!!.details!!.handle == null) {
|
||||
callback(callContact)
|
||||
return
|
||||
}
|
||||
|
||||
val uri = Uri.decode(call!!.details.handle.toString())
|
||||
if (uri.startsWith("tel:")) {
|
||||
val number = uri.substringAfter("tel:")
|
||||
callContact.number = number
|
||||
callContact.name = SimpleContactsHelper(context).getNameFromPhoneNumber(number)
|
||||
callContact.photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(number)
|
||||
|
||||
if (callContact.name != callContact.number) {
|
||||
ensureBackgroundThread {
|
||||
val callContact = CallContact("", "", "")
|
||||
if (call == null || call!!.details == null || call!!.details!!.handle == null) {
|
||||
callback(callContact)
|
||||
} else {
|
||||
val privateCursor = context.getMyContactsCursor().loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor)
|
||||
val privateContact = privateContacts.firstOrNull { it.doesContainPhoneNumber(callContact.number) }
|
||||
if (privateContact != null) {
|
||||
callContact.name = privateContact.name
|
||||
}
|
||||
return@ensureBackgroundThread
|
||||
}
|
||||
|
||||
val uri = Uri.decode(call!!.details.handle.toString())
|
||||
if (uri.startsWith("tel:")) {
|
||||
val number = uri.substringAfter("tel:")
|
||||
callContact.number = number
|
||||
callContact.name = SimpleContactsHelper(context).getNameFromPhoneNumber(number)
|
||||
callContact.photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(number)
|
||||
|
||||
if (callContact.name != callContact.number) {
|
||||
callback(callContact)
|
||||
} else {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
val privateCursor = context.getMyContactsCursor().loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor)
|
||||
val privateContact = privateContacts.firstOrNull { it.doesContainPhoneNumber(callContact.number) }
|
||||
if (privateContact != null) {
|
||||
callContact.name = privateContact.name
|
||||
}
|
||||
callback(callContact)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user