mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
adding a checkbox for remembering SIM at specific numbers
This commit is contained in:
@ -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.commons.helpers.REQUEST_CODE_SET_DEFAULT_DIALER
|
||||||
import com.simplemobiletools.contacts.pro.R
|
import com.simplemobiletools.contacts.pro.R
|
||||||
import com.simplemobiletools.contacts.pro.dialogs.SelectSIMDialog
|
import com.simplemobiletools.contacts.pro.dialogs.SelectSIMDialog
|
||||||
|
import com.simplemobiletools.contacts.pro.extensions.config
|
||||||
|
import com.simplemobiletools.contacts.pro.extensions.getAvailableSIMCardLabels
|
||||||
|
|
||||||
class DialerActivity : SimpleActivity() {
|
class DialerActivity : SimpleActivity() {
|
||||||
private var callNumber: Uri? = null
|
private var callNumber: Uri? = null
|
||||||
@ -46,7 +48,7 @@ class DialerActivity : SimpleActivity() {
|
|||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun initOutgoingCall() {
|
private fun initOutgoingCall() {
|
||||||
try {
|
try {
|
||||||
getHandleToUse { handle ->
|
getHandleToUse(callNumber.toString()) { handle ->
|
||||||
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)
|
||||||
@ -62,15 +64,21 @@ class DialerActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
private fun getHandleToUse(callback: (PhoneAccountHandle) -> Unit) {
|
private fun getHandleToUse(phoneNumber: String, callback: (PhoneAccountHandle) -> Unit) {
|
||||||
val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)
|
val defaultHandle = telecomManager.getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_TEL)
|
||||||
when {
|
when {
|
||||||
intent.hasExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE) -> callback(intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE)!!)
|
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)
|
defaultHandle != null -> callback(defaultHandle)
|
||||||
else -> {
|
else -> {
|
||||||
handlePermission(PERMISSION_READ_PHONE_STATE) {
|
handlePermission(PERMISSION_READ_PHONE_STATE) {
|
||||||
if (it) {
|
if (it) {
|
||||||
SelectSIMDialog(this) { handle ->
|
SelectSIMDialog(this, phoneNumber) { handle ->
|
||||||
callback(handle)
|
callback(handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.simplemobiletools.contacts.pro.dialogs
|
package com.simplemobiletools.contacts.pro.dialogs
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.net.Uri
|
|
||||||
import android.telecom.PhoneAccountHandle
|
import android.telecom.PhoneAccountHandle
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.RadioButton
|
import android.widget.RadioButton
|
||||||
@ -9,31 +8,24 @@ import android.widget.RadioGroup
|
|||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import com.simplemobiletools.commons.extensions.telecomManager
|
|
||||||
import com.simplemobiletools.contacts.pro.R
|
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.*
|
import kotlinx.android.synthetic.main.dialog_select_sim.view.*
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@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 var dialog: AlertDialog? = null
|
||||||
|
private val view = activity.layoutInflater.inflate(R.layout.dialog_select_sim, null)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_sim, null)
|
|
||||||
val radioGroup = view.select_sim_radio_group
|
val radioGroup = view.select_sim_radio_group
|
||||||
|
|
||||||
activity.telecomManager.callCapablePhoneAccounts.forEachIndexed { index, account ->
|
activity.getAvailableSIMCardLabels().forEachIndexed { index, SIMAccount ->
|
||||||
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 {
|
val radioButton = (activity.layoutInflater.inflate(R.layout.radio_button, null) as RadioButton).apply {
|
||||||
text = label
|
text = SIMAccount.label
|
||||||
id = index
|
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))
|
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)
|
callback(handle)
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.simplemobiletools.contacts.pro.extensions
|
package com.simplemobiletools.contacts.pro.extensions
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Context.AUDIO_SERVICE
|
import android.content.Context.AUDIO_SERVICE
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@ -12,6 +13,7 @@ import android.provider.ContactsContract
|
|||||||
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
|
||||||
|
import com.simplemobiletools.commons.extensions.telecomManager
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_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.Contact
|
||||||
import com.simplemobiletools.contacts.pro.models.ContactSource
|
import com.simplemobiletools.contacts.pro.models.ContactSource
|
||||||
import com.simplemobiletools.contacts.pro.models.Organization
|
import com.simplemobiletools.contacts.pro.models.Organization
|
||||||
|
import com.simplemobiletools.contacts.pro.models.SIMAccount
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||||
@ -326,3 +329,20 @@ fun Context.getAllContactSources(): ArrayList<ContactSource> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getPrivateContactSource() = ContactSource(SMT_PRIVATE, SMT_PRIVATE, getString(R.string.phone_storage_hidden))
|
fun Context.getPrivateContactSource() = ContactSource(SMT_PRIVATE, SMT_PRIVATE, getString(R.string.phone_storage_hidden))
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
fun Context.getAvailableSIMCardLabels(): ArrayList<SIMAccount> {
|
||||||
|
val SIMAccounts = ArrayList<SIMAccount>()
|
||||||
|
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
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.simplemobiletools.contacts.pro.helpers
|
package com.simplemobiletools.contacts.pro.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||||
@ -72,6 +73,12 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
get() = prefs.getString(SPEED_DIAL, "")!!
|
get() = prefs.getString(SPEED_DIAL, "")!!
|
||||||
set(speedDial) = prefs.edit().putString(SPEED_DIAL, speedDial).apply()
|
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<SpeedDial> {
|
fun getSpeedDialValues(): ArrayList<SpeedDial> {
|
||||||
val speedDialType = object : TypeToken<List<SpeedDial>>() {}.type
|
val speedDialType = object : TypeToken<List<SpeedDial>>() {}.type
|
||||||
val speedDialValues = Gson().fromJson<ArrayList<SpeedDial>>(speedDial, speedDialType) ?: ArrayList(1)
|
val speedDialValues = Gson().fromJson<ArrayList<SpeedDial>>(speedDial, speedDialType) ?: ArrayList(1)
|
||||||
|
@ -24,6 +24,7 @@ const val SHOW_DIALPAD_LETTERS = "show_dialpad_letters"
|
|||||||
const val SPEED_DIAL = "speed_dial"
|
const val SPEED_DIAL = "speed_dial"
|
||||||
const val LAST_EXPORT_PATH = "last_export_path"
|
const val LAST_EXPORT_PATH = "last_export_path"
|
||||||
const val WAS_LOCAL_ACCOUNT_INITIALIZED = "was_local_account_initialized"
|
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 CONTACT_ID = "contact_id"
|
||||||
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
|
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
|
const val ALL_TABS_MASK = CONTACTS_TAB_MASK or FAVORITES_TAB_MASK or GROUPS_TAB_MASK
|
||||||
|
|
||||||
val tabsList = arrayListOf(CONTACTS_TAB_MASK,
|
val tabsList = arrayListOf(CONTACTS_TAB_MASK,
|
||||||
FAVORITES_TAB_MASK,
|
FAVORITES_TAB_MASK,
|
||||||
GROUPS_TAB_MASK
|
GROUPS_TAB_MASK
|
||||||
)
|
)
|
||||||
|
|
||||||
// contact photo changes
|
// contact photo changes
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.simplemobiletools.contacts.pro.models
|
||||||
|
|
||||||
|
import android.telecom.PhoneAccountHandle
|
||||||
|
|
||||||
|
data class SIMAccount(val handle: PhoneAccountHandle, val label: String)
|
@ -18,6 +18,18 @@
|
|||||||
<RadioGroup
|
<RadioGroup
|
||||||
android:id="@+id/select_sim_radio_group"
|
android:id="@+id/select_sim_radio_group"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/small_margin" />
|
||||||
|
|
||||||
|
<include layout="@layout/divider" />
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
|
||||||
|
android:id="@+id/select_sim_remember"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/small_margin"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
|
android:paddingBottom="@dimen/activity_margin"
|
||||||
|
android:text="@string/always_use_this_sim" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Reference in New Issue
Block a user