mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-04-15 18:47:23 +02:00
Fix dual simcard with same label bug
This commit is contained in:
parent
362757fa42
commit
5cca5b51a4
@ -31,7 +31,7 @@ class SelectSIMDialog(val activity: BaseSimpleActivity, val phoneNumber: String,
|
|||||||
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 = "${index + 1} - ${SIMAccount.label}"
|
text = "${index + 1} - ${SIMAccount.label}"
|
||||||
id = index
|
id = index
|
||||||
setOnClickListener { selectedSIM(SIMAccount.handle, SIMAccount.label) }
|
setOnClickListener { selectedSIM(SIMAccount.handle) }
|
||||||
}
|
}
|
||||||
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,9 +44,9 @@ class SelectSIMDialog(val activity: BaseSimpleActivity, val phoneNumber: String,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun selectedSIM(handle: PhoneAccountHandle, label: String) {
|
private fun selectedSIM(handle: PhoneAccountHandle) {
|
||||||
if (view.select_sim_remember.isChecked) {
|
if (view.select_sim_remember.isChecked) {
|
||||||
activity.config.saveCustomSIM(phoneNumber, label)
|
activity.config.saveCustomSIM(phoneNumber, handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(handle)
|
callback(handle)
|
||||||
|
@ -75,12 +75,10 @@ fun SimpleActivity.getHandleToUse(intent: Intent?, phoneNumber: String, callback
|
|||||||
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)!!)
|
||||||
config.getCustomSIM(phoneNumber)?.isNotEmpty() == true -> {
|
config.getCustomSIM() != null -> {
|
||||||
val storedLabel = Uri.decode(config.getCustomSIM(phoneNumber))
|
callback(config.getCustomSIM())
|
||||||
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 -> {
|
||||||
SelectSIMDialog(this, phoneNumber) { handle ->
|
SelectSIMDialog(this, phoneNumber) { handle ->
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.simplemobiletools.dialer.extensions
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.telecom.PhoneAccountHandle
|
||||||
|
import com.simplemobiletools.dialer.models.PhoneAccountHandleModel
|
||||||
|
import com.google.gson.Gson
|
||||||
|
|
||||||
|
fun SharedPreferences.Editor.putPhoneAccountHandle(
|
||||||
|
key: String,
|
||||||
|
parcelable: PhoneAccountHandle
|
||||||
|
): SharedPreferences.Editor {
|
||||||
|
val componentName = parcelable.componentName
|
||||||
|
val myPhoneAccountHandleModel = PhoneAccountHandleModel(
|
||||||
|
componentName.packageName, componentName.className, parcelable.id
|
||||||
|
)
|
||||||
|
val json = Gson().toJson(myPhoneAccountHandleModel)
|
||||||
|
return putString(key, json)
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T : PhoneAccountHandleModel?> SharedPreferences.getPhoneAccountHandleModel(
|
||||||
|
key: String,
|
||||||
|
default: T
|
||||||
|
): T {
|
||||||
|
val json = getString(key, null)
|
||||||
|
return try {
|
||||||
|
if (json != null)
|
||||||
|
Gson().fromJson(json, T::class.java)
|
||||||
|
else default
|
||||||
|
} catch (_: JsonSyntaxException) {
|
||||||
|
default
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,9 @@
|
|||||||
package com.simplemobiletools.dialer.helpers
|
package com.simplemobiletools.dialer.helpers
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.telecom.PhoneAccountHandle
|
||||||
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
|
||||||
@ -30,11 +32,24 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
return speedDialValues
|
return speedDialValues
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveCustomSIM(number: String, SIMlabel: String) {
|
fun saveCustomSIM(number: String, handle: PhoneAccountHandle) {
|
||||||
prefs.edit().putString(REMEMBER_SIM_PREFIX + number, Uri.encode(SIMlabel)).apply()
|
prefs.edit().putPhoneAccountHandle(REMEMBER_SIM_PREFIX + number,handle).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCustomSIM(number: String) = prefs.getString(REMEMBER_SIM_PREFIX + number, "")
|
fun getCustomSIM(number: String): PhoneAccountHandle? {
|
||||||
|
val myPhoneAccountHandle =
|
||||||
|
prefs.getPhoneAccountHandleModel(REMEMBER_SIM_PREFIX + number, null)
|
||||||
|
return if (myPhoneAccountHandle != null) {
|
||||||
|
val packageName = myPhoneAccountHandle.packageName
|
||||||
|
val className = myPhoneAccountHandle.className
|
||||||
|
val componentName = ComponentName(packageName, className)
|
||||||
|
val id = myPhoneAccountHandle.id
|
||||||
|
|
||||||
|
PhoneAccountHandle(componentName, id)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun removeCustomSIM(number: String) {
|
fun removeCustomSIM(number: String) {
|
||||||
prefs.edit().remove(REMEMBER_SIM_PREFIX + number).apply()
|
prefs.edit().remove(REMEMBER_SIM_PREFIX + number).apply()
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.simplemobiletools.dialer.models
|
||||||
|
|
||||||
|
data class PhoneAccountHandleModel(
|
||||||
|
val packageName: String,
|
||||||
|
val className: String,
|
||||||
|
val id: String
|
||||||
|
)
|
@ -5,6 +5,8 @@ buildscript {
|
|||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
|
maven { url 'https://jitpack.io' }
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:7.3.1'
|
classpath 'com.android.tools.build:gradle:7.3.1'
|
||||||
@ -19,6 +21,7 @@ allprojects {
|
|||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
maven { url 'https://jitpack.io' }
|
maven { url 'https://jitpack.io' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user