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 bf6982da..e432709a 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 @@ -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 { 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 d38532e6..6cad3be7 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 @@ -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 { return socialActions } +fun Context.getViberActions(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.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 { 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 a2a076a8..08e7ef51 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 @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt index f0b2ae1a..91f5e697 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/ContactsHelper.kt @@ -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) diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 85c7c909..a49dc323 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -12,6 +12,7 @@ ICQ Jabber Telegram + Viber Added an initial implementation of Speed Dial, contacts can be set in the app settings