allow changing contact source
This commit is contained in:
parent
6af220bcf0
commit
544121fb45
2 changed files with 28 additions and 5 deletions
|
@ -273,6 +273,7 @@ class ContactActivity : SimpleActivity() {
|
||||||
surname = contact_surname.value
|
surname = contact_surname.value
|
||||||
phoneNumbers = getFilledPhoneNumbers()
|
phoneNumbers = getFilledPhoneNumbers()
|
||||||
emails = getFilledEmails()
|
emails = getFilledEmails()
|
||||||
|
source = contact_source.value
|
||||||
|
|
||||||
/*if (ContactsHelper(this@ContactActivity).updateContact(this)) {
|
/*if (ContactsHelper(this@ContactActivity).updateContact(this)) {
|
||||||
finish()
|
finish()
|
||||||
|
@ -332,7 +333,24 @@ class ContactActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showAccountSourcePicker() {
|
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() {
|
private fun trySendSMS() {
|
||||||
|
|
|
@ -24,21 +24,26 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
val accounts = HashSet<String>()
|
val accounts = HashSet<String>()
|
||||||
Thread {
|
Thread {
|
||||||
val uri = ContactsContract.RawContacts.CONTENT_URI
|
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
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = activity.contentResolver.query(uri, projection, null, null, null)
|
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
accounts.add(cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME))
|
val name = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
|
||||||
|
accounts.add(name)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
val sourcesWithContacts = ArrayList(accounts).filter { doesSourceContainContacts(it) } as ArrayList
|
callback(ArrayList(accounts))
|
||||||
callback(sourcesWithContacts)
|
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue