From 4ec6142547fc527b6af91d678dc337c805887ae6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 7 Apr 2018 17:07:22 +0200 Subject: [PATCH] display contact prefix and suffix --- .../activities/EditContactActivity.kt | 2 +- .../activities/ViewContactActivity.kt | 8 +++- .../contacts/helpers/ContactsHelper.kt | 14 +++++-- .../contacts/helpers/DBHelper.kt | 6 ++- .../contacts/helpers/VcfImporter.kt | 6 ++- .../contacts/models/Contact.kt | 6 ++- .../main/res/layout/activity_view_contact.xml | 40 ++++++++++++++++--- 7 files changed, 66 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt index e3e5a38c..cdd0895f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -394,7 +394,7 @@ class EditContactActivity : ContactActivity() { supportActionBar?.title = resources.getString(R.string.new_contact) val contactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE val organization = Organization("", "") - contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), contactSource, 0, 0, "", null, "", ArrayList(), 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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt index 4b5f8308..41edf52d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/ViewContactActivity.kt @@ -137,6 +137,9 @@ class ViewContactActivity : ContactActivity() { private fun setupViewContact() { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) contact!!.apply { + contact_prefix.text = prefix + contact_prefix.beVisibleIf(prefix.isNotEmpty()) + contact_first_name.text = firstName contact_first_name.beVisibleIf(firstName.isNotEmpty()) @@ -146,7 +149,10 @@ class ViewContactActivity : ContactActivity() { contact_surname.text = surname contact_surname.beVisibleIf(surname.isNotEmpty()) - if (firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty()) { + contact_suffix.text = suffix + contact_suffix.beVisibleIf(suffix.isNotEmpty()) + + if (prefix.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty() && suffix.isEmpty()) { contact_name_image.beInvisible() (contact_photo.layoutParams as RelativeLayout.LayoutParams).bottomMargin = resources.getDimension(R.dimen.medium_margin).toInt() } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt index 39cd30a7..8054745b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt @@ -69,9 +69,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) { if (cursor?.moveToFirst() == true) { do { val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) + val prefix = cursor.getStringValue(CommonDataKinds.StructuredName.PREFIX) ?: "" val firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: "" val middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: "" val surname = cursor.getStringValue(CommonDataKinds.StructuredName.FAMILY_NAME) ?: "" + val suffix = cursor.getStringValue(CommonDataKinds.StructuredName.SUFFIX) ?: "" val photoUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_URI) ?: "" val number = ArrayList() // proper value is obtained below val emails = ArrayList() @@ -84,8 +86,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) { val notes = "" val groups = ArrayList() val organization = Organization("", "") - val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName, - starred, contactId, thumbnailUri, null, notes, groups, organization) + val contact = Contact(id, prefix, firstName, middleName, surname, suffix, photoUri, number, emails, addresses, events, + accountName, starred, contactId, thumbnailUri, null, notes, groups, organization) contacts.put(id, contact) } while (cursor.moveToNext()) } @@ -540,9 +542,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) { cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null) if (cursor?.moveToFirst() == true) { val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID) + val prefix = cursor.getStringValue(CommonDataKinds.StructuredName.PREFIX) ?: "" val firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: "" val middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: "" val surname = cursor.getStringValue(CommonDataKinds.StructuredName.FAMILY_NAME) ?: "" + val suffix = cursor.getStringValue(CommonDataKinds.StructuredName.SUFFIX) ?: "" val photoUri = cursor.getStringValue(CommonDataKinds.Phone.PHOTO_URI) ?: "" val number = getPhoneNumbers(id)[id] ?: ArrayList() val emails = getEmails(id)[id] ?: ArrayList() @@ -555,8 +559,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) { val groups = getContactGroups(storedGroups, contactId)[contactId] ?: ArrayList() val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: "" 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) + return Contact(id, prefix, firstName, middleName, surname, suffix, photoUri, number, emails, addresses, events, accountName, + starred, contactId, thumbnailUri, null, notes, groups, organization) } } finally { cursor?.close() @@ -629,9 +633,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) { private fun getContactProjection() = arrayOf( ContactsContract.Data.CONTACT_ID, ContactsContract.Data.RAW_CONTACT_ID, + CommonDataKinds.StructuredName.PREFIX, CommonDataKinds.StructuredName.GIVEN_NAME, CommonDataKinds.StructuredName.MIDDLE_NAME, CommonDataKinds.StructuredName.FAMILY_NAME, + CommonDataKinds.StructuredName.SUFFIX, CommonDataKinds.StructuredName.PHOTO_URI, CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI, CommonDataKinds.StructuredName.STARRED, diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt index 341e4297..cca49b5e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt @@ -232,9 +232,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont cursor.use { while (cursor.moveToNext()) { val id = cursor.getIntValue(COL_ID) + val prefix = "" val firstName = cursor.getStringValue(COL_FIRST_NAME) val middleName = cursor.getStringValue(COL_MIDDLE_NAME) val surname = cursor.getStringValue(COL_SURNAME) + val suffix = "" val phoneNumbersJson = cursor.getStringValue(COL_PHONE_NUMBERS) val phoneNumbersToken = object : TypeToken>() {}.type @@ -269,8 +271,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val organization = Organization("", "") - val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred, - id, "", photo, notes, groups, organization) + val contact = Contact(id, prefix, firstName, middleName, surname, suffix, "", phoneNumbers, emails, addresses, events, + SMT_PRIVATE, starred, id, "", photo, notes, groups, organization) contacts.add(contact) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt index 48cfe6c4..da2f57a3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/VcfImporter.kt @@ -19,9 +19,11 @@ class VcfImporter(val activity: SimpleActivity) { IMPORT_FAIL, IMPORT_OK, IMPORT_PARTIAL } + private var curPrefix = "" private var curFirstName = "" private var curMiddleName = "" private var curSurname = "" + private var curSuffix = "" private var curPhotoUri = "" private var curNotes = "" private var curPhoneNumbers = ArrayList() @@ -236,7 +238,7 @@ class VcfImporter(val activity: SimpleActivity) { } private fun saveContact(source: String) { - val contact = Contact(0, curFirstName, curMiddleName, curSurname, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents, + val contact = Contact(0, curPrefix, curFirstName, curMiddleName, curSurname, curSuffix, curPhotoUri, curPhoneNumbers, curEmails, curAddresses, curEvents, source, 0, 0, "", null, curNotes, curGroups, curOrganization) if (ContactsHelper(activity).insertContact(contact)) { contactsImported++ @@ -244,9 +246,11 @@ class VcfImporter(val activity: SimpleActivity) { } private fun resetValues() { + curPrefix = "" curFirstName = "" curMiddleName = "" curSurname = "" + curSuffix = "" curPhotoUri = "" curNotes = "" curPhoneNumbers = ArrayList() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt index b086c253..58fd2f10 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt @@ -5,7 +5,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME 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, +data class Contact(val id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String, var photoUri: String, var phoneNumbers: ArrayList, var emails: ArrayList, var addresses: ArrayList
, var events: ArrayList, var source: String, var starred: Int, val contactId: Int, val thumbnailUri: String, var photo: Bitmap?, var notes: String, var groups: ArrayList, var organization: Organization) : Comparable { @@ -38,8 +38,10 @@ data class Contact(val id: Int, var firstName: String, var middleName: String, v if (middleName.isNotEmpty()) { firstPart += " $middleName" } + val lastPart = if (startWithSurname) firstName else surname - return "$firstPart $lastPart".trim() + val suffixComma = if (suffix.isEmpty()) "" else ", $suffix" + return "$prefix $firstPart $lastPart$suffixComma".trim() } private fun compareStrings(first: String, second: String): Int { diff --git a/app/src/main/res/layout/activity_view_contact.xml b/app/src/main/res/layout/activity_view_contact.xml index 1939f806..384c7cd2 100644 --- a/app/src/main/res/layout/activity_view_contact.xml +++ b/app/src/main/res/layout/activity_view_contact.xml @@ -18,7 +18,8 @@ + android:layout_height="@dimen/contact_photo_size" + android:layout_marginBottom="@dimen/normal_margin"/> + + + +