Merge pull request #231 from Aga-C/dial-contact-from-thread

Added calling contact in conversation (#230)
This commit is contained in:
Tibor Kaputa 2021-10-18 18:36:19 +02:00 committed by GitHub
commit 83eb9a886d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 19 deletions

View File

@ -143,6 +143,7 @@ class ThreadActivity : SimpleActivity() {
menu.apply {
findItem(R.id.delete).isVisible = threadItems.isNotEmpty()
findItem(R.id.block_number).isVisible = isNougatPlus()
findItem(R.id.dial_number).isVisible = participants.size == 1
}
updateMenuItemColors(menu)
@ -157,6 +158,7 @@ class ThreadActivity : SimpleActivity() {
when (item.itemId) {
R.id.block_number -> blockNumber()
R.id.delete -> askConfirmDelete()
R.id.dial_number -> dialNumber()
R.id.manage_people -> managePeople()
R.id.mark_as_unread -> markAsUnread()
else -> return super.onOptionsItemSelected(item)
@ -488,6 +490,11 @@ class ThreadActivity : SimpleActivity() {
}
}
private fun dialNumber() {
val phoneNumber = participants.first().phoneNumbers.first()
dialNumber(phoneNumber)
}
private fun managePeople() {
if (thread_add_contacts.isVisible()) {
hideKeyboard()

View File

@ -1,9 +1,7 @@
package com.simplemobiletools.smsmessenger.adapters
import android.content.ActivityNotFoundException
import android.content.Intent
import android.graphics.Typeface
import android.net.Uri
import android.text.TextUtils
import android.util.TypedValue
import android.view.Menu
@ -129,17 +127,8 @@ class ConversationsAdapter(
private fun dialNumber() {
val conversation = getSelectedItems().firstOrNull() ?: return
Intent(Intent.ACTION_DIAL).apply {
data = Uri.fromParts("tel", conversation.phoneNumber, null)
try {
activity.startActivity(this)
finishActMode()
} catch (e: ActivityNotFoundException) {
activity.toast(R.string.no_app_found)
} catch (e: Exception) {
activity.showErrorToast(e)
}
activity.dialNumber(conversation.phoneNumber) {
finishActMode()
}
}

View File

@ -5,10 +5,7 @@ import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ContentResolver
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.content.*
import android.database.Cursor
import android.graphics.Bitmap
import android.media.AudioAttributes
@ -37,11 +34,10 @@ import com.simplemobiletools.smsmessenger.interfaces.MessagesDao
import com.simplemobiletools.smsmessenger.models.*
import com.simplemobiletools.smsmessenger.receivers.DirectReplyReceiver
import com.simplemobiletools.smsmessenger.receivers.MarkAsReadReceiver
import me.leolin.shortcutbadger.ShortcutBadger
import java.io.FileNotFoundException
import java.util.*
import kotlin.collections.ArrayList
import java.text.Normalizer
import me.leolin.shortcutbadger.ShortcutBadger
val Context.config: Config get() = Config.newInstance(applicationContext)
@ -897,3 +893,18 @@ fun Context.getFileSizeFromUri(uri: Uri): Long {
return FILE_SIZE_NONE
}
}
fun Context.dialNumber(phoneNumber: String, callback: (() -> Unit)? = null) {
Intent(Intent.ACTION_DIAL).apply {
data = Uri.fromParts("tel", phoneNumber, null)
try {
startActivity(this)
callback?.invoke()
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found)
} catch (e: Exception) {
showErrorToast(e)
}
}
}

View File

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