split organizations into company and job title

This commit is contained in:
tibbi 2018-04-07 16:04:06 +02:00
parent 4b6a27db06
commit cb2e491f65
21 changed files with 134 additions and 18 deletions

View File

@ -386,7 +386,8 @@ 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(), "")
val organization = Organization("", "")
contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), contactSource, 0, 0, "", null, "", ArrayList(), organization)
contact_source.text = getPublicContactSource(contact!!.source)
contact_source.setOnClickListener {
showContactSourcePicker(contact!!.source) {
@ -603,6 +604,10 @@ class EditContactActivity : ContactActivity() {
starred = if (isContactStarred()) 1 else 0
notes = contact_notes.value
val company = contact_organization_company.value
val jobPosition = contact_organization_job_position.value
organization = Organization(company, jobPosition)
Thread {
config.lastUsedContactSource = source
if (id == 0) {

View File

@ -255,9 +255,11 @@ class ViewContactActivity : ContactActivity() {
private fun setupOrganization() {
val organization = contact!!.organization
contact_organization.text = organization
contact_organization_image.beVisibleIf(organization.isNotEmpty())
contact_organization.beVisibleIf(organization.isNotEmpty())
contact_organization_company.text = organization.company
contact_organization_job_position.text = organization.jobPosition
contact_organization_image.beGoneIf(organization.isEmpty())
contact_organization_company.beGoneIf(organization.company.isEmpty())
contact_organization_job_position.beGoneIf(organization.jobPosition.isEmpty())
}
private fun setupGroups() {

View File

@ -83,7 +83,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
val notes = ""
val groups = ArrayList<Group>()
val organization = ""
val organization = Organization("", "")
val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName,
starred, contactId, thumbnailUri, null, notes, groups, organization)
contacts.put(id, contact)
@ -328,12 +328,13 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
return notes
}
private fun getOrganizations(contactId: Int? = null): SparseArray<String> {
val organizations = SparseArray<String>()
private fun getOrganizations(contactId: Int? = null): SparseArray<Organization> {
val organizations = SparseArray<Organization>()
val uri = ContactsContract.Data.CONTENT_URI
val projection = arrayOf(
ContactsContract.Data.RAW_CONTACT_ID,
CommonDataKinds.Organization.COMPANY
CommonDataKinds.Organization.COMPANY,
CommonDataKinds.Organization.TITLE
)
var selection = "${ContactsContract.Data.MIMETYPE} = ?"
@ -350,7 +351,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
if (cursor?.moveToFirst() == true) {
do {
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
val organization = cursor.getStringValue(CommonDataKinds.Organization.COMPANY) ?: continue
val company = cursor.getStringValue(CommonDataKinds.Organization.COMPANY) ?: continue
val title = cursor.getStringValue(CommonDataKinds.Organization.TITLE) ?: continue
val organization = Organization(company, title)
organizations.put(id, organization)
} while (cursor.moveToNext())
}
@ -551,7 +554,7 @@ 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] ?: ""
val organization = getOrganizations(id)[id] ?: Organization("", "")
return Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName, starred, contactId,
thumbnailUri, null, notes, groups, organization)
}
@ -772,6 +775,18 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
operations.add(build())
}
// organization
ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI).apply {
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ? AND ${ContactsContract.Data.MIMETYPE} = ?"
val selectionArgs = arrayOf(contact.id.toString(), CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
withSelection(selection, selectionArgs)
withValue(CommonDataKinds.Organization.COMPANY, contact.organization.company)
withValue(CommonDataKinds.Organization.TYPE, CommonDataKinds.Organization.TYPE_WORK)
withValue(CommonDataKinds.Organization.TITLE, contact.organization.jobPosition)
withValue(CommonDataKinds.Organization.TYPE, CommonDataKinds.Organization.TYPE_WORK)
operations.add(build())
}
// delete groups
val relevantGroupIDs = getStoredGroups().map { it.id }
if (relevantGroupIDs.isNotEmpty()) {
@ -955,6 +970,17 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
operations.add(build())
}
// organization
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
withValue(CommonDataKinds.Organization.COMPANY, contact.organization.company)
withValue(CommonDataKinds.Organization.TYPE, CommonDataKinds.Organization.TYPE_WORK)
withValue(CommonDataKinds.Organization.TITLE, contact.organization.jobPosition)
withValue(CommonDataKinds.Organization.TYPE, CommonDataKinds.Organization.TYPE_WORK)
operations.add(build())
}
// groups
contact.groups.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {

View File

@ -267,7 +267,7 @@ 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 organization = ""
val organization = Organization("", "")
val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred,
id, "", photo, notes, groups, organization)

View File

@ -24,12 +24,12 @@ 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>()
private var curAddresses = ArrayList<Address>()
private var curGroups = ArrayList<Group>()
private var curOrganization = Organization("", "")
private var isGettingPhoto = false
private var currentPhotoString = StringBuilder()
@ -249,12 +249,12 @@ class VcfImporter(val activity: SimpleActivity) {
curSurname = ""
curPhotoUri = ""
curNotes = ""
curOrganization = ""
curPhoneNumbers = ArrayList()
curEmails = ArrayList()
curEvents = ArrayList()
curAddresses = ArrayList()
curGroups = ArrayList()
curOrganization = Organization("", "")
isGettingPhoto = false
currentPhotoString = StringBuilder()

View File

@ -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>, var organization: String) : Comparable<Contact> {
var groups: ArrayList<Group>, var organization: Organization) : Comparable<Contact> {
companion object {
var sorting = 0
}

View File

@ -0,0 +1,5 @@
package com.simplemobiletools.contacts.models
data class Organization(var company: String, var jobPosition: String) {
fun isEmpty() = company.isEmpty() && jobPosition.isEmpty()
}

View File

@ -313,6 +313,47 @@
android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size"/>
<ImageView
android:id="@+id/contact_organization_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_organization_company"
android:paddingBottom="@dimen/small_margin"
android:paddingEnd="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
android:paddingTop="@dimen/medium_margin"
android:src="@drawable/ic_business"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/contact_organization_company"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_notes"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/normal_margin"
android:layout_toRightOf="@+id/contact_organization_image"
android:hint="@string/company"
android:inputType="textCapWords"
android:maxLines="1"
android:singleLine="true"
android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/contact_organization_job_position"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_organization_company"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/normal_margin"
android:layout_toRightOf="@+id/contact_organization_image"
android:hint="@string/job_position"
android:inputType="textCapWords"
android:maxLines="1"
android:singleLine="true"
android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size"/>
<ImageView
android:id="@+id/contact_groups_image"
android:layout_width="@dimen/contact_icons_size"
@ -328,7 +369,7 @@
android:id="@+id/contact_groups_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_notes"
android:layout_below="@+id/contact_organization_job_position"
android:layout_marginTop="@dimen/medium_margin"
android:layout_toRightOf="@+id/contact_name_image"
android:orientation="vertical">

View File

@ -243,7 +243,7 @@
android:id="@+id/contact_organization_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_organization"
android:layout_alignTop="@+id/contact_organization_company"
android:paddingBottom="@dimen/small_margin"
android:paddingEnd="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
@ -251,7 +251,7 @@
android:src="@drawable/ic_business"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/contact_organization"
android:id="@+id/contact_organization_company"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_notes"
@ -263,6 +263,19 @@
android:paddingTop="@dimen/normal_margin"
android:textSize="@dimen/bigger_text_size"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/contact_organization_job_position"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_organization_company"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/contact_organization_image"
android:lineSpacingExtra="@dimen/medium_margin"
android:paddingBottom="@dimen/normal_margin"
android:paddingLeft="@dimen/small_margin"
android:paddingTop="@dimen/normal_margin"
android:textSize="@dimen/bigger_text_size"/>
<ImageView
android:id="@+id/contact_groups_image"
android:layout_width="@dimen/contact_icons_size"
@ -278,7 +291,7 @@
android:id="@+id/contact_groups_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_organization"
android:layout_below="@+id/contact_organization_job_position"
android:layout_toRightOf="@+id/contact_name_image"
android:orientation="vertical"
android:paddingLeft="@dimen/small_margin"/>

View File

@ -6,6 +6,8 @@
<string name="updating">Aktualisiere…</string>
<string name="phone_storage">Gerätespeicher</string>
<string name="phone_storage_hidden">Gerätespeicher (nicht sichtbar für andere Apps)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">Neuer Kontakt</string>
<string name="edit_contact">Kontakt bearbeiten</string>

View File

@ -6,6 +6,8 @@
<string name="updating">Ενημέρωση...</string>
<string name="phone_storage">Μνήμη τηλεφώνου</string>
<string name="phone_storage_hidden">Μνήμη τηλεφώνου (δεν είναι ορατή από άλλες εφαρμογές)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">Νέα επαφή</string>
<string name="edit_contact">Επεξεργασία επαφής</string>

View File

@ -6,6 +6,8 @@
<string name="updating">Mise à jour…</string>
<string name="phone_storage">Stockage du téléphone</string>
<string name="phone_storage_hidden">Stockage du téléphone (non visible par d\'autres applis)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">Nouveau contact</string>
<string name="edit_contact">Modifier contact</string>

View File

@ -6,6 +6,8 @@
<string name="updating">Ažuriranje...</string>
<string name="phone_storage">Pohrana na telefonu</string>
<string name="phone_storage_hidden">Pohrana na telefonu (nije vidljiva drugim aplikacijama))</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">Novi kontakt</string>
<string name="edit_contact">Uredi kontakt</string>

View File

@ -6,6 +6,8 @@
<string name="updating">수정중…</string>
<string name="phone_storage">Phone storage</string>
<string name="phone_storage_hidden">Phone storage (not visible by other apps)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">새로운 연락처</string>
<string name="edit_contact">연락처 수정</string>

View File

@ -6,6 +6,8 @@
<string name="updating">Atnaujinama…</string>
<string name="phone_storage">Telefono atmintis</string>
<string name="phone_storage_hidden">Telefono atmintis (nematoma kitų programėlių)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">Naujas kontaktas</string>
<string name="edit_contact">Redaguoti kontaktą</string>

View File

@ -6,6 +6,8 @@
<string name="updating">A atualizar…</string>
<string name="phone_storage">Armazenamento do telefone</string>
<string name="phone_storage_hidden">Armazenamento do telefone (não visível por outras alicações)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">Novo contacto</string>
<string name="edit_contact">Editar contacto</string>

View File

@ -6,6 +6,8 @@
<string name="updating">Обновление…</string>
<string name="phone_storage">Память устройства</string>
<string name="phone_storage_hidden">Память устройства (не видна другим приложениям)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">Новый контакт</string>
<string name="edit_contact">Редактировать контакт</string>

View File

@ -6,6 +6,8 @@
<string name="updating">Upravuje sa…</string>
<string name="phone_storage">Úložisko mobilu</string>
<string name="phone_storage_hidden">Úložisko mobilu (neviditeľné pre ostatné apky)</string>
<string name="company">Firma</string>
<string name="job_position">Pracovná pozícia</string>
<string name="new_contact">Nový kontakt</string>
<string name="edit_contact">Upraviť kontakt</string>

View File

@ -6,6 +6,8 @@
<string name="updating">Uppdaterar…</string>
<string name="phone_storage">Telefonens lagringsutrymme</string>
<string name="phone_storage_hidden">Telefonens lagringsutrymme (inte synligt för andra appar)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">Ny kontakt</string>
<string name="edit_contact">Redigera kontakt</string>

View File

@ -6,6 +6,8 @@
<string name="updating">更新中…</string>
<string name="phone_storage">手機空間</string>
<string name="phone_storage_hidden">手機空間 (其他程式不可見)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">新聯絡人</string>
<string name="edit_contact">編輯聯絡人</string>

View File

@ -6,6 +6,8 @@
<string name="updating">Updating…</string>
<string name="phone_storage">Phone storage</string>
<string name="phone_storage_hidden">Phone storage (not visible by other apps)</string>
<string name="company">Company</string>
<string name="job_position">Job position</string>
<string name="new_contact">New contact</string>
<string name="edit_contact">Edit contact</string>