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