mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-04-04 05:21:12 +02:00
store default SIM cards to use system-wide too
This commit is contained in:
parent
067fbf1b45
commit
335129aee4
@ -26,7 +26,7 @@ import com.simplemobiletools.dialer.R
|
|||||||
import com.simplemobiletools.dialer.extensions.addCharacter
|
import com.simplemobiletools.dialer.extensions.addCharacter
|
||||||
import com.simplemobiletools.dialer.extensions.audioManager
|
import com.simplemobiletools.dialer.extensions.audioManager
|
||||||
import com.simplemobiletools.dialer.extensions.config
|
import com.simplemobiletools.dialer.extensions.config
|
||||||
import com.simplemobiletools.dialer.extensions.startCallIntent
|
import com.simplemobiletools.dialer.extensions.getHandleToUse
|
||||||
import com.simplemobiletools.dialer.helpers.ACCEPT_CALL
|
import com.simplemobiletools.dialer.helpers.ACCEPT_CALL
|
||||||
import com.simplemobiletools.dialer.helpers.CallManager
|
import com.simplemobiletools.dialer.helpers.CallManager
|
||||||
import com.simplemobiletools.dialer.helpers.DECLINE_CALL
|
import com.simplemobiletools.dialer.helpers.DECLINE_CALL
|
||||||
@ -239,10 +239,8 @@ class CallActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showPhoneAccountPicker() {
|
private fun showPhoneAccountPicker() {
|
||||||
if (callContact == null || callContact!!.number.isEmpty()) {
|
getHandleToUse(intent, callContact!!.number) { handle, setAsDefault ->
|
||||||
toast(R.string.unknown_error_occurred)
|
CallManager.call?.phoneAccountSelected(handle, setAsDefault)
|
||||||
} else {
|
|
||||||
startCallIntent(callContact!!.number)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class DialerActivity : SimpleActivity() {
|
|||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun initOutgoingCall() {
|
private fun initOutgoingCall() {
|
||||||
try {
|
try {
|
||||||
getHandleToUse(intent, callNumber.toString()) { handle ->
|
getHandleToUse(intent, callNumber.toString()) { handle, setAsDefault ->
|
||||||
Bundle().apply {
|
Bundle().apply {
|
||||||
putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle)
|
putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle)
|
||||||
putBoolean(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, false)
|
putBoolean(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, false)
|
||||||
|
@ -14,7 +14,7 @@ import com.simplemobiletools.dialer.extensions.getAvailableSIMCardLabels
|
|||||||
import kotlinx.android.synthetic.main.dialog_select_sim.view.*
|
import kotlinx.android.synthetic.main.dialog_select_sim.view.*
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
class SelectSIMDialog(val activity: BaseSimpleActivity, val phoneNumber: String, val callback: (handle: PhoneAccountHandle) -> Unit) {
|
class SelectSIMDialog(val activity: BaseSimpleActivity, val phoneNumber: String, val callback: (handle: PhoneAccountHandle, setAsDefault: Boolean) -> Unit) {
|
||||||
private var dialog: AlertDialog? = null
|
private var dialog: AlertDialog? = null
|
||||||
private val view = activity.layoutInflater.inflate(R.layout.dialog_select_sim, null)
|
private val view = activity.layoutInflater.inflate(R.layout.dialog_select_sim, null)
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class SelectSIMDialog(val activity: BaseSimpleActivity, val phoneNumber: String,
|
|||||||
activity.config.saveCustomSIM(phoneNumber, label)
|
activity.config.saveCustomSIM(phoneNumber, label)
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(handle)
|
callback(handle, view.select_sim_remember.isChecked)
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import com.simplemobiletools.dialer.dialogs.SelectSIMDialog
|
|||||||
|
|
||||||
fun SimpleActivity.startCallIntent(recipient: String) {
|
fun SimpleActivity.startCallIntent(recipient: String) {
|
||||||
if (isDefaultDialer()) {
|
if (isDefaultDialer()) {
|
||||||
getHandleToUse(null, recipient) { handle ->
|
getHandleToUse(null, recipient) { handle, setAsDefault ->
|
||||||
launchCallIntent(recipient, handle)
|
launchCallIntent(recipient, handle)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -25,22 +25,22 @@ fun SimpleActivity.startCallIntent(recipient: String) {
|
|||||||
|
|
||||||
// used at devices with multiple SIM cards
|
// used at devices with multiple SIM cards
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun SimpleActivity.getHandleToUse(intent: Intent?, phoneNumber: String, callback: (PhoneAccountHandle) -> Unit) {
|
fun SimpleActivity.getHandleToUse(intent: Intent?, phoneNumber: String, callback: (handle: PhoneAccountHandle, setAsDefault: Boolean) -> Unit) {
|
||||||
handlePermission(PERMISSION_READ_PHONE_STATE) {
|
handlePermission(PERMISSION_READ_PHONE_STATE) {
|
||||||
if (it) {
|
if (it) {
|
||||||
val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)
|
val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)
|
||||||
when {
|
when {
|
||||||
intent?.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) == true -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!)
|
intent?.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) == true -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!, false)
|
||||||
config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> {
|
config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> {
|
||||||
val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber))
|
val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber))
|
||||||
val availableSIMs = getAvailableSIMCardLabels()
|
val availableSIMs = getAvailableSIMCardLabels()
|
||||||
val firstornull = availableSIMs.firstOrNull { it.label == storedLabel }?.handle ?: availableSIMs.first().handle
|
val firstornull = availableSIMs.firstOrNull { it.label == storedLabel }?.handle ?: availableSIMs.first().handle
|
||||||
callback(firstornull)
|
callback(firstornull, false)
|
||||||
}
|
}
|
||||||
defaultHandle != null -> callback(defaultHandle)
|
defaultHandle != null -> callback(defaultHandle, true)
|
||||||
else -> {
|
else -> {
|
||||||
SelectSIMDialog(this, phoneNumber) { handle ->
|
SelectSIMDialog(this, phoneNumber) { handle, setAsDefault ->
|
||||||
callback(handle)
|
callback(handle, setAsDefault)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user