allow dialing phone numbers of conversation recipiends

This commit is contained in:
tibbi 2020-11-03 22:24:17 +01:00
parent 7d8e1a2155
commit 13b25b918d
2 changed files with 23 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.smsmessenger.adapters
import android.content.Intent import android.content.Intent
import android.graphics.Typeface import android.graphics.Typeface
import android.net.Uri
import android.text.TextUtils import android.text.TextUtils
import android.util.TypedValue import android.util.TypedValue
import android.view.Menu import android.view.Menu
@ -37,8 +38,9 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis
override fun prepareActionMode(menu: Menu) { override fun prepareActionMode(menu: Menu) {
menu.apply { menu.apply {
findItem(R.id.cab_add_number_to_contact).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.isGroupConversation == false
findItem(R.id.cab_block_number).isVisible = isNougatPlus() findItem(R.id.cab_block_number).isVisible = isNougatPlus()
findItem(R.id.cab_add_number_to_contact).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.isGroupConversation == false
findItem(R.id.cab_dial_number).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.isGroupConversation == false
findItem(R.id.cab_copy_number).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.isGroupConversation == false findItem(R.id.cab_copy_number).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.isGroupConversation == false
} }
} }
@ -51,6 +53,7 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis
when (id) { when (id) {
R.id.cab_add_number_to_contact -> addNumberToContact() R.id.cab_add_number_to_contact -> addNumberToContact()
R.id.cab_block_number -> askConfirmBlock() R.id.cab_block_number -> askConfirmBlock()
R.id.cab_dial_number -> dialNumber()
R.id.cab_copy_number -> copyNumberToClipboard() R.id.cab_copy_number -> copyNumberToClipboard()
R.id.cab_select_all -> selectAll() R.id.cab_select_all -> selectAll()
R.id.cab_delete -> askConfirmDelete() R.id.cab_delete -> askConfirmDelete()
@ -112,6 +115,20 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis
} }
} }
private fun dialNumber() {
val conversation = getSelectedItems().firstOrNull() ?: return
Intent(Intent.ACTION_DIAL).apply {
data = Uri.fromParts("tel", conversation.phoneNumber, null)
if (resolveActivity(activity.packageManager) != null) {
activity.startActivity(this)
finishActMode()
} else {
activity.toast(R.string.no_app_found)
}
}
}
private fun copyNumberToClipboard() { private fun copyNumberToClipboard() {
val conversation = getSelectedItems().firstOrNull() ?: return val conversation = getSelectedItems().firstOrNull() ?: return
activity.copyToClipboard(conversation.phoneNumber) activity.copyToClipboard(conversation.phoneNumber)

View File

@ -11,6 +11,11 @@
android:icon="@drawable/ic_minus_circle_vector" android:icon="@drawable/ic_minus_circle_vector"
android:title="@string/block_number" android:title="@string/block_number"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item
android:id="@+id/cab_dial_number"
android:icon="@drawable/ic_phone_vector"
android:title="@string/dial_number"
app:showAsAction="ifRoom" />
<item <item
android:id="@+id/cab_copy_number" android:id="@+id/cab_copy_number"
android:title="@string/copy_number_to_clipboard" android:title="@string/copy_number_to_clipboard"