From c8443f7187877b1ed6c48a1a30c9a23b2e547295 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 09:35:54 +0200 Subject: [PATCH 01/28] implement the first version of SIM picker --- .../contacts/pro/activities/CallActivity.kt | 21 -------- .../contacts/pro/activities/DialerActivity.kt | 31 +++++++++-- .../contacts/pro/dialogs/SelectSIMDialog.kt | 51 +++++++++++++++++++ app/src/main/res/layout/dialog_select_sim.xml | 23 +++++++++ 4 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectSIMDialog.kt create mode 100644 app/src/main/res/layout/dialog_select_sim.xml 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 9f28ec2f..358d0bae 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,10 +16,8 @@ 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.* -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 @@ -202,29 +200,10 @@ 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() { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt index 7f5aee0e..fc131c55 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt @@ -5,14 +5,17 @@ import android.content.Intent import android.net.Uri import android.os.Bundle import android.telecom.PhoneAccount +import android.telecom.PhoneAccountHandle import android.telecom.TelecomManager import android.view.Menu import com.simplemobiletools.commons.extensions.isDefaultDialer import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.telecomManager import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.commons.helpers.PERMISSION_READ_PHONE_STATE import com.simplemobiletools.commons.helpers.REQUEST_CODE_SET_DEFAULT_DIALER import com.simplemobiletools.contacts.pro.R +import com.simplemobiletools.contacts.pro.dialogs.SelectSIMDialog class DialerActivity : SimpleActivity() { private var callNumber: Uri? = null @@ -43,11 +46,13 @@ class DialerActivity : SimpleActivity() { @SuppressLint("MissingPermission") private fun initOutgoingCall() { try { - Bundle().apply { - 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_SPEAKERPHONE, false) - telecomManager.placeCall(callNumber, this) + getHandleToUse { + Bundle().apply { + putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, it) + putBoolean(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, false) + putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, false) + telecomManager.placeCall(callNumber, this) + } finish() } } catch (e: Exception) { @@ -56,6 +61,22 @@ class DialerActivity : SimpleActivity() { } } + @SuppressLint("MissingPermission") + private fun getHandleToUse(callback: (PhoneAccountHandle) -> Unit) { + val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL) + if (defaultHandle != null) { + callback(defaultHandle) + } else { + handlePermission(PERMISSION_READ_PHONE_STATE) { + if (it) { + SelectSIMDialog(this) { handle -> + callback(handle) + } + } + } + } + } + override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { super.onActivityResult(requestCode, resultCode, resultData) if (requestCode == REQUEST_CODE_SET_DEFAULT_DIALER) { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectSIMDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectSIMDialog.kt new file mode 100644 index 00000000..c3cb2e47 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectSIMDialog.kt @@ -0,0 +1,51 @@ +package com.simplemobiletools.contacts.pro.dialogs + +import android.annotation.SuppressLint +import android.net.Uri +import android.telecom.PhoneAccountHandle +import android.view.ViewGroup +import android.widget.RadioButton +import android.widget.RadioGroup +import androidx.appcompat.app.AlertDialog +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.commons.extensions.telecomManager +import com.simplemobiletools.contacts.pro.R +import kotlinx.android.synthetic.main.dialog_select_sim.view.* + +@SuppressLint("MissingPermission") +class SelectSIMDialog(val activity: BaseSimpleActivity, val callback: (handle: PhoneAccountHandle) -> Unit) { + private var dialog: AlertDialog? = null + + init { + val view = activity.layoutInflater.inflate(R.layout.dialog_select_sim, null) + val radioGroup = view.select_sim_radio_group + + activity.telecomManager.callCapablePhoneAccounts.forEachIndexed { index, account -> + val phoneAccount = activity.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 radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply { + text = label + id = index + setOnClickListener { selectedSIM(phoneAccount.accountHandle) } + } + radioGroup!!.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) + } + + dialog = AlertDialog.Builder(activity) + .create().apply { + activity.setupDialogStuff(view, this) + } + } + + private fun selectedSIM(handle: PhoneAccountHandle) { + callback(handle) + dialog?.dismiss() + } +} diff --git a/app/src/main/res/layout/dialog_select_sim.xml b/app/src/main/res/layout/dialog_select_sim.xml new file mode 100644 index 00000000..7a8f7b14 --- /dev/null +++ b/app/src/main/res/layout/dialog_select_sim.xml @@ -0,0 +1,23 @@ + + + + + + + + From d740d7f2eae05e82284fa00b7bbeede5dfcde9ff Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 13:37:10 +0200 Subject: [PATCH 02/28] renaming the Handle variable used at starting calls --- .../contacts/pro/activities/DialerActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt index fc131c55..c8028456 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt @@ -46,9 +46,9 @@ class DialerActivity : SimpleActivity() { @SuppressLint("MissingPermission") private fun initOutgoingCall() { try { - getHandleToUse { + getHandleToUse { handle -> Bundle().apply { - putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, it) + putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle) putBoolean(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, false) putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, false) telecomManager.placeCall(callNumber, this) From 099a54388d1470b17e02e82ce5c0b4e05e9f6f7a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 18:13:32 +0200 Subject: [PATCH 03/28] adding a new permission, used at determining which SIM should be used at calls --- app/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index eb8dfaa4..59907330 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,6 +16,7 @@ + Date: Sat, 2 May 2020 18:38:26 +0200 Subject: [PATCH 04/28] show Outgoing call UI at DIALING state too --- .../simplemobiletools/contacts/pro/activities/CallActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 358d0bae..a2980290 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 @@ -159,7 +159,7 @@ class CallActivity : SimpleActivity() { Call.STATE_RINGING -> callRinging() Call.STATE_ACTIVE -> callStarted() Call.STATE_DISCONNECTED -> endCall() - Call.STATE_CONNECTING -> initOutgoingCallUI() + Call.STATE_CONNECTING, Call.STATE_DIALING -> initOutgoingCallUI() Call.STATE_SELECT_PHONE_ACCOUNT -> showPhoneAccountPicker() } From 964486fedc621bf1cd0255f8a4c51c802f7e937c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 20:01:22 +0200 Subject: [PATCH 05/28] improve the handling of SIM picker at call start --- .../contacts/pro/activities/CallActivity.kt | 12 +++++++++--- .../contacts/pro/helpers/CallManager.kt | 3 ++- .../contacts/pro/models/CallContact.kt | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) 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 a2980290..7ca4170e 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 @@ -17,10 +17,14 @@ import android.view.WindowManager import android.widget.RemoteViews import androidx.core.app.NotificationCompat import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.* +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.contacts.pro.R import com.simplemobiletools.contacts.pro.extensions.audioManager import com.simplemobiletools.contacts.pro.extensions.config +import com.simplemobiletools.contacts.pro.extensions.startCallIntent import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL import com.simplemobiletools.contacts.pro.helpers.CallManager import com.simplemobiletools.contacts.pro.helpers.DECLINE_CALL @@ -201,8 +205,10 @@ class CallActivity : SimpleActivity() { } private fun showPhoneAccountPicker() { - if (!hasPermission(PERMISSION_READ_PHONE_STATE)) { - return + if (callContact == null || callContact!!.number.isEmpty()) { + toast(R.string.unknown_error_occurred) + } else { + startCallIntent(callContact!!.number) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt index 3be9e194..27074a07 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt @@ -46,7 +46,7 @@ class CallManager { } fun getCallContact(context: Context): CallContact? { - val callContact = CallContact("", "") + val callContact = CallContact("", "", "") if (call == null) { return callContact } @@ -54,6 +54,7 @@ class CallManager { val uri = Uri.decode(call!!.details.handle.toString()) if (uri.startsWith("tel:")) { val number = uri.substringAfter("tel:") + callContact.number = number callContact.name = context.getNameFromPhoneNumber(number) callContact.photoUri = context.getPhotoUriFromPhoneNumber(number) } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/CallContact.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/CallContact.kt index 86a3ae69..2390f8b7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/CallContact.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/CallContact.kt @@ -1,4 +1,4 @@ package com.simplemobiletools.contacts.pro.models // a simpler Contact model containing just info needed at the call screen -data class CallContact(var name: String, var photoUri: String) +data class CallContact(var name: String, var photoUri: String, var number: String) From 91c33b503041b81a676a4c2bd20b377505d11320 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 20:07:14 +0200 Subject: [PATCH 06/28] properly recognize SIM card to use from third party intents --- .../contacts/pro/activities/DialerActivity.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt index c8028456..a7bd2590 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt @@ -64,13 +64,15 @@ class DialerActivity : SimpleActivity() { @SuppressLint("MissingPermission") private fun getHandleToUse(callback: (PhoneAccountHandle) -> Unit) { val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL) - if (defaultHandle != null) { - callback(defaultHandle) - } else { - handlePermission(PERMISSION_READ_PHONE_STATE) { - if (it) { - SelectSIMDialog(this) { handle -> - callback(handle) + when { + defaultHandle != null -> callback(defaultHandle) + intent.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)) + else -> { + handlePermission(PERMISSION_READ_PHONE_STATE) { + if (it) { + SelectSIMDialog(this) { handle -> + callback(handle) + } } } } From 1ddbe9a06c872bca992507f690844d44aec79619 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 20:23:09 +0200 Subject: [PATCH 07/28] prefer the third party intents SIM over the default one --- .../simplemobiletools/contacts/pro/activities/DialerActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt index a7bd2590..a2d29519 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt @@ -65,8 +65,8 @@ class DialerActivity : SimpleActivity() { private fun getHandleToUse(callback: (PhoneAccountHandle) -> Unit) { val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL) when { + intent.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!) defaultHandle != null -> callback(defaultHandle) - intent.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)) else -> { handlePermission(PERMISSION_READ_PHONE_STATE) { if (it) { From 56e8e4744e23fa10e1959010eb6bad4e2ae02195 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 20:48:00 +0200 Subject: [PATCH 08/28] adding a checkbox for remembering SIM at specific numbers --- .../contacts/pro/activities/DialerActivity.kt | 14 ++++++++-- .../contacts/pro/dialogs/SelectSIMDialog.kt | 28 ++++++++----------- .../contacts/pro/extensions/Context.kt | 20 +++++++++++++ .../contacts/pro/helpers/Config.kt | 7 +++++ .../contacts/pro/helpers/Constants.kt | 5 ++-- .../contacts/pro/models/SIMAccount.kt | 5 ++++ app/src/main/res/layout/dialog_select_sim.xml | 14 +++++++++- 7 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/SIMAccount.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt index a2d29519..c020692f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt @@ -16,6 +16,8 @@ import com.simplemobiletools.commons.helpers.PERMISSION_READ_PHONE_STATE import com.simplemobiletools.commons.helpers.REQUEST_CODE_SET_DEFAULT_DIALER import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.dialogs.SelectSIMDialog +import com.simplemobiletools.contacts.pro.extensions.config +import com.simplemobiletools.contacts.pro.extensions.getAvailableSIMCardLabels class DialerActivity : SimpleActivity() { private var callNumber: Uri? = null @@ -46,7 +48,7 @@ class DialerActivity : SimpleActivity() { @SuppressLint("MissingPermission") private fun initOutgoingCall() { try { - getHandleToUse { handle -> + getHandleToUse(callNumber.toString()) { handle -> Bundle().apply { putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle) putBoolean(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, false) @@ -62,15 +64,21 @@ class DialerActivity : SimpleActivity() { } @SuppressLint("MissingPermission") - private fun getHandleToUse(callback: (PhoneAccountHandle) -> Unit) { + private fun getHandleToUse(phoneNumber: String, callback: (PhoneAccountHandle) -> Unit) { val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL) when { intent.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!) + config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> { + val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber)) + val availableSIMs = getAvailableSIMCardLabels() + val firstornull = availableSIMs.firstOrNull { it.label == storedLabel }?.handle ?: availableSIMs.first().handle + callback(firstornull) + } defaultHandle != null -> callback(defaultHandle) else -> { handlePermission(PERMISSION_READ_PHONE_STATE) { if (it) { - SelectSIMDialog(this) { handle -> + SelectSIMDialog(this, phoneNumber) { handle -> callback(handle) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectSIMDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectSIMDialog.kt index c3cb2e47..c621ceae 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectSIMDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/dialogs/SelectSIMDialog.kt @@ -1,7 +1,6 @@ package com.simplemobiletools.contacts.pro.dialogs import android.annotation.SuppressLint -import android.net.Uri import android.telecom.PhoneAccountHandle import android.view.ViewGroup import android.widget.RadioButton @@ -9,31 +8,24 @@ import android.widget.RadioGroup import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.setupDialogStuff -import com.simplemobiletools.commons.extensions.telecomManager import com.simplemobiletools.contacts.pro.R +import com.simplemobiletools.contacts.pro.extensions.config +import com.simplemobiletools.contacts.pro.extensions.getAvailableSIMCardLabels import kotlinx.android.synthetic.main.dialog_select_sim.view.* @SuppressLint("MissingPermission") -class SelectSIMDialog(val activity: BaseSimpleActivity, val callback: (handle: PhoneAccountHandle) -> Unit) { +class SelectSIMDialog(val activity: BaseSimpleActivity, val phoneNumber: String, val callback: (handle: PhoneAccountHandle) -> Unit) { private var dialog: AlertDialog? = null + private val view = activity.layoutInflater.inflate(R.layout.dialog_select_sim, null) init { - val view = activity.layoutInflater.inflate(R.layout.dialog_select_sim, null) val radioGroup = view.select_sim_radio_group - activity.telecomManager.callCapablePhoneAccounts.forEachIndexed { index, account -> - val phoneAccount = activity.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)" - } - + activity.getAvailableSIMCardLabels().forEachIndexed { index, SIMAccount -> val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply { - text = label + text = SIMAccount.label id = index - setOnClickListener { selectedSIM(phoneAccount.accountHandle) } + setOnClickListener { selectedSIM(SIMAccount.handle, SIMAccount.label) } } radioGroup!!.addView(radioButton, RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)) } @@ -44,7 +36,11 @@ class SelectSIMDialog(val activity: BaseSimpleActivity, val callback: (handle: P } } - private fun selectedSIM(handle: PhoneAccountHandle) { + private fun selectedSIM(handle: PhoneAccountHandle, label: String) { + if (view.select_sim_remember.isChecked) { + activity.config.saveCustomSIM(phoneNumber, label) + } + callback(handle) dialog?.dismiss() } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt index e9cafbc2..ca8dd026 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Context.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.contacts.pro.extensions +import android.annotation.SuppressLint import android.content.Context import android.content.Context.AUDIO_SERVICE import android.content.Intent @@ -12,6 +13,7 @@ import android.provider.ContactsContract import androidx.core.content.FileProvider import com.simplemobiletools.commons.extensions.getIntValue import com.simplemobiletools.commons.extensions.hasPermission +import com.simplemobiletools.commons.extensions.telecomManager import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS @@ -26,6 +28,7 @@ import com.simplemobiletools.contacts.pro.interfaces.GroupsDao import com.simplemobiletools.contacts.pro.models.Contact import com.simplemobiletools.contacts.pro.models.ContactSource import com.simplemobiletools.contacts.pro.models.Organization +import com.simplemobiletools.contacts.pro.models.SIMAccount import java.io.File val Context.config: Config get() = Config.newInstance(applicationContext) @@ -326,3 +329,20 @@ fun Context.getAllContactSources(): ArrayList { } fun Context.getPrivateContactSource() = ContactSource(SMT_PRIVATE, SMT_PRIVATE, getString(R.string.phone_storage_hidden)) + +@SuppressLint("MissingPermission") +fun Context.getAvailableSIMCardLabels(): ArrayList { + val SIMAccounts = ArrayList() + telecomManager.callCapablePhoneAccounts.forEach { 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 SIM = SIMAccount(phoneAccount.accountHandle, label) + SIMAccounts.add(SIM) + } + return SIMAccounts +} diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Config.kt index 76b047a7..b931a9ee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Config.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.contacts.pro.helpers import android.content.Context +import android.net.Uri import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.helpers.BaseConfig @@ -72,6 +73,12 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getString(SPEED_DIAL, "")!! set(speedDial) = prefs.edit().putString(SPEED_DIAL, speedDial).apply() + fun saveCustomSIM(number: String, SIMlabel: String) { + prefs.edit().putString(REMEMBER_SIM_PREFIX + number, Uri.encode(SIMlabel)).apply() + } + + fun getCustomSIM(number: String) = prefs.getString(REMEMBER_SIM_PREFIX + number, "") + fun getSpeedDialValues(): ArrayList { val speedDialType = object : TypeToken>() {}.type val speedDialValues = Gson().fromJson>(speedDial, speedDialType) ?: ArrayList(1) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt index 5de1e921..dedf47b3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/Constants.kt @@ -24,6 +24,7 @@ const val SHOW_DIALPAD_LETTERS = "show_dialpad_letters" const val SPEED_DIAL = "speed_dial" const val LAST_EXPORT_PATH = "last_export_path" const val WAS_LOCAL_ACCOUNT_INITIALIZED = "was_local_account_initialized" +const val REMEMBER_SIM_PREFIX = "remember_sim_" const val CONTACT_ID = "contact_id" const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps @@ -56,8 +57,8 @@ const val GROUPS_TAB_MASK = 8 const val ALL_TABS_MASK = CONTACTS_TAB_MASK or FAVORITES_TAB_MASK or GROUPS_TAB_MASK val tabsList = arrayListOf(CONTACTS_TAB_MASK, - FAVORITES_TAB_MASK, - GROUPS_TAB_MASK + FAVORITES_TAB_MASK, + GROUPS_TAB_MASK ) // contact photo changes diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/SIMAccount.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/SIMAccount.kt new file mode 100644 index 00000000..aca810f4 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/models/SIMAccount.kt @@ -0,0 +1,5 @@ +package com.simplemobiletools.contacts.pro.models + +import android.telecom.PhoneAccountHandle + +data class SIMAccount(val handle: PhoneAccountHandle, val label: String) diff --git a/app/src/main/res/layout/dialog_select_sim.xml b/app/src/main/res/layout/dialog_select_sim.xml index 7a8f7b14..6c51bb4b 100644 --- a/app/src/main/res/layout/dialog_select_sim.xml +++ b/app/src/main/res/layout/dialog_select_sim.xml @@ -18,6 +18,18 @@ + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/small_margin" /> + + + + From ce281797b46ee7d3d67f6e293ef4e24e2f7b8c95 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 20:58:39 +0200 Subject: [PATCH 09/28] ask for a SIM card to be used earlier, not at Dialer activity --- .../contacts/pro/activities/DialerActivity.kt | 33 +------------ .../contacts/pro/extensions/Activity.kt | 46 ++++++++++++++++--- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt index c020692f..7d3b1a78 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialerActivity.kt @@ -4,20 +4,15 @@ import android.annotation.SuppressLint import android.content.Intent import android.net.Uri import android.os.Bundle -import android.telecom.PhoneAccount -import android.telecom.PhoneAccountHandle import android.telecom.TelecomManager import android.view.Menu import com.simplemobiletools.commons.extensions.isDefaultDialer import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.telecomManager import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.commons.helpers.PERMISSION_READ_PHONE_STATE import com.simplemobiletools.commons.helpers.REQUEST_CODE_SET_DEFAULT_DIALER import com.simplemobiletools.contacts.pro.R -import com.simplemobiletools.contacts.pro.dialogs.SelectSIMDialog -import com.simplemobiletools.contacts.pro.extensions.config -import com.simplemobiletools.contacts.pro.extensions.getAvailableSIMCardLabels +import com.simplemobiletools.contacts.pro.extensions.getHandleToUse class DialerActivity : SimpleActivity() { private var callNumber: Uri? = null @@ -48,7 +43,7 @@ class DialerActivity : SimpleActivity() { @SuppressLint("MissingPermission") private fun initOutgoingCall() { try { - getHandleToUse(callNumber.toString()) { handle -> + getHandleToUse(intent, callNumber.toString()) { handle -> Bundle().apply { putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle) putBoolean(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, false) @@ -63,30 +58,6 @@ class DialerActivity : SimpleActivity() { } } - @SuppressLint("MissingPermission") - private fun getHandleToUse(phoneNumber: String, callback: (PhoneAccountHandle) -> Unit) { - val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL) - when { - intent.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!) - config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> { - val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber)) - val availableSIMs = getAvailableSIMCardLabels() - val firstornull = availableSIMs.firstOrNull { it.label == storedLabel }?.handle ?: availableSIMs.first().handle - callback(firstornull) - } - defaultHandle != null -> callback(defaultHandle) - else -> { - handlePermission(PERMISSION_READ_PHONE_STATE) { - if (it) { - SelectSIMDialog(this, phoneNumber) { handle -> - callback(handle) - } - } - } - } - } - } - override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { super.onActivityResult(requestCode, resultCode, resultData) if (requestCode == REQUEST_CODE_SET_DEFAULT_DIALER) { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt index 19d4ef1e..432f5900 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt @@ -1,28 +1,37 @@ package com.simplemobiletools.contacts.pro.extensions +import android.annotation.SuppressLint import android.content.Intent import android.net.Uri +import android.telecom.PhoneAccount +import android.telecom.PhoneAccountHandle +import android.telecom.TelecomManager import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PERMISSION_CALL_PHONE +import com.simplemobiletools.commons.helpers.PERMISSION_READ_PHONE_STATE import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.contacts.pro.BuildConfig import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.activities.SimpleActivity import com.simplemobiletools.contacts.pro.dialogs.CallConfirmationDialog +import com.simplemobiletools.contacts.pro.dialogs.SelectSIMDialog import com.simplemobiletools.contacts.pro.helpers.* import com.simplemobiletools.contacts.pro.models.Contact fun SimpleActivity.startCallIntent(recipient: String) { handlePermission(PERMISSION_CALL_PHONE) { val action = if (it) Intent.ACTION_CALL else Intent.ACTION_DIAL - Intent(action).apply { - data = Uri.fromParts("tel", recipient, null) - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) + getHandleToUse(null, recipient) { handle -> + Intent(action).apply { + data = Uri.fromParts("tel", recipient, null) + putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle) + if (resolveActivity(packageManager) != null) { + startActivity(this) + } else { + toast(R.string.no_app_found) + } } } } @@ -109,3 +118,28 @@ fun SimpleActivity.callContact(contact: Contact) { toast(R.string.no_phone_number_found) } } + +// used at devices with multiple SIM cards +@SuppressLint("MissingPermission") +fun SimpleActivity.getHandleToUse(intent: Intent?, phoneNumber: String, callback: (PhoneAccountHandle) -> Unit) { + val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL) + when { + intent?.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) == true -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!) + config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> { + val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber)) + val availableSIMs = getAvailableSIMCardLabels() + val firstornull = availableSIMs.firstOrNull { it.label == storedLabel }?.handle ?: availableSIMs.first().handle + callback(firstornull) + } + defaultHandle != null -> callback(defaultHandle) + else -> { + handlePermission(PERMISSION_READ_PHONE_STATE) { + if (it) { + SelectSIMDialog(this, phoneNumber) { handle -> + callback(handle) + } + } + } + } + } +} From 3b0ca0ccf060329dde842f66a63e8d69dfa7fe69 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 21:07:55 +0200 Subject: [PATCH 10/28] require the PERMISSION_READ_PHONE_STATE before getting the SIM card to use --- .../contacts/pro/extensions/Activity.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt index 432f5900..354fa41a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt @@ -122,19 +122,19 @@ fun SimpleActivity.callContact(contact: Contact) { // used at devices with multiple SIM cards @SuppressLint("MissingPermission") fun SimpleActivity.getHandleToUse(intent: Intent?, phoneNumber: String, callback: (PhoneAccountHandle) -> Unit) { - val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL) - when { - intent?.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) == true -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!) - config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> { - val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber)) - val availableSIMs = getAvailableSIMCardLabels() - val firstornull = availableSIMs.firstOrNull { it.label == storedLabel }?.handle ?: availableSIMs.first().handle - callback(firstornull) - } - defaultHandle != null -> callback(defaultHandle) - else -> { - handlePermission(PERMISSION_READ_PHONE_STATE) { - if (it) { + handlePermission(PERMISSION_READ_PHONE_STATE) { + if (it) { + val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL) + when { + intent?.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) == true -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!) + config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> { + val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber)) + val availableSIMs = getAvailableSIMCardLabels() + val firstornull = availableSIMs.firstOrNull { it.label == storedLabel }?.handle ?: availableSIMs.first().handle + callback(firstornull) + } + defaultHandle != null -> callback(defaultHandle) + else -> { SelectSIMDialog(this, phoneNumber) { handle -> callback(handle) } From 8098fdf08010e80db835fa0a9a70455d4010cffe Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 21:27:23 +0200 Subject: [PATCH 11/28] adding three dots after Is Calling and Dialing strings --- app/src/main/res/values-ar/strings.xml | 4 ++-- app/src/main/res/values-az/strings.xml | 4 ++-- app/src/main/res/values-cs/strings.xml | 4 ++-- app/src/main/res/values-cy/strings.xml | 4 ++-- app/src/main/res/values-da/strings.xml | 4 ++-- app/src/main/res/values-de/strings.xml | 4 ++-- app/src/main/res/values-el/strings.xml | 4 ++-- app/src/main/res/values-es/strings.xml | 4 ++-- app/src/main/res/values-eu/strings.xml | 4 ++-- app/src/main/res/values-fi/strings.xml | 4 ++-- app/src/main/res/values-fr/strings.xml | 4 ++-- app/src/main/res/values-hr/strings.xml | 4 ++-- app/src/main/res/values-hu/strings.xml | 4 ++-- app/src/main/res/values-id/strings.xml | 4 ++-- app/src/main/res/values-in/strings.xml | 4 ++-- app/src/main/res/values-it/strings.xml | 4 ++-- app/src/main/res/values-ja/strings.xml | 4 ++-- app/src/main/res/values-ko-rKR/strings.xml | 4 ++-- app/src/main/res/values-lt/strings.xml | 4 ++-- app/src/main/res/values-nl/strings.xml | 4 ++-- app/src/main/res/values-pl/strings.xml | 4 ++-- app/src/main/res/values-pt-rBR/strings.xml | 4 ++-- app/src/main/res/values-pt/strings.xml | 4 ++-- app/src/main/res/values-ru/strings.xml | 4 ++-- app/src/main/res/values-sk/strings.xml | 4 ++-- app/src/main/res/values-sv/strings.xml | 4 ++-- app/src/main/res/values-tr/strings.xml | 4 ++-- app/src/main/res/values-uk/strings.xml | 4 ++-- app/src/main/res/values-zh-rCN/strings.xml | 4 ++-- app/src/main/res/values-zh-rTW/strings.xml | 4 ++-- app/src/main/res/values/strings.xml | 4 ++-- 31 files changed, 62 insertions(+), 62 deletions(-) diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 00ade1ed..7c5102f0 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-az/strings.xml b/app/src/main/res/values-az/strings.xml index 6135e086..26166ffb 100644 --- a/app/src/main/res/values-az/strings.xml +++ b/app/src/main/res/values-az/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 92052208..5b58addb 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-cy/strings.xml b/app/src/main/res/values-cy/strings.xml index d49922ab..6c11898e 100644 --- a/app/src/main/res/values-cy/strings.xml +++ b/app/src/main/res/values-cy/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 1b2a90a0..20b1af55 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 65b24c63..603e1fd8 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 565bf54c..e36487ae 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -106,8 +106,8 @@ Αποδοχή Απόρριψη Άγνωστος - Καλεί - Πληκτρολόγηση + Καλεί… + Πληκτρολόγηση… Τέλος Κλήσης Τερματισμός Κλήσης Τρέχουσα κλήση diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index cc1d78ef..28219ab0 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-eu/strings.xml b/app/src/main/res/values-eu/strings.xml index f65c3e45..70777aa1 100644 --- a/app/src/main/res/values-eu/strings.xml +++ b/app/src/main/res/values-eu/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 149de07b..6270f323 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index cfe05b8c..01ff191a 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index 33393fd5..67d126fb 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 15fc551c..9f272f10 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-id/strings.xml index 6e48e75c..f64593b0 100644 --- a/app/src/main/res/values-id/strings.xml +++ b/app/src/main/res/values-id/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 6e48e75c..f64593b0 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index b0651f6d..c81acb12 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 1f70c3f5..9945786f 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-ko-rKR/strings.xml b/app/src/main/res/values-ko-rKR/strings.xml index e54ac1e1..abb1ed36 100644 --- a/app/src/main/res/values-ko-rKR/strings.xml +++ b/app/src/main/res/values-ko-rKR/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index c0e16ec1..6680468e 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index ed725d5a..99bd60ad 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index d98bbba5..761d3e48 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 31b446c9..1a51a7e8 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 349a9303..e639fe65 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index a8691fd5..325c3ad5 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -106,8 +106,8 @@ Принять Отклонить Неизвестный абонент - Вызывает - Набор номера + Вызывает… + Набор номера… Вызов завершён Завершение вызова Текущий вызов diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 01e7c5e2..8b06696d 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -106,8 +106,8 @@ Prijať Odmietnuť Neznámy volajúci - Vám volá - Vytáčanie + Vám volá… + Vytáčanie… Hovor ukončený Hovor končí Prebiehajúci hovor diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 36a0a321..ce22c968 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 64524035..e66379a7 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -106,8 +106,8 @@ Kabul Et Reddet Bilinmeyen Arama - Arıyor - Çevriliyor + Arıyor… + Çevriliyor… Arama Sonlandırıldı Arama Sonlandırılıyor Devam Eden Arama diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 21f36bb2..037d23e1 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 051174a5..bce9e7d8 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index fbcc4374..f6ee1c27 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ee20b9dc..1af45d01 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -106,8 +106,8 @@ Accept Decline Unknown Caller - Is Calling - Dialing + Is Calling… + Dialing… Call Ended Call Ending Ongoing Call From c80192e1b0f98401492c2e3da64f285ed94cbd76 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 21:40:15 +0200 Subject: [PATCH 12/28] removing the beeping when the call notification appears --- .../simplemobiletools/contacts/pro/activities/CallActivity.kt | 2 ++ 1 file changed, 2 insertions(+) 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 7ca4170e..30205077 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 @@ -288,6 +288,7 @@ class CallActivity : SimpleActivity() { val name = "call_notification_channel" NotificationChannel(channelId, name, importance).apply { + setSound(null, null) notificationManager.createNotificationChannel(this) } } @@ -333,6 +334,7 @@ class CallActivity : SimpleActivity() { .setCategory(Notification.CATEGORY_CALL) .setCustomContentView(collapsedView) .setOngoing(true) + .setSound(null) .setUsesChronometer(callState == Call.STATE_ACTIVE) .setChannelId(channelId) .setStyle(NotificationCompat.DecoratedCustomViewStyle()) From f5d8822bef80ae2064fe7020a40874b2f19dd674 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 22:58:32 +0200 Subject: [PATCH 13/28] moving dialpad character inserting into extensions --- .../pro/activities/DialpadActivity.kt | 54 ++++++------------- .../contacts/pro/extensions/EditText.kt | 26 +++++++++ 2 files changed, 43 insertions(+), 37 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/EditText.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialpadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialpadActivity.kt index aa2c198e..a7e09793 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialpadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/DialpadActivity.kt @@ -19,9 +19,7 @@ import com.simplemobiletools.commons.helpers.isOreoPlus import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.adapters.ContactsAdapter import com.simplemobiletools.contacts.pro.dialogs.CallConfirmationDialog -import com.simplemobiletools.contacts.pro.extensions.callContact -import com.simplemobiletools.contacts.pro.extensions.config -import com.simplemobiletools.contacts.pro.extensions.startCallIntent +import com.simplemobiletools.contacts.pro.extensions.* import com.simplemobiletools.contacts.pro.helpers.ContactsHelper import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE import com.simplemobiletools.contacts.pro.helpers.LOCATION_DIALPAD @@ -45,16 +43,16 @@ class DialpadActivity : SimpleActivity() { speedDialValues = config.getSpeedDialValues() - dialpad_0_holder.setOnClickListener { dialpadPressed("0", it) } - dialpad_1.setOnClickListener { dialpadPressed("1", it) } - dialpad_2.setOnClickListener { dialpadPressed("2", it) } - dialpad_3.setOnClickListener { dialpadPressed("3", it) } - dialpad_4.setOnClickListener { dialpadPressed("4", it) } - dialpad_5.setOnClickListener { dialpadPressed("5", it) } - dialpad_6.setOnClickListener { dialpadPressed("6", it) } - dialpad_7.setOnClickListener { dialpadPressed("7", it) } - dialpad_8.setOnClickListener { dialpadPressed("8", it) } - dialpad_9.setOnClickListener { dialpadPressed("9", it) } + dialpad_0_holder.setOnClickListener { dialpadPressed('0', it) } + dialpad_1.setOnClickListener { dialpadPressed('1', it) } + dialpad_2.setOnClickListener { dialpadPressed('2', it) } + dialpad_3.setOnClickListener { dialpadPressed('3', it) } + dialpad_4.setOnClickListener { dialpadPressed('4', it) } + dialpad_5.setOnClickListener { dialpadPressed('5', it) } + dialpad_6.setOnClickListener { dialpadPressed('6', it) } + dialpad_7.setOnClickListener { dialpadPressed('7', it) } + dialpad_8.setOnClickListener { dialpadPressed('8', it) } + dialpad_9.setOnClickListener { dialpadPressed('9', it) } dialpad_1.setOnLongClickListener { speedDial(1); true } dialpad_2.setOnLongClickListener { speedDial(2); true } @@ -66,9 +64,9 @@ class DialpadActivity : SimpleActivity() { dialpad_8.setOnLongClickListener { speedDial(8); true } dialpad_9.setOnLongClickListener { speedDial(9); true } - dialpad_0_holder.setOnLongClickListener { dialpadPressed("+", null); true } - dialpad_asterisk.setOnClickListener { dialpadPressed("*", it) } - dialpad_hashtag.setOnClickListener { dialpadPressed("#", it) } + dialpad_0_holder.setOnLongClickListener { dialpadPressed('+', null); true } + dialpad_asterisk.setOnClickListener { dialpadPressed('*', it) } + dialpad_hashtag.setOnClickListener { dialpadPressed('#', it) } dialpad_clear_char.setOnClickListener { clearChar(it) } dialpad_clear_char.setOnLongClickListener { clearInput(); true } dialpad_call_button.setOnClickListener { initCall() } @@ -130,13 +128,13 @@ class DialpadActivity : SimpleActivity() { } } - private fun dialpadPressed(char: String, view: View?) { - dialpad_input.dispatchKeyEvent(getKeyEvent(getCharKeyCode(char))) + private fun dialpadPressed(char: Char, view: View?) { + dialpad_input.addCharacter(char) view?.performHapticFeedback() } private fun clearChar(view: View) { - dialpad_input.dispatchKeyEvent(getKeyEvent(KeyEvent.KEYCODE_DEL)) + dialpad_input.dispatchKeyEvent(dialpad_input.getKeyEvent(KeyEvent.KEYCODE_DEL)) view.performHapticFeedback() } @@ -144,24 +142,6 @@ class DialpadActivity : SimpleActivity() { dialpad_input.setText("") } - private fun getKeyEvent(keyCode: Int) = KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 0) - - private fun getCharKeyCode(char: String) = when (char) { - "0" -> KeyEvent.KEYCODE_0 - "1" -> KeyEvent.KEYCODE_1 - "2" -> KeyEvent.KEYCODE_2 - "3" -> KeyEvent.KEYCODE_3 - "4" -> KeyEvent.KEYCODE_4 - "5" -> KeyEvent.KEYCODE_5 - "6" -> KeyEvent.KEYCODE_6 - "7" -> KeyEvent.KEYCODE_7 - "8" -> KeyEvent.KEYCODE_8 - "9" -> KeyEvent.KEYCODE_9 - "*" -> KeyEvent.KEYCODE_STAR - "+" -> KeyEvent.KEYCODE_PLUS - else -> KeyEvent.KEYCODE_POUND - } - private fun disableKeyboardPopping() { dialpad_input.showSoftInputOnFocus = false } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/EditText.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/EditText.kt new file mode 100644 index 00000000..f4362f14 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/EditText.kt @@ -0,0 +1,26 @@ +package com.simplemobiletools.contacts.pro.extensions + +import android.view.KeyEvent +import android.widget.EditText + +fun EditText.addCharacter(char: Char) { + dispatchKeyEvent(getKeyEvent(getCharKeyCode(char))) +} + +fun EditText.getKeyEvent(keyCode: Int) = KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 0) + +private fun getCharKeyCode(char: Char) = when (char) { + '0' -> KeyEvent.KEYCODE_0 + '1' -> KeyEvent.KEYCODE_1 + '2' -> KeyEvent.KEYCODE_2 + '3' -> KeyEvent.KEYCODE_3 + '4' -> KeyEvent.KEYCODE_4 + '5' -> KeyEvent.KEYCODE_5 + '6' -> KeyEvent.KEYCODE_6 + '7' -> KeyEvent.KEYCODE_7 + '8' -> KeyEvent.KEYCODE_8 + '9' -> KeyEvent.KEYCODE_9 + '*' -> KeyEvent.KEYCODE_STAR + '+' -> KeyEvent.KEYCODE_PLUS + else -> KeyEvent.KEYCODE_POUND +} From 1e979e2b6ec62fe85e70c51232381ffe0b53e872 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 2 May 2020 23:04:08 +0200 Subject: [PATCH 14/28] add handling for dialpad presses during calls --- .../contacts/pro/activities/CallActivity.kt | 22 +++++++++++++++++++ .../contacts/pro/helpers/CallManager.kt | 5 +++++ 2 files changed, 27 insertions(+) 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 30205077..356a3c10 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 @@ -22,6 +22,7 @@ import com.simplemobiletools.commons.helpers.isOreoMr1Plus import com.simplemobiletools.commons.helpers.isOreoPlus import com.simplemobiletools.commons.helpers.isQPlus import com.simplemobiletools.contacts.pro.R +import com.simplemobiletools.contacts.pro.extensions.addCharacter import com.simplemobiletools.contacts.pro.extensions.audioManager import com.simplemobiletools.contacts.pro.extensions.config import com.simplemobiletools.contacts.pro.extensions.startCallIntent @@ -31,6 +32,7 @@ import com.simplemobiletools.contacts.pro.helpers.DECLINE_CALL import com.simplemobiletools.contacts.pro.models.CallContact import com.simplemobiletools.contacts.pro.receivers.CallActionReceiver import kotlinx.android.synthetic.main.activity_call.* +import kotlinx.android.synthetic.main.dialpad.* import java.util.* class CallActivity : SimpleActivity() { @@ -120,9 +122,29 @@ class CallActivity : SimpleActivity() { endCall() } + dialpad_0_holder.setOnClickListener { dialpadPressed('0') } + dialpad_1.setOnClickListener { dialpadPressed('1') } + dialpad_2.setOnClickListener { dialpadPressed('2') } + dialpad_3.setOnClickListener { dialpadPressed('3') } + dialpad_4.setOnClickListener { dialpadPressed('4') } + dialpad_5.setOnClickListener { dialpadPressed('5') } + dialpad_6.setOnClickListener { dialpadPressed('6') } + dialpad_7.setOnClickListener { dialpadPressed('7') } + dialpad_8.setOnClickListener { dialpadPressed('8') } + dialpad_9.setOnClickListener { dialpadPressed('9') } + + dialpad_0_holder.setOnLongClickListener { dialpadPressed('+'); true } + dialpad_asterisk.setOnClickListener { dialpadPressed('*') } + dialpad_hashtag.setOnClickListener { dialpadPressed('#') } + dialpad_wrapper.setBackgroundColor(config.backgroundColor) } + private fun dialpadPressed(char: Char) { + CallManager.keypad(char) + dialpad_input.addCharacter(char) + } + private fun toggleSpeaker() { isSpeakerOn = !isSpeakerOn val drawable = if (isSpeakerOn) R.drawable.ic_speaker_on_vector else R.drawable.ic_speaker_off_vector diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt index 27074a07..102e0c40 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt @@ -45,6 +45,11 @@ class CallManager { call!!.state } + fun keypad(c: Char) { + call?.playDtmfTone(c) + call?.stopDtmfTone() + } + fun getCallContact(context: Context): CallContact? { val callContact = CallContact("", "", "") if (call == null) { From 91bf4517940226574e70e0a2ee2552a2d780ca5e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 3 May 2020 09:38:44 +0200 Subject: [PATCH 15/28] set MODE_IN_CALL audio mode right at launching the call screen --- .../simplemobiletools/contacts/pro/activities/CallActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 356a3c10..531db03d 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 @@ -55,6 +55,7 @@ class CallActivity : SimpleActivity() { updateTextColors(call_holder) initButtons() + audioManager.mode = AudioManager.MODE_IN_CALL callContact = CallManager.getCallContact(applicationContext) callContactAvatar = getCallContactAvatar() addLockScreenFlags() @@ -222,7 +223,6 @@ class CallActivity : SimpleActivity() { private fun callStarted() { incoming_call_holder.beGone() ongoing_call_holder.beVisible() - audioManager.mode = AudioManager.MODE_IN_CALL callTimer.scheduleAtFixedRate(getCallTimerUpdateTask(), 1000, 1000) } From cae2ef091952dec192c951b7b93d89eee7c25a0e Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 3 May 2020 17:58:40 +0200 Subject: [PATCH 16/28] adding some bottom padding at the dialpad --- app/src/main/res/layout/dialpad.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/dialpad.xml b/app/src/main/res/layout/dialpad.xml index 28561ddf..e6235d65 100644 --- a/app/src/main/res/layout/dialpad.xml +++ b/app/src/main/res/layout/dialpad.xml @@ -7,6 +7,7 @@ android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:focusableInTouchMode="true" + android:paddingBottom="@dimen/normal_margin" tools:ignore="HardcodedText"> Date: Sun, 3 May 2020 18:07:31 +0200 Subject: [PATCH 17/28] use proper icon colors at the calling screen --- .../simplemobiletools/contacts/pro/activities/CallActivity.kt | 3 +++ 1 file changed, 3 insertions(+) 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 531db03d..090641cb 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 @@ -139,6 +139,9 @@ class CallActivity : SimpleActivity() { dialpad_hashtag.setOnClickListener { dialpadPressed('#') } dialpad_wrapper.setBackgroundColor(config.backgroundColor) + arrayOf(call_toggle_microphone, call_toggle_speaker, call_dialpad, dialpad_close).forEach { + it.applyColorFilter(config.textColor) + } } private fun dialpadPressed(char: Char) { From e8c995830644c89e92d701aeced1dd2789c19edd Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 3 May 2020 18:51:55 +0200 Subject: [PATCH 18/28] show contacts name at the Call Screen, even if stored at the private space --- .../contacts/pro/activities/CallActivity.kt | 16 +++++++----- .../contacts/pro/helpers/CallManager.kt | 25 ++++++++++++++++--- .../pro/helpers/LocalContactsHelper.kt | 2 +- .../contacts/pro/interfaces/ContactsDao.kt | 3 +++ 4 files changed, 35 insertions(+), 11 deletions(-) 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 090641cb..e4e67839 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 @@ -56,11 +56,16 @@ class CallActivity : SimpleActivity() { initButtons() audioManager.mode = AudioManager.MODE_IN_CALL - callContact = CallManager.getCallContact(applicationContext) - callContactAvatar = getCallContactAvatar() + CallManager.getCallContact(applicationContext) { contact -> + callContact = contact + callContactAvatar = getCallContactAvatar() + setupNotification() + runOnUiThread { + updateOtherPersonsInfo() + } + } + addLockScreenFlags() - setupNotification() - updateOtherPersonsInfo() initProximitySensor() CallManager.registerCallback(callCallback) @@ -176,8 +181,7 @@ class CallActivity : SimpleActivity() { return } - val callContact = CallManager.getCallContact(applicationContext) ?: return - caller_name_label.text = if (callContact.name.isNotEmpty()) callContact.name else getString(R.string.unknown_caller) + caller_name_label.text = if (callContact!!.name.isNotEmpty()) callContact!!.name else getString(R.string.unknown_caller) if (callContactAvatar != null) { caller_avatar.setImageBitmap(callContactAvatar) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt index 102e0c40..0661cdc1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt @@ -7,6 +7,8 @@ import android.telecom.Call import android.telecom.VideoProfile import com.simplemobiletools.commons.extensions.getNameFromPhoneNumber import com.simplemobiletools.commons.extensions.getPhotoUriFromPhoneNumber +import com.simplemobiletools.commons.helpers.ensureBackgroundThread +import com.simplemobiletools.contacts.pro.extensions.contactsDB import com.simplemobiletools.contacts.pro.models.CallContact // inspired by https://github.com/Chooloo/call_manage @@ -50,10 +52,11 @@ class CallManager { call?.stopDtmfTone() } - fun getCallContact(context: Context): CallContact? { + fun getCallContact(context: Context, callback: (CallContact?) -> Unit) { val callContact = CallContact("", "", "") if (call == null) { - return callContact + callback(callContact) + return } val uri = Uri.decode(call!!.details.handle.toString()) @@ -62,9 +65,23 @@ class CallManager { callContact.number = number callContact.name = context.getNameFromPhoneNumber(number) callContact.photoUri = context.getPhotoUriFromPhoneNumber(number) - } - return callContact + if (callContact.name == callContact.number) { + ensureBackgroundThread { + val localContact = context.contactsDB.getContactWithNumber("%$number%") + if (localContact != null) { + val storedGroups = ContactsHelper(context).getStoredGroupsSync() + val newContact = LocalContactsHelper(context).convertLocalContactToContact(localContact, storedGroups) + callContact.name = newContact!!.getNameToDisplay() + callContact.photoUri = newContact.photoUri + } + + callback(callContact) + } + } else { + callback(callContact) + } + } } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt index ce5007ea..d4bf5d95 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/LocalContactsHelper.kt @@ -81,7 +81,7 @@ class LocalContactsHelper(val context: Context) { return scaledSizePhotoData } - private fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList): Contact? { + fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList): Contact? { if (localContact == null) { return null } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/interfaces/ContactsDao.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/interfaces/ContactsDao.kt index cc869362..42621e76 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/interfaces/ContactsDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/interfaces/ContactsDao.kt @@ -14,6 +14,9 @@ interface ContactsDao { @Query("SELECT * FROM contacts WHERE id = :id") fun getContactWithId(id: Int): LocalContact? + @Query("SELECT * FROM contacts WHERE phone_numbers LIKE :number") + fun getContactWithNumber(number: String): LocalContact? + @Query("UPDATE contacts SET starred = :isStarred WHERE id = :id") fun updateStarred(isStarred: Int, id: Int) From 419431247bd277f0ab97315eea12a2d9777c728d Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 3 May 2020 20:09:22 +0200 Subject: [PATCH 19/28] properly handle updating letter fastscroller related colors --- .../contacts/pro/fragments/MyViewPagerFragment.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt index 6bfca4a4..2d108fb2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt @@ -85,11 +85,16 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) updateTextColor(color) } } + + letter_fastscroller?.textColor = color.getColorStateList() } fun primaryColorChanged() { fragment_fastscroller?.updatePrimaryColor() fragment_fastscroller?.updateBubblePrimaryColor() + letter_fastscroller_thumb?.thumbColor = config.primaryColor.getColorStateList() + letter_fastscroller_thumb?.textColor = config.primaryColor.getContrastColor() + (fragment_list.adapter as? ContactsAdapter)?.apply { adjustedPrimaryColor = context.getAdjustedPrimaryColor() } From bf1db86b4f9e96761a38a859fe1972296ec011f7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 3 May 2020 20:27:56 +0200 Subject: [PATCH 20/28] setup the call notification on the main thread --- .../simplemobiletools/contacts/pro/activities/CallActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e4e67839..5e635837 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 @@ -59,8 +59,8 @@ class CallActivity : SimpleActivity() { CallManager.getCallContact(applicationContext) { contact -> callContact = contact callContactAvatar = getCallContactAvatar() - setupNotification() runOnUiThread { + setupNotification() updateOtherPersonsInfo() } } From 6851a7c6d886298fceaac5a65d150d6da303a921 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 3 May 2020 20:35:31 +0200 Subject: [PATCH 21/28] make call notification receiver exported and enabled --- app/src/main/AndroidManifest.xml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 59907330..9d3a040a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -279,10 +279,13 @@ - + - - + + From bd92b4cd84b9ca166e157782a5824f68cfacf21b Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 3 May 2020 20:42:06 +0200 Subject: [PATCH 22/28] update version to 6.10.0 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 01a77f74..1e04886c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { applicationId "com.simplemobiletools.contacts.pro" minSdkVersion 23 targetSdkVersion 29 - versionCode 60 - versionName "6.9.0" + versionCode 61 + versionName "6.10.0" setProperty("archivesBaseName", "contacts") } From 23c75122b709e80915ae5bebb721c2944b09d873 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 3 May 2020 20:42:13 +0200 Subject: [PATCH 23/28] updating changelog --- CHANGELOG.md | 9 +++++++++ fastlane/metadata/android/en-US/changelogs/61.txt | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 fastlane/metadata/android/en-US/changelogs/61.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 7227b9c9..a0ba5151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Changelog ========== +Version 6.10.0 *(2020-05-03)* +---------------------------- + + * Adding a first implementation of a Dialer, to really allow the app handle calls + * Increased the minimal required Android OS version to 6 Marshmallow to allow handling calls + * Try fixing the glitch with some saved contacts disappearing + * Properly handle inserting bigger resolution contact images in some cases + * Added a few other UX and UI improvements here and there + Version 6.9.0 *(2020-04-16)* ---------------------------- diff --git a/fastlane/metadata/android/en-US/changelogs/61.txt b/fastlane/metadata/android/en-US/changelogs/61.txt new file mode 100644 index 00000000..d323a1bd --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/61.txt @@ -0,0 +1,5 @@ + * Adding a first implementation of a Dialer, to really allow the app handle calls + * Increased the minimal required Android OS version to 6 Marshmallow to allow handling calls + * Try fixing the glitch with some saved contacts disappearing + * Properly handle inserting bigger resolution contact images in some cases + * Added a few other UX and UI improvements here and there From 5ab75aed4b2d9222218fe032e55847813742f2fc Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 4 May 2020 16:36:24 +0200 Subject: [PATCH 24/28] change the default contact placeholder letter from S to A --- app/build.gradle | 2 +- .../contacts/pro/activities/ContactActivity.kt | 2 +- .../com/simplemobiletools/contacts/pro/helpers/CallManager.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1e04886c..82a5a9f6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,7 +57,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.27.2' + implementation 'com.simplemobiletools:commons:5.27.5' 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/ContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ContactActivity.kt index 15a03894..28671ddb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/ContactActivity.kt @@ -31,7 +31,7 @@ abstract class ContactActivity : SimpleActivity() { protected var currentContactPhotoPath = "" fun showPhotoPlaceholder(photoView: ImageView) { - val placeholder = BitmapDrawable(resources, getContactLetterIcon(contact?.getNameToDisplay() ?: "S")) + val placeholder = BitmapDrawable(resources, getContactLetterIcon(contact?.getNameToDisplay() ?: "A")) photoView.setImageDrawable(placeholder) currentContactPhotoPath = "" contact?.photo = null diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt index 0661cdc1..eebc769d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/helpers/CallManager.kt @@ -54,7 +54,7 @@ class CallManager { fun getCallContact(context: Context, callback: (CallContact?) -> Unit) { val callContact = CallContact("", "", "") - if (call == null) { + if (call == null || call!!.details == null || call!!.details!!.handle == null) { callback(callContact) return } From 96ce1eabcd0bb36ca44a710a2efad8b78769ca02 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 4 May 2020 16:45:18 +0200 Subject: [PATCH 25/28] handle the SIM picking before calling only if this is the default dialer app --- .../contacts/pro/extensions/Activity.kt | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt index 354fa41a..99f13307 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt @@ -21,17 +21,29 @@ import com.simplemobiletools.contacts.pro.helpers.* import com.simplemobiletools.contacts.pro.models.Contact fun SimpleActivity.startCallIntent(recipient: String) { + if (isDefaultDialer()) { + getHandleToUse(null, recipient) { handle -> + launchCallIntent(recipient, handle) + } + } else { + launchCallIntent(recipient, null) + } +} + +fun SimpleActivity.launchCallIntent(recipient: String, handle: PhoneAccountHandle?) { handlePermission(PERMISSION_CALL_PHONE) { val action = if (it) Intent.ACTION_CALL else Intent.ACTION_DIAL - getHandleToUse(null, recipient) { handle -> - Intent(action).apply { - data = Uri.fromParts("tel", recipient, null) + Intent(action).apply { + data = Uri.fromParts("tel", recipient, null) + + if (handle != null) { putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle) - if (resolveActivity(packageManager) != null) { - startActivity(this) - } else { - toast(R.string.no_app_found) - } + } + + if (resolveActivity(packageManager) != null) { + startActivity(this) + } else { + toast(R.string.no_app_found) } } } From 12671eb961513fbf5229d65f790851b1e4f5ad89 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 4 May 2020 17:01:15 +0200 Subject: [PATCH 26/28] lets add the READ_CALL_LOG permission --- app/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9d3a040a..b6a708e9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,6 +15,7 @@ + From c487be72d813d9d680be03e8883d04c0b08e917d Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 4 May 2020 17:08:15 +0200 Subject: [PATCH 27/28] update version to 6.10.1 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 82a5a9f6..754c13d0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { applicationId "com.simplemobiletools.contacts.pro" minSdkVersion 23 targetSdkVersion 29 - versionCode 61 - versionName "6.10.0" + versionCode 62 + versionName "6.10.1" setProperty("archivesBaseName", "contacts") } From 59891145f70677cf95474e5166e8d2a23b91046e Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 4 May 2020 17:08:22 +0200 Subject: [PATCH 28/28] updating changelog --- CHANGELOG.md | 6 ++++++ fastlane/metadata/android/en-US/changelogs/62.txt | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 fastlane/metadata/android/en-US/changelogs/62.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index a0ba5151..18a2b4ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========== +Version 6.10.1 *(2020-05-04)* +---------------------------- + + * Show the multi-SIM picker only if the app is set as the default dialer + * Added a couple other stability and UX improvements + Version 6.10.0 *(2020-05-03)* ---------------------------- diff --git a/fastlane/metadata/android/en-US/changelogs/62.txt b/fastlane/metadata/android/en-US/changelogs/62.txt new file mode 100644 index 00000000..4c1f6e73 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/62.txt @@ -0,0 +1,2 @@ + * Show the multi-SIM picker only if the app is set as the default dialer + * Added a couple other stability and UX improvements