Dialing number refactor

This commit is contained in:
Agnieszka C 2021-10-18 18:19:26 +02:00
parent 41114e5f2c
commit 44547b05d0
3 changed files with 18 additions and 28 deletions

View File

@ -493,17 +493,7 @@ class ThreadActivity : SimpleActivity() {
private fun dialNumber() {
val phoneNumber = participants.first().phoneNumbers.first()
Intent(Intent.ACTION_DIAL).apply {
data = Uri.fromParts("tel", phoneNumber, null)
try {
startActivity(this)
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found)
} catch (e: Exception) {
showErrorToast(e)
}
}
dialNumber(phoneNumber)
}
private fun managePeople() {

View File

@ -129,18 +129,7 @@ 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() }
}
private fun copyNumberToClipboard() {

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
@ -40,7 +37,6 @@ import com.simplemobiletools.smsmessenger.receivers.MarkAsReadReceiver
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 = fun() {}) {
Intent(Intent.ACTION_DIAL).apply {
data = Uri.fromParts("tel", phoneNumber, null)
try {
startActivity(this)
callback()
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found)
} catch (e: Exception) {
showErrorToast(e)
}
}
}