Merge pull request #279 from Aga-C/open-contact-details
Added opening contact details from the conversation view (#104)
This commit is contained in:
commit
9631e84ef3
|
@ -10,6 +10,7 @@ import android.media.MediaMetadataRetriever
|
|||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.provider.ContactsContract
|
||||
import android.provider.Telephony
|
||||
import android.telephony.SubscriptionManager
|
||||
import android.text.TextUtils
|
||||
|
@ -898,6 +899,31 @@ class ThreadActivity : SimpleActivity() {
|
|||
return participants
|
||||
}
|
||||
|
||||
fun startContactDetailsIntent(contact: SimpleContact) {
|
||||
val simpleContacts = "com.simplemobiletools.contacts.pro"
|
||||
val simpleContactsDebug = "com.simplemobiletools.contacts.pro.debug"
|
||||
if (contact.rawId > 1000000 && contact.contactId > 1000000 && contact.rawId == contact.contactId &&
|
||||
(isPackageInstalled(simpleContacts) || isPackageInstalled(simpleContactsDebug))
|
||||
) {
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
putExtra(CONTACT_ID, contact.rawId)
|
||||
putExtra(IS_PRIVATE, true)
|
||||
`package` = if (isPackageInstalled(simpleContacts)) simpleContacts else simpleContactsDebug
|
||||
setDataAndType(ContactsContract.Contacts.CONTENT_LOOKUP_URI, "vnd.android.cursor.dir/person")
|
||||
launchActivityIntent(this)
|
||||
}
|
||||
} else {
|
||||
ensureBackgroundThread {
|
||||
val lookupKey = SimpleContactsHelper(this).getContactLookupKey((contact).rawId.toString())
|
||||
val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||
runOnUiThread {
|
||||
launchViewContactIntent(publicUri)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun saveMMS(mimeType: String, path: String) {
|
||||
lastAttachmentUri = path
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||
|
|
|
@ -32,6 +32,7 @@ import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
|||
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
|
||||
import com.simplemobiletools.smsmessenger.dialogs.SelectTextDialog
|
||||
import com.simplemobiletools.smsmessenger.extensions.deleteMessage
|
||||
import com.simplemobiletools.smsmessenger.extensions.getContactFromAddress
|
||||
import com.simplemobiletools.smsmessenger.extensions.updateLastConversationMessage
|
||||
import com.simplemobiletools.smsmessenger.helpers.*
|
||||
import com.simplemobiletools.smsmessenger.models.*
|
||||
|
@ -234,6 +235,14 @@ class ThreadAdapter(
|
|||
|
||||
if (message.isReceivedMessage()) {
|
||||
thread_message_sender_photo.beVisible()
|
||||
thread_message_sender_photo.setOnClickListener {
|
||||
val contact = message.participants.first()
|
||||
context.getContactFromAddress(contact.phoneNumbers.first()) {
|
||||
if (it != null) {
|
||||
(activity as ThreadActivity).startContactDetailsIntent(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
thread_message_body.setTextColor(textColor)
|
||||
thread_message_body.setLinkTextColor(context.getAdjustedPrimaryColor())
|
||||
|
||||
|
|
|
@ -684,6 +684,20 @@ fun Context.getNameFromAddress(address: String, privateCursor: Cursor?): String
|
|||
return sender
|
||||
}
|
||||
|
||||
fun Context.getContactFromAddress(address: String, callback: ((contact: SimpleContact?) -> Unit)) {
|
||||
val privateCursor = getMyContactsCursor(false, true)?.loadInBackground()
|
||||
SimpleContactsHelper(this).getAvailableContacts(false) {
|
||||
val contact = it.firstOrNull { it.doesHavePhoneNumber(address) }
|
||||
if (contact == null) {
|
||||
val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
val privateContact = privateContacts.firstOrNull { it.doesHavePhoneNumber(address) }
|
||||
callback(privateContact)
|
||||
} else {
|
||||
callback(contact)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun Context.showMessageNotification(address: String, body: String, threadId: Long, bitmap: Bitmap?, sender: String) {
|
||||
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
|
Loading…
Reference in New Issue