use a new model ContactSource
This commit is contained in:
parent
6f82aadcb9
commit
f0a2f585b8
|
@ -227,9 +227,9 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
"com.android.huawei.phone",
|
||||
"Local Phone Account")
|
||||
|
||||
ContactsHelper(this).getContactTypes {
|
||||
ContactsHelper(this).getContactSources {
|
||||
var localAccountType = ""
|
||||
it.forEach {
|
||||
it.map { it.type }.forEach {
|
||||
if (localAccountTypes.contains(it)) {
|
||||
localAccountType = it
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class ExportContactsDialog(val activity: SimpleActivity, val path: String, priva
|
|||
|
||||
ContactsHelper(activity).getContactSources {
|
||||
activity.runOnUiThread {
|
||||
export_contacts_list.adapter = FilterContactSourcesAdapter(activity, it, activity.config.displayContactSources)
|
||||
export_contacts_list.adapter = FilterContactSourcesAdapter(activity, it.map { it.name }, activity.config.displayContactSources)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, private val callb
|
|||
|
||||
val selectedSources = activity.config.displayContactSources
|
||||
activity.runOnUiThread {
|
||||
view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, it, selectedSources)
|
||||
view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, it.map { it.name }, selectedSources)
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, { dialogInterface, i -> confirmEventTypes() })
|
||||
|
|
|
@ -51,7 +51,7 @@ fun SimpleActivity.tryStartCall(contact: Contact) {
|
|||
fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (newSource: String) -> Unit) {
|
||||
ContactsHelper(this).getContactSources {
|
||||
val items = ArrayList<RadioItem>()
|
||||
val sources = it
|
||||
val sources = it.map { it.name }
|
||||
var currentSourceIndex = -1
|
||||
sources.forEachIndexed { index, account ->
|
||||
items.add(RadioItem(index, account))
|
||||
|
|
|
@ -22,10 +22,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_SURNAME
|
|||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import com.simplemobiletools.contacts.models.Email
|
||||
import com.simplemobiletools.contacts.models.Event
|
||||
import com.simplemobiletools.contacts.models.PhoneNumber
|
||||
import com.simplemobiletools.contacts.models.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.*
|
||||
|
||||
|
@ -229,11 +226,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
return null
|
||||
}
|
||||
|
||||
fun getContactSources(callback: (ArrayList<String>) -> Unit) {
|
||||
val accounts = HashSet<String>()
|
||||
fun getContactSources(callback: (ArrayList<ContactSource>) -> Unit) {
|
||||
val sources = HashSet<ContactSource>()
|
||||
Thread {
|
||||
val uri = ContactsContract.RawContacts.CONTENT_URI
|
||||
val projection = arrayOf(ContactsContract.RawContacts.ACCOUNT_NAME)
|
||||
val projection = arrayOf(ContactsContract.RawContacts.ACCOUNT_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE)
|
||||
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
|
@ -241,37 +238,16 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val name = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: continue
|
||||
accounts.add(name)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
||||
callback(ArrayList(accounts))
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun getContactTypes(callback: (ArrayList<String>) -> Unit) {
|
||||
val accounts = HashSet<String>()
|
||||
Thread {
|
||||
val uri = ContactsContract.RawContacts.CONTENT_URI
|
||||
val projection = arrayOf(ContactsContract.RawContacts.ACCOUNT_TYPE)
|
||||
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = activity.contentResolver.query(uri, projection, null, null, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val type = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_TYPE) ?: continue
|
||||
accounts.add(type)
|
||||
val contactSource = ContactSource(name, type)
|
||||
sources.add(contactSource)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
||||
callback(ArrayList(accounts))
|
||||
callback(ArrayList(sources))
|
||||
}.start()
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ data class Contact(val id: Int, var firstName: String, var middleName: String, v
|
|||
var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var events: ArrayList<Event>, var source: String,
|
||||
var starred: Int, val contactId: Int, val thumbnailUri: String) : Comparable<Contact> {
|
||||
companion object {
|
||||
var sorting: Int = 0
|
||||
var sorting = 0
|
||||
}
|
||||
|
||||
override fun compareTo(other: Contact): Int {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package com.simplemobiletools.contacts.models
|
||||
|
||||
data class ContactSource(var name: String, var type: String)
|
Loading…
Reference in New Issue