split the name at the Contact activity layout too

This commit is contained in:
tibbi 2017-12-13 13:39:22 +01:00
parent 791dbb2960
commit 51030dbff1
6 changed files with 54 additions and 20 deletions

View file

@ -135,7 +135,9 @@ class ContactActivity : SimpleActivity() {
private fun setupEditContact() {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
supportActionBar?.title = resources.getString(R.string.edit_contact)
contact_name.setText(contact!!.firstName)
contact_first_name.setText(contact!!.firstName)
contact_middle_name.setText(contact!!.middleName)
contact_surname.setText(contact!!.surname)
contact_number.setText(contact!!.number)
contact_email.setText(contact!!.email)
}

View file

@ -100,8 +100,8 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
private fun setupView(view: View, contact: Contact) {
view.apply {
contact_name.text = contact.getFullName()
contact_name.setTextColor(textColor)
contact_first_name.text = contact.getFullName()
contact_first_name.setTextColor(textColor)
contact_number.text = contact.number
contact_number.setTextColor(textColor)

View file

@ -58,15 +58,15 @@ class ContactsHelper(val activity: SimpleActivity) {
val id = cursor.getIntValue(ContactsContract.CommonDataKinds.StructuredName.CONTACT_ID)
val firstName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME) ?: ""
val middleName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
val familyName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
if (firstName.isEmpty() && middleName.isEmpty() && familyName.isEmpty())
val surname = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
if (firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty())
continue
val photoUri = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI) ?: ""
val number = "" // proper value is obtained below
val email = "" // proper value is obtained below
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
val contact = Contact(id, firstName, middleName, familyName, photoUri, number, email, accountName)
val contact = Contact(id, firstName, middleName, surname, photoUri, number, email, accountName)
contacts.put(id, contact)
} while (cursor.moveToNext())
}
@ -203,12 +203,12 @@ class ContactsHelper(val activity: SimpleActivity) {
if (cursor?.moveToFirst() == true) {
val firstName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME) ?: ""
val middleName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
val familyName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
val surname = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
val photoUri = cursor.getStringValue(ContactsContract.CommonDataKinds.Phone.PHOTO_URI) ?: ""
val number = getContactNumber(id)
val email = getContactEmail(id)
val accountName = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_NAME)
return Contact(id, firstName, middleName, familyName, photoUri, number, email, accountName)
return Contact(id, firstName, middleName, surname, photoUri, number, email, accountName)
}
} finally {
cursor?.close()

View file

@ -3,7 +3,7 @@ package com.simplemobiletools.contacts.models
import com.simplemobiletools.commons.helpers.SORT_BY_NUMBER
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
data class Contact(val id: Int, var firstName: String, var middleName: String, var familyName: String, var photoUri: String, var number: String,
data class Contact(val id: Int, var firstName: String, var middleName: String, var surname: String, var photoUri: String, var number: String,
var email: String, var source: String) : Comparable<Contact> {
companion object {
var sorting: Int = 0
@ -38,6 +38,6 @@ data class Contact(val id: Int, var firstName: String, var middleName: String, v
if (middleName.isNotEmpty()) {
name += " $middleName"
}
return "$name $familyName".trim()
return "$name $surname".trim()
}
}

View file

@ -3,13 +3,13 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contact_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin">
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/contact_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin">
<ImageView
android:id="@+id/contact_photo"
@ -63,14 +63,14 @@
android:id="@+id/contact_name_image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/contact_name"
android:layout_alignTop="@+id/contact_name"
android:layout_alignBottom="@+id/contact_first_name"
android:layout_alignTop="@+id/contact_first_name"
android:paddingBottom="@dimen/medium_margin"
android:paddingTop="@dimen/medium_margin"
android:src="@drawable/ic_person"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/contact_name"
android:id="@+id/contact_first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_photo"
@ -78,7 +78,39 @@
android:layout_marginStart="@dimen/medium_margin"
android:layout_marginTop="@dimen/activity_margin"
android:layout_toRightOf="@+id/contact_name_image"
android:hint="@string/name"
android:hint="@string/first_name"
android:inputType="textCapWords"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:textSize="@dimen/big_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/contact_middle_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_first_name"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/medium_margin"
android:layout_marginTop="@dimen/activity_margin"
android:layout_toRightOf="@+id/contact_name_image"
android:hint="@string/middle_name"
android:inputType="textCapWords"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:textSize="@dimen/big_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/contact_surname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_middle_name"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/medium_margin"
android:layout_marginTop="@dimen/activity_margin"
android:layout_toRightOf="@+id/contact_name_image"
android:hint="@string/surname"
android:inputType="textCapWords"
android:lines="1"
android:maxLines="1"
@ -99,7 +131,7 @@
android:id="@+id/contact_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_name"
android:layout_below="@+id/contact_surname"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/medium_margin"
android:layout_marginTop="@dimen/activity_margin"

View file

@ -24,7 +24,7 @@
android:src="@drawable/ic_person"/>
<TextView
android:id="@+id/contact_name"
android:id="@+id/contact_first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/contact_tmb"
@ -40,7 +40,7 @@
android:id="@+id/contact_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_name"
android:layout_below="@+id/contact_first_name"
android:layout_toRightOf="@+id/contact_tmb"
android:maxLines="1"
android:paddingLeft="@dimen/small_margin"