fetch the user Organization field
This commit is contained in:
parent
25c9abb92d
commit
dbd3bec690
|
@ -386,7 +386,7 @@ class EditContactActivity : ContactActivity() {
|
|||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
|
||||
supportActionBar?.title = resources.getString(R.string.new_contact)
|
||||
val contactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
||||
contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), contactSource, 0, 0, "", null, "", ArrayList())
|
||||
contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), contactSource, 0, 0, "", null, "", ArrayList(), "")
|
||||
contact_source.text = getPublicContactSource(contact!!.source)
|
||||
contact_source.setOnClickListener {
|
||||
showContactSourcePicker(contact!!.source) {
|
||||
|
|
|
@ -83,8 +83,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
||||
val notes = ""
|
||||
val groups = ArrayList<Group>()
|
||||
val organization = ""
|
||||
val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName,
|
||||
starred, contactId, thumbnailUri, null, notes, groups)
|
||||
starred, contactId, thumbnailUri, null, notes, groups, organization)
|
||||
contacts.put(id, contact)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
|
@ -128,6 +129,13 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
val key = notes.keyAt(i)
|
||||
contacts[key]?.notes = notes.valueAt(i)
|
||||
}
|
||||
|
||||
val organizations = getOrganizations()
|
||||
size = organizations.size()
|
||||
for (i in 0 until size) {
|
||||
val key = organizations.keyAt(i)
|
||||
contacts[key]?.organization = organizations.valueAt(i)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPhoneNumbers(contactId: Int? = null): SparseArray<ArrayList<PhoneNumber>> {
|
||||
|
@ -320,6 +328,41 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
return notes
|
||||
}
|
||||
|
||||
private fun getOrganizations(contactId: Int? = null): SparseArray<String> {
|
||||
val organizations = SparseArray<String>()
|
||||
val uri = ContactsContract.Data.CONTENT_URI
|
||||
val projection = arrayOf(
|
||||
ContactsContract.Data.RAW_CONTACT_ID,
|
||||
CommonDataKinds.Organization.COMPANY
|
||||
)
|
||||
|
||||
var selection = "${ContactsContract.Data.MIMETYPE} = ?"
|
||||
var selectionArgs = arrayOf(CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
|
||||
|
||||
if (contactId != null) {
|
||||
selection += " AND ${ContactsContract.Data.RAW_CONTACT_ID} = ?"
|
||||
selectionArgs = arrayOf(CommonDataKinds.Organization.CONTENT_ITEM_TYPE, contactId.toString())
|
||||
}
|
||||
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
||||
val organization = cursor.getStringValue(CommonDataKinds.Organization.COMPANY) ?: continue
|
||||
organizations.put(id, organization)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
activity.showErrorToast(e)
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
||||
return organizations
|
||||
}
|
||||
|
||||
private fun getContactGroups(storedGroups: ArrayList<Group>, contactId: Int? = null): SparseArray<ArrayList<Group>> {
|
||||
val groups = SparseArray<ArrayList<Group>>()
|
||||
if (!activity.hasContactPermissions()) {
|
||||
|
@ -508,8 +551,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
val contactId = cursor.getIntValue(ContactsContract.Data.CONTACT_ID)
|
||||
val groups = getContactGroups(storedGroups, contactId)[contactId] ?: ArrayList()
|
||||
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
||||
val organization = getOrganizations(id)[id] ?: ""
|
||||
return Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName, starred, contactId,
|
||||
thumbnailUri, null, notes, groups)
|
||||
thumbnailUri, null, notes, groups, organization)
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
|
|
|
@ -267,7 +267,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
val groupIds = Gson().fromJson<ArrayList<Long>>(groupIdsJson, groupIdsToken) ?: ArrayList(1)
|
||||
val groups = storedGroups.filter { groupIds.contains(it.id) } as ArrayList<Group>
|
||||
|
||||
val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred, id, "", photo, notes, groups)
|
||||
val organization = ""
|
||||
|
||||
val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred,
|
||||
id, "", photo, notes, groups, organization)
|
||||
contacts.add(contact)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||
private var curSurname = ""
|
||||
private var curPhotoUri = ""
|
||||
private var curNotes = ""
|
||||
private var curOrganization = ""
|
||||
private var curPhoneNumbers = ArrayList<PhoneNumber>()
|
||||
private var curEmails = ArrayList<Email>()
|
||||
private var curEvents = ArrayList<Event>()
|
||||
|
@ -236,7 +237,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||
|
||||
private fun saveContact(source: String) {
|
||||
val contact = Contact(0, curFirstName, curMiddleName, curSurname, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents,
|
||||
source, 0, 0, "", null, curNotes, curGroups)
|
||||
source, 0, 0, "", null, curNotes, curGroups, curOrganization)
|
||||
if (ContactsHelper(activity).insertContact(contact)) {
|
||||
contactsImported++
|
||||
}
|
||||
|
@ -248,6 +249,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||
curSurname = ""
|
||||
curPhotoUri = ""
|
||||
curNotes = ""
|
||||
curOrganization = ""
|
||||
curPhoneNumbers = ArrayList()
|
||||
curEmails = ArrayList()
|
||||
curEvents = ArrayList()
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
|||
data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String,
|
||||
var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var addresses: ArrayList<Address>, var events: ArrayList<Event>,
|
||||
var source: String, var starred: Int, val contactId: Int, val thumbnailUri: String, var photo: Bitmap?, var notes: String,
|
||||
var groups: ArrayList<Group>) : Comparable<Contact> {
|
||||
var groups: ArrayList<Group>, var organization: String) : Comparable<Contact> {
|
||||
companion object {
|
||||
var sorting = 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue