allow changing contact source

This commit is contained in:
tibbi 2017-12-21 14:22:14 +01:00
parent 6af220bcf0
commit 544121fb45
2 changed files with 28 additions and 5 deletions

View file

@ -273,6 +273,7 @@ class ContactActivity : SimpleActivity() {
surname = contact_surname.value
phoneNumbers = getFilledPhoneNumbers()
emails = getFilledEmails()
source = contact_source.value
/*if (ContactsHelper(this@ContactActivity).updateContact(this)) {
finish()
@ -332,7 +333,24 @@ class ContactActivity : SimpleActivity() {
}
private fun showAccountSourcePicker() {
ContactsHelper(this).getContactSources {
val items = ArrayList<RadioItem>()
val sources = it
val currentSource = contact_source.value
var currentSourceIndex = -1
sources.forEachIndexed { index, account ->
items.add(RadioItem(index, account))
if (account == currentSource) {
currentSourceIndex = index
}
}
runOnUiThread {
RadioGroupDialog(this, items, currentSourceIndex) {
contact_source.text = sources[it as Int]
}
}
}
}
private fun trySendSMS() {

View file

@ -24,21 +24,26 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
val accounts = HashSet<String>()
Thread {
val uri = ContactsContract.RawContacts.CONTENT_URI
val projection = arrayOf(ContactsContract.RawContacts.ACCOUNT_NAME)
val projection = arrayOf(
ContactsContract.RawContacts.ACCOUNT_NAME
)
val selection = "${ContactsContract.RawContacts.DIRTY} = ?"
val selectionArgs = arrayOf("0")
var cursor: Cursor? = null
try {
cursor = activity.contentResolver.query(uri, projection, null, null, null)
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
if (cursor?.moveToFirst() == true) {
do {
accounts.add(cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME))
val name = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
accounts.add(name)
} while (cursor.moveToNext())
}
} finally {
cursor?.close()
}
val sourcesWithContacts = ArrayList(accounts).filter { doesSourceContainContacts(it) } as ArrayList
callback(sourcesWithContacts)
callback(ArrayList(accounts))
}.start()
}