show Telegram actions

This commit is contained in:
tibbi 2020-10-27 17:33:38 +01:00
parent b28571db15
commit 4995308818
3 changed files with 58 additions and 4 deletions

View File

@ -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 {

View File

@ -421,6 +421,38 @@ fun Context.getViberActions(id: Int): ArrayList<SocialAction> {
return socialActions
}
fun Context.getTelegramActions(id: Int): ArrayList<SocialAction> {
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<SocialAction>()
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 {

View File

@ -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