show Signal actions too

This commit is contained in:
tibbi 2020-10-27 15:53:54 +01:00
parent 75a4714c3d
commit f537b78aa2
3 changed files with 58 additions and 3 deletions

View File

@ -541,7 +541,15 @@ class ViewContactActivity : ContactActivity() {
contact_source_image.setImageDrawable(getPackageDrawable(WHATSAPP_PACKAGE)) contact_source_image.setImageDrawable(getPackageDrawable(WHATSAPP_PACKAGE))
contact_source_image.beVisible() contact_source_image.beVisible()
contact_source_image.setOnClickListener { contact_source_image.setOnClickListener {
showWhatsAppActions() showWhatsAppActions(key.id)
}
}
if (value.toLowerCase() == SIGNAL) {
contact_source_image.setImageDrawable(getPackageDrawable(SIGNAL_PACKAGE))
contact_source_image.beVisible()
contact_source_image.setOnClickListener {
showSignalActions(key.id)
} }
} }
} }
@ -589,9 +597,25 @@ class ViewContactActivity : ContactActivity() {
} }
} }
private fun showWhatsAppActions() { private fun showWhatsAppActions(contactId: Int) {
ensureBackgroundThread { ensureBackgroundThread {
val actions = getWhatsAppActions(contact!!.id) val actions = getWhatsAppActions(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 showSignalActions(contactId: Int) {
ensureBackgroundThread {
val actions = getSignalActions(contactId)
runOnUiThread { runOnUiThread {
ChooseSocialDialog(this@ViewContactActivity, actions) { action -> ChooseSocialDialog(this@ViewContactActivity, actions) { action ->
Intent(Intent.ACTION_VIEW).apply { Intent(Intent.ACTION_VIEW).apply {

View File

@ -354,6 +354,36 @@ fun Context.getWhatsAppActions(id: Int): ArrayList<SocialAction> {
return socialActions return socialActions
} }
fun Context.getSignalActions(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.thoughtcrime.securesms.contact" -> SOCIAL_MESSAGE
"vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call" -> SOCIAL_VOICE_CALL
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? { fun Context.getPackageDrawable(packageName: String): Drawable? {
var drawable: Drawable? = null var drawable: Drawable? = null
try { try {

View File

@ -108,6 +108,7 @@ const val SIGNAL_PACKAGE = "org.thoughtcrime.securesms"
const val WHATSAPP_PACKAGE = "com.whatsapp" const val WHATSAPP_PACKAGE = "com.whatsapp"
const val WHATSAPP = "whatsapp" const val WHATSAPP = "whatsapp"
const val SIGNAL = "signal"
const val SOCIAL_VOICE_CALL = 0 const val SOCIAL_VOICE_CALL = 0
const val SOCIAL_VIDEO_CALL = 1 const val SOCIAL_VIDEO_CALL = 1