adding a context extension for referencing the telecomManager
This commit is contained in:
parent
02198f572e
commit
ff0a08862c
|
@ -2,7 +2,6 @@ package com.simplemobiletools.contacts.pro.activities
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
@ -12,6 +11,7 @@ import android.telecom.TelecomManager
|
||||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.contacts.pro.R
|
import com.simplemobiletools.contacts.pro.R
|
||||||
|
import com.simplemobiletools.contacts.pro.extensions.telecomManager
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
class DialerActivity : SimpleActivity() {
|
class DialerActivity : SimpleActivity() {
|
||||||
|
@ -25,7 +25,6 @@ class DialerActivity : SimpleActivity() {
|
||||||
callNumber = intent.data
|
callNumber = intent.data
|
||||||
|
|
||||||
// make sure Simple Contacts is the default Phone app before initiating an outgoing call
|
// make sure Simple Contacts is the default Phone app before initiating an outgoing call
|
||||||
val telecomManager = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
|
||||||
if (telecomManager.defaultDialerPackage != packageName) {
|
if (telecomManager.defaultDialerPackage != packageName) {
|
||||||
val intent = Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER).putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName)
|
val intent = Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER).putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName)
|
||||||
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER)
|
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER)
|
||||||
|
@ -41,7 +40,6 @@ class DialerActivity : SimpleActivity() {
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun initOutgoingCall() {
|
private fun initOutgoingCall() {
|
||||||
try {
|
try {
|
||||||
val telecomManager = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
|
||||||
Bundle().apply {
|
Bundle().apply {
|
||||||
putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL))
|
putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL))
|
||||||
putBoolean(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, false)
|
putBoolean(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, false)
|
||||||
|
@ -58,7 +56,6 @@ class DialerActivity : SimpleActivity() {
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, resultData)
|
super.onActivityResult(requestCode, resultCode, resultData)
|
||||||
if (requestCode == REQUEST_CODE_SET_DEFAULT_DIALER) {
|
if (requestCode == REQUEST_CODE_SET_DEFAULT_DIALER) {
|
||||||
val telecomManager = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
|
||||||
if (telecomManager.defaultDialerPackage != packageName) {
|
if (telecomManager.defaultDialerPackage != packageName) {
|
||||||
finish()
|
finish()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Intent
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
|
import android.telecom.TelecomManager
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import com.simplemobiletools.commons.extensions.getIntValue
|
import com.simplemobiletools.commons.extensions.getIntValue
|
||||||
import com.simplemobiletools.commons.extensions.hasPermission
|
import com.simplemobiletools.commons.extensions.hasPermission
|
||||||
|
@ -30,6 +31,8 @@ val Context.contactsDB: ContactsDao get() = ContactsDatabase.getInstance(applica
|
||||||
|
|
||||||
val Context.groupsDB: GroupsDao get() = ContactsDatabase.getInstance(applicationContext).GroupsDao()
|
val Context.groupsDB: GroupsDao get() = ContactsDatabase.getInstance(applicationContext).GroupsDao()
|
||||||
|
|
||||||
|
val Context.telecomManager: TelecomManager get() = getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
||||||
|
|
||||||
fun Context.getEmptyContact(): Contact {
|
fun Context.getEmptyContact(): Contact {
|
||||||
val originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
val originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
||||||
val organization = Organization("", "")
|
val organization = Organization("", "")
|
||||||
|
|
|
@ -15,6 +15,7 @@ import com.simplemobiletools.contacts.pro.activities.EditContactActivity
|
||||||
import com.simplemobiletools.contacts.pro.adapters.RecentCallsAdapter
|
import com.simplemobiletools.contacts.pro.adapters.RecentCallsAdapter
|
||||||
import com.simplemobiletools.contacts.pro.extensions.contactClicked
|
import com.simplemobiletools.contacts.pro.extensions.contactClicked
|
||||||
import com.simplemobiletools.contacts.pro.extensions.normalizeNumber
|
import com.simplemobiletools.contacts.pro.extensions.normalizeNumber
|
||||||
|
import com.simplemobiletools.contacts.pro.extensions.telecomManager
|
||||||
import com.simplemobiletools.contacts.pro.helpers.IS_FROM_SIMPLE_CONTACTS
|
import com.simplemobiletools.contacts.pro.helpers.IS_FROM_SIMPLE_CONTACTS
|
||||||
import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE
|
import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE
|
||||||
import com.simplemobiletools.contacts.pro.helpers.RECENTS_TAB_MASK
|
import com.simplemobiletools.contacts.pro.helpers.RECENTS_TAB_MASK
|
||||||
|
@ -27,8 +28,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
override fun placeholderClicked() {
|
override fun placeholderClicked() {
|
||||||
val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
if (!isMarshmallowPlus() || (isMarshmallowPlus() && context.telecomManager.defaultDialerPackage == context.packageName)) {
|
||||||
if (!isMarshmallowPlus() || (isMarshmallowPlus() && telecomManager.defaultDialerPackage == context.packageName)) {
|
|
||||||
activity!!.handlePermission(PERMISSION_WRITE_CALL_LOG) {
|
activity!!.handlePermission(PERMISSION_WRITE_CALL_LOG) {
|
||||||
if (it) {
|
if (it) {
|
||||||
activity!!.handlePermission(PERMISSION_READ_CALL_LOG) {
|
activity!!.handlePermission(PERMISSION_READ_CALL_LOG) {
|
||||||
|
|
Loading…
Reference in New Issue