mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-03-11 16:50:26 +01:00
allow adding a contact to Favorites during creating
This commit is contained in:
parent
962ff318e6
commit
dd678cc7d2
@ -182,6 +182,12 @@ class EditContactActivity : ContactActivity() {
|
||||
contact_email_add_new.setOnClickListener { addNewEmailField() }
|
||||
contact_event_add_new.setOnClickListener { addNewEventField() }
|
||||
|
||||
contact_toggle_favorite.apply {
|
||||
setImageDrawable(getStarDrawable(contact!!.starred == 1))
|
||||
tag = contact!!.starred
|
||||
applyColorFilter(textColor)
|
||||
}
|
||||
|
||||
updateTextColors(contact_scrollview)
|
||||
wasActivityInitialized = true
|
||||
invalidateOptionsMenu()
|
||||
@ -213,13 +219,6 @@ class EditContactActivity : ContactActivity() {
|
||||
contact_surname.setText(contact!!.surname)
|
||||
contact_source.text = getPublicContactSource(contact!!.source)
|
||||
|
||||
contact_toggle_favorite.apply {
|
||||
beVisible()
|
||||
setImageDrawable(getStarDrawable(contact!!.starred == 1))
|
||||
tag = contact!!.starred
|
||||
applyColorFilter(config.textColor)
|
||||
}
|
||||
|
||||
setupPhoneNumbers()
|
||||
setupEmails()
|
||||
setupEvents()
|
||||
|
@ -301,6 +301,24 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
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 {
|
||||
return try {
|
||||
activity.toast(R.string.updating)
|
||||
@ -515,9 +533,18 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
}
|
||||
|
||||
// fullsize photo
|
||||
val rawId = ContentUris.parseId(results[0].uri)
|
||||
if (contact.photoUri.isNotEmpty() && fullSizePhotoData != null) {
|
||||
val rawContactId = ContentUris.parseId(results[0].uri)
|
||||
addFullSizePhoto(rawContactId, fullSizePhotoData)
|
||||
addFullSizePhoto(rawId, 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
|
||||
|
@ -31,8 +31,7 @@
|
||||
android:layout_toRightOf="@+id/contact_photo"
|
||||
android:adjustViewBounds="true"
|
||||
android:padding="@dimen/tiny_margin"
|
||||
android:src="@drawable/ic_star_off_big"
|
||||
android:visibility="gone"/>
|
||||
android:src="@drawable/ic_star_off_big"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/contact_actions_holder"
|
||||
|
Loading…
x
Reference in New Issue
Block a user