removing some social action fetching related code duplication
This commit is contained in:
parent
4995308818
commit
ab44c35fac
2 changed files with 17 additions and 140 deletions
|
@ -11,7 +11,10 @@ import android.view.WindowManager
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
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.contacts.pro.R
|
import com.simplemobiletools.contacts.pro.R
|
||||||
import com.simplemobiletools.contacts.pro.dialogs.CallConfirmationDialog
|
import com.simplemobiletools.contacts.pro.dialogs.CallConfirmationDialog
|
||||||
import com.simplemobiletools.contacts.pro.dialogs.ChooseSocialDialog
|
import com.simplemobiletools.contacts.pro.dialogs.ChooseSocialDialog
|
||||||
|
@ -536,7 +539,7 @@ 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(key.id)
|
showSocialActions(key.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,7 +547,7 @@ class ViewContactActivity : ContactActivity() {
|
||||||
contact_source_image.setImageDrawable(getPackageDrawable(SIGNAL_PACKAGE))
|
contact_source_image.setImageDrawable(getPackageDrawable(SIGNAL_PACKAGE))
|
||||||
contact_source_image.beVisible()
|
contact_source_image.beVisible()
|
||||||
contact_source_image.setOnClickListener {
|
contact_source_image.setOnClickListener {
|
||||||
showSignalActions(key.id)
|
showSocialActions(key.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,7 +555,7 @@ class ViewContactActivity : ContactActivity() {
|
||||||
contact_source_image.setImageDrawable(getPackageDrawable(VIBER_PACKAGE))
|
contact_source_image.setImageDrawable(getPackageDrawable(VIBER_PACKAGE))
|
||||||
contact_source_image.beVisible()
|
contact_source_image.beVisible()
|
||||||
contact_source_image.setOnClickListener {
|
contact_source_image.setOnClickListener {
|
||||||
showViberActions(key.id)
|
showSocialActions(key.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,7 +563,7 @@ class ViewContactActivity : ContactActivity() {
|
||||||
contact_source_image.setImageDrawable(getPackageDrawable(TELEGRAM_PACKAGE))
|
contact_source_image.setImageDrawable(getPackageDrawable(TELEGRAM_PACKAGE))
|
||||||
contact_source_image.beVisible()
|
contact_source_image.beVisible()
|
||||||
contact_source_image.setOnClickListener {
|
contact_source_image.setOnClickListener {
|
||||||
showTelegramActions(key.id)
|
showSocialActions(key.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -608,57 +611,9 @@ class ViewContactActivity : ContactActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showWhatsAppActions(contactId: Int) {
|
private fun showSocialActions(contactId: Int) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val actions = getWhatsAppActions(contactId)
|
val actions = getSocialActions(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 {
|
|
||||||
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 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 showTelegramActions(contactId: Int) {
|
|
||||||
ensureBackgroundThread {
|
|
||||||
val actions = getTelegramActions(contactId)
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
ChooseSocialDialog(this@ViewContactActivity, actions) { action ->
|
ChooseSocialDialog(this@ViewContactActivity, actions) { action ->
|
||||||
Intent(Intent.ACTION_VIEW).apply {
|
Intent(Intent.ACTION_VIEW).apply {
|
||||||
|
|
|
@ -329,7 +329,7 @@ fun Context.getAllContactSources(): ArrayList<ContactSource> {
|
||||||
|
|
||||||
fun Context.getPrivateContactSource() = ContactSource(SMT_PRIVATE, SMT_PRIVATE, getString(R.string.phone_storage_hidden))
|
fun Context.getPrivateContactSource() = ContactSource(SMT_PRIVATE, SMT_PRIVATE, getString(R.string.phone_storage_hidden))
|
||||||
|
|
||||||
fun Context.getWhatsAppActions(id: Int): ArrayList<SocialAction> {
|
fun Context.getSocialActions(id: Int): ArrayList<SocialAction> {
|
||||||
val uri = ContactsContract.Data.CONTENT_URI
|
val uri = ContactsContract.Data.CONTENT_URI
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
ContactsContract.Data._ID,
|
ContactsContract.Data._ID,
|
||||||
|
@ -345,98 +345,21 @@ fun Context.getWhatsAppActions(id: Int): ArrayList<SocialAction> {
|
||||||
queryCursor(uri, projection, selection, selectionArgs, null, true) { cursor ->
|
queryCursor(uri, projection, selection, selectionArgs, null, true) { cursor ->
|
||||||
val mimetype = cursor.getStringValue(ContactsContract.Data.MIMETYPE)
|
val mimetype = cursor.getStringValue(ContactsContract.Data.MIMETYPE)
|
||||||
val type = when (mimetype) {
|
val type = when (mimetype) {
|
||||||
|
// WhatsApp
|
||||||
"vnd.android.cursor.item/vnd.com.whatsapp.profile" -> SOCIAL_MESSAGE
|
"vnd.android.cursor.item/vnd.com.whatsapp.profile" -> SOCIAL_MESSAGE
|
||||||
"vnd.android.cursor.item/vnd.com.whatsapp.voip.call" -> SOCIAL_VOICE_CALL
|
"vnd.android.cursor.item/vnd.com.whatsapp.voip.call" -> SOCIAL_VOICE_CALL
|
||||||
"vnd.android.cursor.item/vnd.com.whatsapp.video.call" -> SOCIAL_VIDEO_CALL
|
"vnd.android.cursor.item/vnd.com.whatsapp.video.call" -> SOCIAL_VIDEO_CALL
|
||||||
else -> return@queryCursor
|
|
||||||
}
|
|
||||||
|
|
||||||
val label = cursor.getStringValue(ContactsContract.Data.DATA3)
|
// Viber
|
||||||
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.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.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_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_out_call_viber" -> SOCIAL_VOICE_CALL
|
||||||
"vnd.android.cursor.item/vnd.com.viber.voip.viber_number_message" -> SOCIAL_MESSAGE
|
"vnd.android.cursor.item/vnd.com.viber.voip.viber_number_message" -> SOCIAL_MESSAGE
|
||||||
else -> return@queryCursor
|
|
||||||
}
|
|
||||||
|
|
||||||
val label = cursor.getStringValue(ContactsContract.Data.DATA3)
|
// Signal
|
||||||
val realID = cursor.getLongValue(ContactsContract.Data._ID)
|
"vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.contact" -> SOCIAL_MESSAGE
|
||||||
val packageName = cursor.getStringValue(ContactsContract.Data.ACCOUNT_TYPE_AND_DATA_SET)
|
"vnd.android.cursor.item/vnd.org.thoughtcrime.securesms.call" -> SOCIAL_VOICE_CALL
|
||||||
val socialAction = SocialAction(curActionId++, type, label, mimetype, realID, packageName)
|
|
||||||
socialActions.add(socialAction)
|
|
||||||
}
|
|
||||||
return socialActions
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Context.getTelegramActions(id: Int): ArrayList<SocialAction> {
|
// Telegram
|
||||||
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" -> 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.call.video" -> SOCIAL_VIDEO_CALL
|
||||||
"vnd.android.cursor.item/vnd.org.telegram.messenger.android.profile" -> SOCIAL_MESSAGE
|
"vnd.android.cursor.item/vnd.org.telegram.messenger.android.profile" -> SOCIAL_MESSAGE
|
||||||
|
@ -449,7 +372,6 @@ fun Context.getTelegramActions(id: Int): ArrayList<SocialAction> {
|
||||||
val socialAction = SocialAction(curActionId++, type, label, mimetype, realID, packageName)
|
val socialAction = SocialAction(curActionId++, type, label, mimetype, realID, packageName)
|
||||||
socialActions.add(socialAction)
|
socialActions.add(socialAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
return socialActions
|
return socialActions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue