From f177cbd0118028b8739869e379650b7878360fd6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 1 May 2020 23:50:22 +0200 Subject: [PATCH] adding an initial implementation of the PhoneAccount picker --- app/build.gradle | 2 +- .../contacts/pro/activities/CallActivity.kt | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6cb925ec..01a77f74 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.27.1' + implementation 'com.simplemobiletools:commons:5.27.2' implementation 'joda-time:joda-time:2.10.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4' implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5' diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/CallActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/CallActivity.kt index 68d3edc7..9f28ec2f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/CallActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/CallActivity.kt @@ -16,11 +16,10 @@ import android.util.Size import android.view.WindowManager import android.widget.RemoteViews import androidx.core.app.NotificationCompat +import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.MINUTE_SECONDS -import com.simplemobiletools.commons.helpers.isOreoMr1Plus -import com.simplemobiletools.commons.helpers.isOreoPlus -import com.simplemobiletools.commons.helpers.isQPlus +import com.simplemobiletools.commons.helpers.* +import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.extensions.audioManager import com.simplemobiletools.contacts.pro.extensions.config @@ -163,6 +162,7 @@ class CallActivity : SimpleActivity() { Call.STATE_ACTIVE -> callStarted() Call.STATE_DISCONNECTED -> endCall() Call.STATE_CONNECTING -> initOutgoingCallUI() + Call.STATE_SELECT_PHONE_ACCOUNT -> showPhoneAccountPicker() } if (state == Call.STATE_DISCONNECTED || state == Call.STATE_DISCONNECTING) { @@ -202,6 +202,31 @@ class CallActivity : SimpleActivity() { callTimer.scheduleAtFixedRate(getCallTimerUpdateTask(), 1000, 1000) } + @SuppressLint("MissingPermission") + private fun showPhoneAccountPicker() { + if (!hasPermission(PERMISSION_READ_PHONE_STATE)) { + return + } + + val items = ArrayList() + telecomManager.callCapablePhoneAccounts.forEachIndexed { index, account -> + val phoneAccount = telecomManager.getPhoneAccount(account) + var label = phoneAccount.label.toString() + var address = phoneAccount.address.toString() + if (address.startsWith("tel:") && address.substringAfter("tel:").isNotEmpty()) { + address = Uri.decode(address.substringAfter("tel:")) + label += " ($address)" + } + + val radioItem = RadioItem(index, label, phoneAccount.accountHandle) + items.add(radioItem) + } + + RadioGroupDialog(this, items, titleId = R.string.select_sim) { + + } + } + private fun endCall() { CallManager.reject() if (proximityWakeLock?.isHeld == true) {