diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt index e432709a..f3d3bdb2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ViewContactActivity.kt @@ -11,10 +11,7 @@ import android.view.WindowManager import android.widget.RelativeLayout import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.CONTACT_ID -import com.simplemobiletools.commons.helpers.IS_PRIVATE -import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS -import com.simplemobiletools.commons.helpers.ensureBackgroundThread +import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.dialogs.CallConfirmationDialog import com.simplemobiletools.contacts.pro.dialogs.ChooseSocialDialog @@ -558,6 +555,14 @@ class ViewContactActivity : ContactActivity() { showViberActions(key.id) } } + + if (value.toLowerCase() == TELEGRAM) { + contact_source_image.setImageDrawable(getPackageDrawable(TELEGRAM_PACKAGE)) + contact_source_image.beVisible() + contact_source_image.setOnClickListener { + showTelegramActions(key.id) + } + } } } @@ -651,6 +656,22 @@ class ViewContactActivity : ContactActivity() { } } + private fun showTelegramActions(contactId: Int) { + ensureBackgroundThread { + val actions = getTelegramActions(contactId) + runOnUiThread { + ChooseSocialDialog(this@ViewContactActivity, actions) { action -> + Intent(Intent.ACTION_VIEW).apply { + val uri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, action.dataId) + setDataAndType(uri, action.mimetype) + flags = Intent.FLAG_ACTIVITY_CLEAR_TASK + startActivity(this) + } + } + } + } + } + private fun getDuplicateContacts(callback: () -> Unit) { ContactsHelper(this).getDuplicatesOfContact(contact!!, false) { contacts -> ensureBackgroundThread { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt index 6cad3be7..3c1b8fad 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt @@ -421,6 +421,38 @@ fun Context.getViberActions(id: Int): ArrayList { return socialActions } +fun Context.getTelegramActions(id: Int): ArrayList { + val uri = ContactsContract.Data.CONTENT_URI + val projection = arrayOf( + ContactsContract.Data._ID, + ContactsContract.Data.DATA3, + ContactsContract.Data.MIMETYPE, + ContactsContract.Data.ACCOUNT_TYPE_AND_DATA_SET + ) + + val socialActions = ArrayList() + var curActionId = 0 + val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ?" + val selectionArgs = arrayOf(id.toString()) + queryCursor(uri, projection, selection, selectionArgs, null, true) { cursor -> + val mimetype = cursor.getStringValue(ContactsContract.Data.MIMETYPE) + val type = when (mimetype) { + "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call" -> SOCIAL_VOICE_CALL + "vnd.android.cursor.item/vnd.org.telegram.messenger.android.call.video" -> SOCIAL_VIDEO_CALL + "vnd.android.cursor.item/vnd.org.telegram.messenger.android.profile" -> SOCIAL_MESSAGE + else -> return@queryCursor + } + + val label = cursor.getStringValue(ContactsContract.Data.DATA3) + val realID = cursor.getLongValue(ContactsContract.Data._ID) + val packageName = cursor.getStringValue(ContactsContract.Data.ACCOUNT_TYPE_AND_DATA_SET) + val socialAction = SocialAction(curActionId++, type, label, mimetype, realID, packageName) + socialActions.add(socialAction) + } + + return socialActions +} + fun Context.getPackageDrawable(packageName: String): Drawable? { var drawable: Drawable? = null try { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt index 08e7ef51..ca6720f4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt @@ -111,6 +111,7 @@ const val VIBER_PACKAGE = "com.viber.voip" const val WHATSAPP = "whatsapp" const val SIGNAL = "signal" const val VIBER = "viber" +const val TELEGRAM = "telegram" const val SOCIAL_VOICE_CALL = 0 const val SOCIAL_VIDEO_CALL = 1