fix nickname adding and editing at contacts

This commit is contained in:
tibbi 2018-08-12 22:13:28 +02:00
parent 0335bdf10d
commit 1b28f626aa
3 changed files with 44 additions and 1 deletions

View File

@ -279,6 +279,7 @@ class EditContactActivity : ContactActivity() {
contact_middle_name.beVisibleIf(showFields and SHOW_MIDDLE_NAME_FIELD != 0)
contact_surname.beVisibleIf(showFields and SHOW_SURNAME_FIELD != 0)
contact_suffix.beVisibleIf(showFields and SHOW_SUFFIX_FIELD != 0)
contact_nickname.beVisibleIf(showFields and SHOW_NICKNAME_FIELD != 0)
contact_source.beVisibleIf(showFields and SHOW_CONTACT_SOURCE_FIELD != 0)
contact_source_image.beVisibleIf(showFields and SHOW_CONTACT_SOURCE_FIELD != 0)
@ -346,6 +347,7 @@ class EditContactActivity : ContactActivity() {
contact_middle_name.setText(middleName)
contact_surname.setText(surname)
contact_suffix.setText(suffix)
contact_nickname.setText(nickname)
}
}
@ -715,6 +717,7 @@ class EditContactActivity : ContactActivity() {
middleName = contact_middle_name.value
surname = contact_surname.value
suffix = contact_suffix.value
nickname = contact_nickname.value
photoUri = currentContactPhotoPath
phoneNumbers = getFilledPhoneNumbers()
emails = getFilledEmails()

View File

@ -825,6 +825,22 @@ class ContactsHelper(val activity: Activity) {
operations.add(build())
}
// delete nickname
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).apply {
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ? AND ${ContactsContract.Data.MIMETYPE} = ? "
val selectionArgs = arrayOf(contact.id.toString(), Nickname.CONTENT_ITEM_TYPE)
withSelection(selection, selectionArgs)
operations.add(build())
}
// add nickname
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
withValue(ContactsContract.Data.RAW_CONTACT_ID, contact.id)
withValue(ContactsContract.Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
withValue(Nickname.NAME, contact.nickname)
operations.add(build())
}
// delete phone numbers
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).apply {
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ? AND ${ContactsContract.Data.MIMETYPE} = ? "
@ -1089,6 +1105,14 @@ class ContactsHelper(val activity: Activity) {
operations.add(build())
}
// nickname
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
withValue(ContactsContract.Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
withValue(Nickname.NAME, contact.nickname)
operations.add(build())
}
// phone numbers
contact.phoneNumbers.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {

View File

@ -170,6 +170,22 @@
android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size"/>
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/contact_nickname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_suffix"
android:layout_centerVertical="true"
android:layout_marginBottom="@dimen/medium_margin"
android:layout_toRightOf="@+id/contact_name_image"
android:hint="@string/nickname"
android:inputType="textCapWords"
android:lines="1"
android:maxLines="1"
android:singleLine="true"
android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size"/>
<ImageView
android:id="@+id/contact_numbers_image"
android:layout_width="@dimen/contact_icons_size"
@ -185,7 +201,7 @@
android:id="@+id/contact_numbers_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/contact_suffix"
android:layout_below="@+id/contact_nickname"
android:layout_marginBottom="@dimen/small_margin"
android:layout_toRightOf="@+id/contact_numbers_image"
android:orientation="vertical">