display contact prefix and suffix

This commit is contained in:
tibbi 2018-04-07 17:07:22 +02:00
parent 30a3249159
commit 4ec6142547
7 changed files with 66 additions and 16 deletions

View File

@ -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) {

View File

@ -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()
}

View File

@ -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<PhoneNumber>() // proper value is obtained below
val emails = ArrayList<Email>()
@ -84,8 +86,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
val notes = ""
val groups = ArrayList<Group>()
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,

View File

@ -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<List<PhoneNumber>>() {}.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)
}
}

View File

@ -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<PhoneNumber>()
@ -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()

View File

@ -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<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: Organization) : Comparable<Contact> {
@ -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 {

View File

@ -18,7 +18,8 @@
<ImageView
android:id="@+id/contact_photo"
android:layout_width="@dimen/contact_photo_size"
android:layout_height="@dimen/contact_photo_size"/>
android:layout_height="@dimen/contact_photo_size"
android:layout_marginBottom="@dimen/normal_margin"/>
<ImageView
android:id="@+id/contact_toggle_favorite"
@ -83,7 +84,7 @@
android:id="@+id/contact_name_image"
android:layout_width="@dimen/contact_icons_size"
android:layout_height="@dimen/contact_icons_size"
android:layout_alignTop="@+id/contact_first_name"
android:layout_below="@+id/contact_photo"
android:paddingBottom="@dimen/small_margin"
android:paddingEnd="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
@ -91,12 +92,26 @@
android:src="@drawable/ic_person"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/contact_first_name"
android:id="@+id/contact_prefix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_photo"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/normal_margin"
android:layout_toRightOf="@+id/contact_name_image"
android:lines="1"
android:maxLines="1"
android:paddingBottom="@dimen/normal_margin"
android:paddingLeft="@dimen/small_margin"
android:paddingTop="@dimen/normal_margin"
android:singleLine="true"
android:textSize="@dimen/bigger_text_size"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/contact_first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_prefix"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/contact_name_image"
android:lines="1"
android:maxLines="1"
@ -136,6 +151,21 @@
android:singleLine="true"
android:textSize="@dimen/bigger_text_size"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/contact_suffix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_surname"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/contact_name_image"
android:lines="1"
android:maxLines="1"
android:paddingBottom="@dimen/normal_margin"
android:paddingLeft="@dimen/small_margin"
android:paddingTop="@dimen/normal_margin"
android:singleLine="true"
android:textSize="@dimen/bigger_text_size"/>
<ImageView
android:id="@+id/contact_number_image"
android:layout_width="@dimen/contact_icons_size"
@ -151,7 +181,7 @@
android:id="@+id/contact_numbers_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_surname"
android:layout_below="@+id/contact_suffix"
android:layout_toRightOf="@+id/contact_number_image"
android:orientation="vertical"
android:paddingLeft="@dimen/small_margin"/>