count with the privately stored contacts at Suggestions
This commit is contained in:
parent
3e8697d7cc
commit
2e20dd7454
|
@ -26,6 +26,7 @@ import kotlin.collections.ArrayList
|
|||
|
||||
class NewConversationActivity : SimpleActivity() {
|
||||
private var allContacts = ArrayList<SimpleContact>()
|
||||
private var privateContacts = ArrayList<SimpleContact>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -104,11 +105,9 @@ class NewConversationActivity : SimpleActivity() {
|
|||
|
||||
private fun fetchContacts() {
|
||||
fillSuggestedContacts {
|
||||
val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground()
|
||||
SimpleContactsHelper(this).getAvailableContacts(false) {
|
||||
allContacts = it
|
||||
|
||||
val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
if (privateContacts.isNotEmpty()) {
|
||||
allContacts.addAll(privateContacts)
|
||||
allContacts.sort()
|
||||
|
@ -143,8 +142,10 @@ class NewConversationActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun fillSuggestedContacts(callback: () -> Unit) {
|
||||
val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
val suggestions = getSuggestedContacts()
|
||||
privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
val suggestions = getSuggestedContacts(privateContacts)
|
||||
runOnUiThread {
|
||||
suggestions_holder.removeAllViews()
|
||||
if (suggestions.isEmpty()) {
|
||||
|
|
|
@ -367,7 +367,7 @@ fun Context.getPhoneNumberFromAddressId(canonicalAddressId: Int): String {
|
|||
return ""
|
||||
}
|
||||
|
||||
fun Context.getSuggestedContacts(): ArrayList<SimpleContact> {
|
||||
fun Context.getSuggestedContacts(privateContacts: ArrayList<SimpleContact>): ArrayList<SimpleContact> {
|
||||
val contacts = ArrayList<SimpleContact>()
|
||||
val uri = Sms.CONTENT_URI
|
||||
val projection = arrayOf(
|
||||
|
@ -381,11 +381,22 @@ fun Context.getSuggestedContacts(): ArrayList<SimpleContact> {
|
|||
queryCursor(uri, projection, selection, selectionArgs, sortOrder, showErrors = true) { cursor ->
|
||||
val senderNumber = cursor.getStringValue(Sms.ADDRESS) ?: return@queryCursor
|
||||
val namePhoto = getNameAndPhotoFromPhoneNumber(senderNumber)
|
||||
if (namePhoto == null || namePhoto.name == senderNumber || isNumberBlocked(senderNumber)) {
|
||||
var senderName = namePhoto?.name ?: ""
|
||||
if (namePhoto == null || isNumberBlocked(senderNumber)) {
|
||||
return@queryCursor
|
||||
} else if (namePhoto.name == senderNumber) {
|
||||
if (privateContacts.isNotEmpty()) {
|
||||
val privateContact = privateContacts.firstOrNull { it.phoneNumber == senderNumber }
|
||||
if (privateContact != null) {
|
||||
senderName = privateContact.name
|
||||
} else {
|
||||
return@queryCursor
|
||||
}
|
||||
} else {
|
||||
return@queryCursor
|
||||
}
|
||||
}
|
||||
|
||||
val senderName = namePhoto.name
|
||||
val photoUri = namePhoto.photoUri ?: ""
|
||||
val contact = SimpleContact(0, 0, senderName, photoUri, senderNumber)
|
||||
if (!contacts.map { it.phoneNumber.trimToComparableNumber() }.contains(senderNumber.trimToComparableNumber())) {
|
||||
|
|
Loading…
Reference in New Issue