From 7e9586af09e8ccb3f6b42de4e37a8783f1f23f93 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 5 Feb 2022 21:08:21 +0100 Subject: [PATCH] adding an activity extension --- .../smsmessenger/extensions/Activity.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Activity.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Activity.kt new file mode 100644 index 00000000..1d165091 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Activity.kt @@ -0,0 +1,26 @@ +package com.simplemobiletools.smsmessenger.extensions + +import android.app.Activity +import android.content.ActivityNotFoundException +import android.content.Intent +import android.net.Uri +import com.simplemobiletools.commons.extensions.hideKeyboard +import com.simplemobiletools.commons.extensions.showErrorToast +import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.smsmessenger.R + +fun Activity.dialNumber(phoneNumber: String, callback: (() -> Unit)? = null) { + hideKeyboard() + 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) + } + } +}