adding Viber handling

This commit is contained in:
tibbi 2020-10-27 16:59:25 +01:00
parent e0b13c648a
commit 457a66c4f2
5 changed files with 69 additions and 3 deletions

View File

@ -550,6 +550,14 @@ class ViewContactActivity : ContactActivity() {
showSignalActions(key.id)
}
}
if (value.toLowerCase() == VIBER) {
contact_source_image.setImageDrawable(getPackageDrawable(VIBER_PACKAGE))
contact_source_image.beVisible()
contact_source_image.setOnClickListener {
showViberActions(key.id)
}
}
}
}
@ -627,6 +635,22 @@ class ViewContactActivity : ContactActivity() {
}
}
private fun showViberActions(contactId: Int) {
ensureBackgroundThread {
val actions = getViberActions(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

@ -193,7 +193,10 @@ fun Context.getPublicContactSource(source: String, callback: (String) -> Unit) {
var newSource = source
for (contactSource in it) {
if (contactSource.name == source && contactSource.type == TELEGRAM_PACKAGE) {
newSource += " (${getString(R.string.telegram)})"
newSource = getString(R.string.telegram)
break
} else if (contactSource.name == source && contactSource.type == VIBER_PACKAGE) {
newSource = getString(R.string.viber)
break
}
}
@ -212,7 +215,10 @@ fun Context.getPublicContactSourceSync(source: String, contactSources: ArrayList
var newSource = source
for (contactSource in contactSources) {
if (contactSource.name == source && contactSource.type == TELEGRAM_PACKAGE) {
newSource += " (${getString(R.string.telegram)})"
newSource = getString(R.string.telegram)
break
} else if (contactSource.name == source && contactSource.type == VIBER_PACKAGE) {
newSource = getString(R.string.viber)
break
}
}
@ -384,6 +390,37 @@ fun Context.getSignalActions(id: Int): ArrayList<SocialAction> {
return socialActions
}
fun Context.getViberActions(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.com.viber.voip.viber_number_call" -> SOCIAL_VOICE_CALL
"vnd.android.cursor.item/vnd.com.viber.voip.viber_out_call_viber" -> SOCIAL_VOICE_CALL
"vnd.android.cursor.item/vnd.com.viber.voip.viber_number_message" -> 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

@ -106,9 +106,11 @@ const val DEFAULT_IM_TYPE = CommonDataKinds.Im.PROTOCOL_SKYPE
const val TELEGRAM_PACKAGE = "org.telegram.messenger"
const val SIGNAL_PACKAGE = "org.thoughtcrime.securesms"
const val WHATSAPP_PACKAGE = "com.whatsapp"
const val VIBER_PACKAGE = "com.viber.voip"
const val WHATSAPP = "whatsapp"
const val SIGNAL = "signal"
const val VIBER = "viber"
const val SOCIAL_VOICE_CALL = 0
const val SOCIAL_VIDEO_CALL = 1

View File

@ -770,7 +770,9 @@ class ContactsHelper(val context: Context) {
if (ContentResolver.getIsSyncable(it, AUTHORITY) == 1) {
var publicName = it.name
if (it.type == TELEGRAM_PACKAGE) {
publicName += " (${context.getString(R.string.telegram)})"
publicName = context.getString(R.string.telegram)
} else if (it.type == VIBER_PACKAGE) {
publicName = context.getString(R.string.viber)
}
val contactSource = ContactSource(it.name, it.type, publicName)
sources.add(contactSource)

View File

@ -12,6 +12,7 @@
<string name="icq">ICQ</string>
<string name="jabber">Jabber</string>
<string name="telegram">Telegram</string>
<string name="viber">Viber</string>
<!-- Release notes -->
<string name="release_56">Added an initial implementation of Speed Dial, contacts can be set in the app settings</string>