Disable fetching Msisdn, it does not work

This commit is contained in:
Benoit Marty 2020-07-10 09:43:32 +02:00
parent c78bba803c
commit 3d68b15e60
2 changed files with 67 additions and 52 deletions

View File

@ -29,8 +29,16 @@ class ContactsDataSource @Inject constructor(
private val context: Context
) {
/**
* Will return a list of contact from the contacts book of the device, with at least one email or phone.
* If both param are false, you will get en empty list.
* Note: The return list does not contain any matrixId.
*/
@WorkerThread
fun getContacts(): List<MappedContact> {
fun getContacts(
withEmails: Boolean,
withMsisdn: Boolean
): List<MappedContact> {
val map = mutableMapOf<Long, MappedContactBuilder>()
val contentResolver = context.contentResolver
@ -69,6 +77,7 @@ class ContactsDataSource @Inject constructor(
}
// Get the phone numbers
if (withMsisdn) {
contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
arrayOf(
ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
@ -93,8 +102,10 @@ class ContactsDataSource @Inject constructor(
}
}
}
}
// Get Emails
if (withEmails) {
contentResolver.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
arrayOf(
@ -122,7 +133,7 @@ class ContactsDataSource @Inject constructor(
}
}
}
}
}.also { Timber.d("Took ${it}ms to fetch ${map.size} contact(s)") }
return map

View File

@ -90,7 +90,11 @@ class ContactsBookViewModel @AssistedInject constructor(@Assisted
}
viewModelScope.launch(Dispatchers.IO) {
allContacts = contactsDataSource.getContacts()
allContacts = contactsDataSource.getContacts(
withEmails = true,
// Do not handle phone numbers for the moment
withMsisdn = false
)
mappedContacts = allContacts
setState {