display contact prefix and suffix
This commit is contained in:
parent
30a3249159
commit
4ec6142547
|
@ -394,7 +394,7 @@ class EditContactActivity : ContactActivity() {
|
||||||
supportActionBar?.title = resources.getString(R.string.new_contact)
|
supportActionBar?.title = resources.getString(R.string.new_contact)
|
||||||
val contactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
val contactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
||||||
val organization = Organization("", "")
|
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.text = getPublicContactSource(contact!!.source)
|
||||||
contact_source.setOnClickListener {
|
contact_source.setOnClickListener {
|
||||||
showContactSourcePicker(contact!!.source) {
|
showContactSourcePicker(contact!!.source) {
|
||||||
|
|
|
@ -137,6 +137,9 @@ class ViewContactActivity : ContactActivity() {
|
||||||
private fun setupViewContact() {
|
private fun setupViewContact() {
|
||||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
|
||||||
contact!!.apply {
|
contact!!.apply {
|
||||||
|
contact_prefix.text = prefix
|
||||||
|
contact_prefix.beVisibleIf(prefix.isNotEmpty())
|
||||||
|
|
||||||
contact_first_name.text = firstName
|
contact_first_name.text = firstName
|
||||||
contact_first_name.beVisibleIf(firstName.isNotEmpty())
|
contact_first_name.beVisibleIf(firstName.isNotEmpty())
|
||||||
|
|
||||||
|
@ -146,7 +149,10 @@ class ViewContactActivity : ContactActivity() {
|
||||||
contact_surname.text = surname
|
contact_surname.text = surname
|
||||||
contact_surname.beVisibleIf(surname.isNotEmpty())
|
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_name_image.beInvisible()
|
||||||
(contact_photo.layoutParams as RelativeLayout.LayoutParams).bottomMargin = resources.getDimension(R.dimen.medium_margin).toInt()
|
(contact_photo.layoutParams as RelativeLayout.LayoutParams).bottomMargin = resources.getDimension(R.dimen.medium_margin).toInt()
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,9 +69,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
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 firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: ""
|
||||||
val middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
val middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
||||||
val surname = cursor.getStringValue(CommonDataKinds.StructuredName.FAMILY_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 photoUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_URI) ?: ""
|
||||||
val number = ArrayList<PhoneNumber>() // proper value is obtained below
|
val number = ArrayList<PhoneNumber>() // proper value is obtained below
|
||||||
val emails = ArrayList<Email>()
|
val emails = ArrayList<Email>()
|
||||||
|
@ -84,8 +86,8 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
val notes = ""
|
val notes = ""
|
||||||
val groups = ArrayList<Group>()
|
val groups = ArrayList<Group>()
|
||||||
val organization = Organization("", "")
|
val organization = Organization("", "")
|
||||||
val contact = Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName,
|
val contact = Contact(id, prefix, firstName, middleName, surname, suffix, photoUri, number, emails, addresses, events,
|
||||||
starred, contactId, thumbnailUri, null, notes, groups, organization)
|
accountName, starred, contactId, thumbnailUri, null, notes, groups, organization)
|
||||||
contacts.put(id, contact)
|
contacts.put(id, contact)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
|
@ -540,9 +542,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
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 firstName = cursor.getStringValue(CommonDataKinds.StructuredName.GIVEN_NAME) ?: ""
|
||||||
val middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
val middleName = cursor.getStringValue(CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
|
||||||
val surname = cursor.getStringValue(CommonDataKinds.StructuredName.FAMILY_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 photoUri = cursor.getStringValue(CommonDataKinds.Phone.PHOTO_URI) ?: ""
|
||||||
val number = getPhoneNumbers(id)[id] ?: ArrayList()
|
val number = getPhoneNumbers(id)[id] ?: ArrayList()
|
||||||
val emails = getEmails(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 groups = getContactGroups(storedGroups, contactId)[contactId] ?: ArrayList()
|
||||||
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
val thumbnailUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
|
||||||
val organization = getOrganizations(id)[id] ?: Organization("", "")
|
val organization = getOrganizations(id)[id] ?: Organization("", "")
|
||||||
return Contact(id, firstName, middleName, surname, photoUri, number, emails, addresses, events, accountName, starred, contactId,
|
return Contact(id, prefix, firstName, middleName, surname, suffix, photoUri, number, emails, addresses, events, accountName,
|
||||||
thumbnailUri, null, notes, groups, organization)
|
starred, contactId, thumbnailUri, null, notes, groups, organization)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
|
@ -629,9 +633,11 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
private fun getContactProjection() = arrayOf(
|
private fun getContactProjection() = arrayOf(
|
||||||
ContactsContract.Data.CONTACT_ID,
|
ContactsContract.Data.CONTACT_ID,
|
||||||
ContactsContract.Data.RAW_CONTACT_ID,
|
ContactsContract.Data.RAW_CONTACT_ID,
|
||||||
|
CommonDataKinds.StructuredName.PREFIX,
|
||||||
CommonDataKinds.StructuredName.GIVEN_NAME,
|
CommonDataKinds.StructuredName.GIVEN_NAME,
|
||||||
CommonDataKinds.StructuredName.MIDDLE_NAME,
|
CommonDataKinds.StructuredName.MIDDLE_NAME,
|
||||||
CommonDataKinds.StructuredName.FAMILY_NAME,
|
CommonDataKinds.StructuredName.FAMILY_NAME,
|
||||||
|
CommonDataKinds.StructuredName.SUFFIX,
|
||||||
CommonDataKinds.StructuredName.PHOTO_URI,
|
CommonDataKinds.StructuredName.PHOTO_URI,
|
||||||
CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI,
|
CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI,
|
||||||
CommonDataKinds.StructuredName.STARRED,
|
CommonDataKinds.StructuredName.STARRED,
|
||||||
|
|
|
@ -232,9 +232,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
cursor.use {
|
cursor.use {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val id = cursor.getIntValue(COL_ID)
|
val id = cursor.getIntValue(COL_ID)
|
||||||
|
val prefix = ""
|
||||||
val firstName = cursor.getStringValue(COL_FIRST_NAME)
|
val firstName = cursor.getStringValue(COL_FIRST_NAME)
|
||||||
val middleName = cursor.getStringValue(COL_MIDDLE_NAME)
|
val middleName = cursor.getStringValue(COL_MIDDLE_NAME)
|
||||||
val surname = cursor.getStringValue(COL_SURNAME)
|
val surname = cursor.getStringValue(COL_SURNAME)
|
||||||
|
val suffix = ""
|
||||||
|
|
||||||
val phoneNumbersJson = cursor.getStringValue(COL_PHONE_NUMBERS)
|
val phoneNumbersJson = cursor.getStringValue(COL_PHONE_NUMBERS)
|
||||||
val phoneNumbersToken = object : TypeToken<List<PhoneNumber>>() {}.type
|
val phoneNumbersToken = object : TypeToken<List<PhoneNumber>>() {}.type
|
||||||
|
@ -269,8 +271,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
|
|
||||||
val organization = Organization("", "")
|
val organization = Organization("", "")
|
||||||
|
|
||||||
val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred,
|
val contact = Contact(id, prefix, firstName, middleName, surname, suffix, "", phoneNumbers, emails, addresses, events,
|
||||||
id, "", photo, notes, groups, organization)
|
SMT_PRIVATE, starred, id, "", photo, notes, groups, organization)
|
||||||
contacts.add(contact)
|
contacts.add(contact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,11 @@ class VcfImporter(val activity: SimpleActivity) {
|
||||||
IMPORT_FAIL, IMPORT_OK, IMPORT_PARTIAL
|
IMPORT_FAIL, IMPORT_OK, IMPORT_PARTIAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var curPrefix = ""
|
||||||
private var curFirstName = ""
|
private var curFirstName = ""
|
||||||
private var curMiddleName = ""
|
private var curMiddleName = ""
|
||||||
private var curSurname = ""
|
private var curSurname = ""
|
||||||
|
private var curSuffix = ""
|
||||||
private var curPhotoUri = ""
|
private var curPhotoUri = ""
|
||||||
private var curNotes = ""
|
private var curNotes = ""
|
||||||
private var curPhoneNumbers = ArrayList<PhoneNumber>()
|
private var curPhoneNumbers = ArrayList<PhoneNumber>()
|
||||||
|
@ -236,7 +238,7 @@ class VcfImporter(val activity: SimpleActivity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveContact(source: String) {
|
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)
|
source, 0, 0, "", null, curNotes, curGroups, curOrganization)
|
||||||
if (ContactsHelper(activity).insertContact(contact)) {
|
if (ContactsHelper(activity).insertContact(contact)) {
|
||||||
contactsImported++
|
contactsImported++
|
||||||
|
@ -244,9 +246,11 @@ class VcfImporter(val activity: SimpleActivity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resetValues() {
|
private fun resetValues() {
|
||||||
|
curPrefix = ""
|
||||||
curFirstName = ""
|
curFirstName = ""
|
||||||
curMiddleName = ""
|
curMiddleName = ""
|
||||||
curSurname = ""
|
curSurname = ""
|
||||||
|
curSuffix = ""
|
||||||
curPhotoUri = ""
|
curPhotoUri = ""
|
||||||
curNotes = ""
|
curNotes = ""
|
||||||
curPhoneNumbers = ArrayList()
|
curPhoneNumbers = ArrayList()
|
||||||
|
|
|
@ -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_BY_MIDDLE_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
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 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 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> {
|
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()) {
|
if (middleName.isNotEmpty()) {
|
||||||
firstPart += " $middleName"
|
firstPart += " $middleName"
|
||||||
}
|
}
|
||||||
|
|
||||||
val lastPart = if (startWithSurname) firstName else surname
|
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 {
|
private fun compareStrings(first: String, second: String): Int {
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/contact_photo"
|
android:id="@+id/contact_photo"
|
||||||
android:layout_width="@dimen/contact_photo_size"
|
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
|
<ImageView
|
||||||
android:id="@+id/contact_toggle_favorite"
|
android:id="@+id/contact_toggle_favorite"
|
||||||
|
@ -83,7 +84,7 @@
|
||||||
android:id="@+id/contact_name_image"
|
android:id="@+id/contact_name_image"
|
||||||
android:layout_width="@dimen/contact_icons_size"
|
android:layout_width="@dimen/contact_icons_size"
|
||||||
android:layout_height="@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:paddingBottom="@dimen/small_margin"
|
||||||
android:paddingEnd="@dimen/small_margin"
|
android:paddingEnd="@dimen/small_margin"
|
||||||
android:paddingRight="@dimen/small_margin"
|
android:paddingRight="@dimen/small_margin"
|
||||||
|
@ -91,12 +92,26 @@
|
||||||
android:src="@drawable/ic_person"/>
|
android:src="@drawable/ic_person"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
android:id="@+id/contact_first_name"
|
android:id="@+id/contact_prefix"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/contact_photo"
|
android:layout_below="@+id/contact_photo"
|
||||||
android:layout_centerVertical="true"
|
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:layout_toRightOf="@+id/contact_name_image"
|
||||||
android:lines="1"
|
android:lines="1"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
|
@ -136,6 +151,21 @@
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textSize="@dimen/bigger_text_size"/>
|
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
|
<ImageView
|
||||||
android:id="@+id/contact_number_image"
|
android:id="@+id/contact_number_image"
|
||||||
android:layout_width="@dimen/contact_icons_size"
|
android:layout_width="@dimen/contact_icons_size"
|
||||||
|
@ -151,7 +181,7 @@
|
||||||
android:id="@+id/contact_numbers_holder"
|
android:id="@+id/contact_numbers_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
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:layout_toRightOf="@+id/contact_number_image"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingLeft="@dimen/small_margin"/>
|
android:paddingLeft="@dimen/small_margin"/>
|
||||||
|
|
Loading…
Reference in New Issue