mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
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",
|
"com.android.huawei.phone",
|
||||||
"Local Phone Account")
|
"Local Phone Account")
|
||||||
|
|
||||||
ContactsHelper(this).getContactTypes {
|
ContactsHelper(this).getContactSources {
|
||||||
var localAccountType = ""
|
var localAccountType = ""
|
||||||
it.forEach {
|
it.map { it.type }.forEach {
|
||||||
if (localAccountTypes.contains(it)) {
|
if (localAccountTypes.contains(it)) {
|
||||||
localAccountType = it
|
localAccountType = it
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ class ExportContactsDialog(val activity: SimpleActivity, val path: String, priva
|
|||||||
|
|
||||||
ContactsHelper(activity).getContactSources {
|
ContactsHelper(activity).getContactSources {
|
||||||
activity.runOnUiThread {
|
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
|
val selectedSources = activity.config.displayContactSources
|
||||||
activity.runOnUiThread {
|
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)
|
dialog = AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.ok, { dialogInterface, i -> confirmEventTypes() })
|
.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) {
|
fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (newSource: String) -> Unit) {
|
||||||
ContactsHelper(this).getContactSources {
|
ContactsHelper(this).getContactSources {
|
||||||
val items = ArrayList<RadioItem>()
|
val items = ArrayList<RadioItem>()
|
||||||
val sources = it
|
val sources = it.map { it.name }
|
||||||
var currentSourceIndex = -1
|
var currentSourceIndex = -1
|
||||||
sources.forEachIndexed { index, account ->
|
sources.forEachIndexed { index, account ->
|
||||||
items.add(RadioItem(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.commons.helpers.SORT_DESCENDING
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.models.Contact
|
import com.simplemobiletools.contacts.models.*
|
||||||
import com.simplemobiletools.contacts.models.Email
|
|
||||||
import com.simplemobiletools.contacts.models.Event
|
|
||||||
import com.simplemobiletools.contacts.models.PhoneNumber
|
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -229,11 +226,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContactSources(callback: (ArrayList<String>) -> Unit) {
|
fun getContactSources(callback: (ArrayList<ContactSource>) -> Unit) {
|
||||||
val accounts = HashSet<String>()
|
val sources = HashSet<ContactSource>()
|
||||||
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, ContactsContract.RawContacts.ACCOUNT_TYPE)
|
||||||
|
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
@ -241,37 +238,16 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val name = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME) ?: continue
|
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
|
val type = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_TYPE) ?: continue
|
||||||
accounts.add(type)
|
val contactSource = ContactSource(name, type)
|
||||||
|
sources.add(contactSource)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(ArrayList(accounts))
|
callback(ArrayList(sources))
|
||||||
}.start()
|
}.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 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> {
|
var starred: Int, val contactId: Int, val thumbnailUri: String) : Comparable<Contact> {
|
||||||
companion object {
|
companion object {
|
||||||
var sorting: Int = 0
|
var sorting = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun compareTo(other: Contact): Int {
|
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…
x
Reference in New Issue
Block a user