tls prefs wip

This commit is contained in:
Jonathan Fisher 2020-11-09 22:08:56 +00:00
parent 63081b2cf9
commit 6c7f6d4b19
1 changed files with 22 additions and 9 deletions

View File

@ -41,19 +41,32 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
}
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
preference?.key?.let{ key ->
if(key.startsWith("tls_")){
protocols.forEach {protocol ->
val tlsSwitchKey = "tls_${protocol.toLowerCase(Locale.getDefault())}"
if(tlsSwitchKey != key){
val otherTLSSwitch = preferenceScreen.findPreference<SwitchPreferenceCompat>(tlsSwitchKey)
otherTLSSwitch?.isChecked = false
if(preference is SwitchPreferenceCompat && newValue is Boolean && newValue == true) {
preference.key?.let { key ->
if (key.startsWith("tls_")) {
protocols.forEach { protocol ->
val tlsSwitchKey = "tls_${protocol.toLowerCase(Locale.getDefault())}"
if (tlsSwitchKey != key) {
val otherTLSSwitch =
preferenceScreen.findPreference<SwitchPreferenceCompat>(tlsSwitchKey)
otherTLSSwitch?.isChecked = false
}
}
}
}
setTLSProtocol(preference.title.toString())
return true
}
return true
return false
}
private fun setTLSProtocol(protocol: String){
preferenceManager.sharedPreferences.edit().putString(
"tls_protocol",
protocol
).apply()
}
}