mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
allow adding a contact to Favorites during creating
This commit is contained in:
@ -182,6 +182,12 @@ class EditContactActivity : ContactActivity() {
|
|||||||
contact_email_add_new.setOnClickListener { addNewEmailField() }
|
contact_email_add_new.setOnClickListener { addNewEmailField() }
|
||||||
contact_event_add_new.setOnClickListener { addNewEventField() }
|
contact_event_add_new.setOnClickListener { addNewEventField() }
|
||||||
|
|
||||||
|
contact_toggle_favorite.apply {
|
||||||
|
setImageDrawable(getStarDrawable(contact!!.starred == 1))
|
||||||
|
tag = contact!!.starred
|
||||||
|
applyColorFilter(textColor)
|
||||||
|
}
|
||||||
|
|
||||||
updateTextColors(contact_scrollview)
|
updateTextColors(contact_scrollview)
|
||||||
wasActivityInitialized = true
|
wasActivityInitialized = true
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
@ -213,13 +219,6 @@ class EditContactActivity : ContactActivity() {
|
|||||||
contact_surname.setText(contact!!.surname)
|
contact_surname.setText(contact!!.surname)
|
||||||
contact_source.text = getPublicContactSource(contact!!.source)
|
contact_source.text = getPublicContactSource(contact!!.source)
|
||||||
|
|
||||||
contact_toggle_favorite.apply {
|
|
||||||
beVisible()
|
|
||||||
setImageDrawable(getStarDrawable(contact!!.starred == 1))
|
|
||||||
tag = contact!!.starred
|
|
||||||
applyColorFilter(config.textColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
setupPhoneNumbers()
|
setupPhoneNumbers()
|
||||||
setupEmails()
|
setupEmails()
|
||||||
setupEvents()
|
setupEvents()
|
||||||
|
@ -301,6 +301,24 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
return sort
|
return sort
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getRealContactId(id: Long): Int {
|
||||||
|
val uri = ContactsContract.Data.CONTENT_URI
|
||||||
|
val projection = getContactProjection()
|
||||||
|
val selection = "${ContactsContract.Data.MIMETYPE} = ? AND ${ContactsContract.Data.RAW_CONTACT_ID} = ?"
|
||||||
|
val selectionArgs = arrayOf(CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, id.toString())
|
||||||
|
var cursor: Cursor? = null
|
||||||
|
try {
|
||||||
|
cursor = activity.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
|
if (cursor?.moveToFirst() == true) {
|
||||||
|
return cursor.getIntValue(ContactsContract.Data.CONTACT_ID)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
fun updateContact(contact: Contact, photoUpdateStatus: Int): Boolean {
|
fun updateContact(contact: Contact, photoUpdateStatus: Int): Boolean {
|
||||||
return try {
|
return try {
|
||||||
activity.toast(R.string.updating)
|
activity.toast(R.string.updating)
|
||||||
@ -515,9 +533,18 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fullsize photo
|
// fullsize photo
|
||||||
|
val rawId = ContentUris.parseId(results[0].uri)
|
||||||
if (contact.photoUri.isNotEmpty() && fullSizePhotoData != null) {
|
if (contact.photoUri.isNotEmpty() && fullSizePhotoData != null) {
|
||||||
val rawContactId = ContentUris.parseId(results[0].uri)
|
addFullSizePhoto(rawId, fullSizePhotoData)
|
||||||
addFullSizePhoto(rawContactId, fullSizePhotoData)
|
}
|
||||||
|
|
||||||
|
// favorite
|
||||||
|
val userId = getRealContactId(rawId)
|
||||||
|
if (userId != 0 && contact.starred == 1) {
|
||||||
|
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, userId.toString())
|
||||||
|
val contentValues = ContentValues(1)
|
||||||
|
contentValues.put(ContactsContract.Contacts.STARRED, contact.starred)
|
||||||
|
activity.contentResolver.update(uri, contentValues, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
|
@ -31,8 +31,7 @@
|
|||||||
android:layout_toRightOf="@+id/contact_photo"
|
android:layout_toRightOf="@+id/contact_photo"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:padding="@dimen/tiny_margin"
|
android:padding="@dimen/tiny_margin"
|
||||||
android:src="@drawable/ic_star_off_big"
|
android:src="@drawable/ic_star_off_big"/>
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/contact_actions_holder"
|
android:id="@+id/contact_actions_holder"
|
||||||
|
Reference in New Issue
Block a user