AndroidAPS/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt

485 lines
24 KiB
Kotlin
Raw Normal View History

package info.nightscout.androidaps.activities
2020-03-22 19:59:35 +01:00
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.os.Bundle
import androidx.annotation.XmlRes
2022-11-04 10:32:12 +01:00
import androidx.preference.EditTextPreference
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceGroup
import androidx.preference.PreferenceManager
import androidx.preference.PreferenceScreen
import androidx.preference.size
import dagger.android.support.AndroidSupportInjection
import info.nightscout.androidaps.R
import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.danaRv2.DanaRv2Plugin
import info.nightscout.androidaps.danar.DanaRPlugin
import info.nightscout.androidaps.danars.DanaRSPlugin
2021-06-08 23:27:14 +02:00
import info.nightscout.androidaps.diaconn.DiaconnG8Plugin
import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.events.EventRebuildTabs
2022-03-04 17:11:11 +01:00
import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.PluginBase
2022-03-04 17:11:11 +01:00
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
2022-11-04 10:32:12 +01:00
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugin.general.openhumans.OpenHumansUploader
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
2022-11-04 10:32:12 +01:00
import info.nightscout.androidaps.plugins.aps.openAPSSMBDynamicISF.OpenAPSSMBDynamicISFPlugin
2021-10-15 14:56:22 +02:00
import info.nightscout.androidaps.plugins.bus.RxBus
2020-03-16 21:40:29 +01:00
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin
2020-01-09 21:41:02 +01:00
import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus
import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin
import info.nightscout.androidaps.plugins.general.wear.WearPlugin
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin
import info.nightscout.androidaps.plugins.pump.combov2.ComboV2Plugin
2022-02-11 13:58:07 +09:00
import info.nightscout.androidaps.plugins.pump.eopatch.EopatchPumpPlugin
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin
2022-11-04 10:32:12 +01:00
import info.nightscout.androidaps.plugins.source.AidexPlugin
import info.nightscout.androidaps.plugins.source.DexcomPlugin
import info.nightscout.androidaps.plugins.source.EversensePlugin
import info.nightscout.androidaps.plugins.source.GlimpPlugin
import info.nightscout.androidaps.plugins.source.GlunovoPlugin
import info.nightscout.androidaps.plugins.source.IntelligoPlugin
import info.nightscout.androidaps.plugins.source.PoctechPlugin
import info.nightscout.androidaps.plugins.source.TomatoPlugin
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.show
import info.nightscout.androidaps.utils.protection.PasswordCheck
2022-11-04 10:32:12 +01:00
import info.nightscout.androidaps.utils.protection.ProtectionCheck.ProtectionType.BIOMETRIC
import info.nightscout.androidaps.utils.protection.ProtectionCheck.ProtectionType.CUSTOM_PASSWORD
import info.nightscout.androidaps.utils.protection.ProtectionCheck.ProtectionType.CUSTOM_PIN
import info.nightscout.androidaps.utils.protection.ProtectionCheck.ProtectionType.NONE
import info.nightscout.automation.AutomationPlugin
2022-11-04 20:43:11 +01:00
import info.nightscout.plugins.general.autotune.AutotunePlugin
2022-11-04 10:32:12 +01:00
import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin
2022-11-04 20:43:11 +01:00
import info.nightscout.plugins.general.xdripStatusline.StatusLinePlugin
2022-11-04 10:32:12 +01:00
import info.nightscout.plugins.insulin.InsulinOrefFreePeakPlugin
2022-03-04 17:11:11 +01:00
import info.nightscout.shared.SafeParse
2021-12-10 12:17:03 +01:00
import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Inject
2020-12-06 13:19:53 +01:00
class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListener {
private var pluginId = -1
private var filter = ""
2021-10-15 14:56:22 +02:00
@Inject lateinit var rxBus: RxBus
2021-11-04 10:56:12 +01:00
@Inject lateinit var rh: ResourceHelper
@Inject lateinit var sp: SP
2020-03-10 18:58:27 +01:00
@Inject lateinit var profileFunction: ProfileFunction
2020-03-16 21:40:29 +01:00
@Inject lateinit var pluginStore: PluginStore
2020-05-07 09:54:36 +02:00
@Inject lateinit var config: Config
@Inject lateinit var automationPlugin: AutomationPlugin
2022-05-05 22:37:20 +02:00
@Inject lateinit var autotunePlugin: AutotunePlugin
@Inject lateinit var danaRPlugin: DanaRPlugin
@Inject lateinit var danaRKoreanPlugin: DanaRKoreanPlugin
@Inject lateinit var danaRv2Plugin: DanaRv2Plugin
@Inject lateinit var danaRSPlugin: DanaRSPlugin
2020-01-10 23:14:58 +01:00
@Inject lateinit var comboPlugin: ComboPlugin
@Inject lateinit var combov2Plugin: ComboV2Plugin
@Inject lateinit var insulinOrefFreePeakPlugin: InsulinOrefFreePeakPlugin
@Inject lateinit var loopPlugin: LoopPlugin
2020-01-10 23:14:58 +01:00
@Inject lateinit var localInsightPlugin: LocalInsightPlugin
@Inject lateinit var medtronicPumpPlugin: MedtronicPumpPlugin
@Inject lateinit var nsClientPlugin: NSClientPlugin
@Inject lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
@Inject lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
2022-07-12 18:44:02 +02:00
@Inject lateinit var openAPSSMBDynamicISFPlugin: OpenAPSSMBDynamicISFPlugin
@Inject lateinit var safetyPlugin: SafetyPlugin
2020-01-10 23:14:58 +01:00
@Inject lateinit var sensitivityAAPSPlugin: SensitivityAAPSPlugin
@Inject lateinit var sensitivityOref1Plugin: SensitivityOref1Plugin
@Inject lateinit var sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin
@Inject lateinit var dexcomPlugin: DexcomPlugin
@Inject lateinit var eversensePlugin: EversensePlugin
@Inject lateinit var glimpPlugin: GlimpPlugin
@Inject lateinit var poctechPlugin: PoctechPlugin
@Inject lateinit var tomatoPlugin: TomatoPlugin
2021-11-09 15:26:09 +01:00
@Inject lateinit var glunovoPlugin: GlunovoPlugin
2022-07-31 19:34:22 +03:00
@Inject lateinit var intelligoPlugin: IntelligoPlugin
@Inject lateinit var aidexPlugin: AidexPlugin
@Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin
@Inject lateinit var statusLinePlugin: StatusLinePlugin
@Inject lateinit var tidepoolPlugin: TidepoolPlugin
@Inject lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Inject lateinit var wearPlugin: WearPlugin
2020-01-09 21:41:02 +01:00
@Inject lateinit var maintenancePlugin: MaintenancePlugin
2022-02-11 13:58:07 +09:00
@Inject lateinit var eopatchPumpPlugin: EopatchPumpPlugin
@Inject lateinit var passwordCheck: PasswordCheck
@Inject lateinit var nsSettingStatus: NSSettingsStatus
@Inject lateinit var openHumansUploader: OpenHumansUploader
2021-06-08 23:27:14 +02:00
@Inject lateinit var diaconnG8Plugin: DiaconnG8Plugin
override fun onAttach(context: Context) {
AndroidSupportInjection.inject(this)
super.onAttach(context)
}
override fun setArguments(args: Bundle?) {
super.setArguments(args)
pluginId = args?.getInt("id") ?: -1
filter = args?.getString("filter") ?: ""
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putInt("id", pluginId)
outState.putString("filter", filter)
}
2020-03-06 19:13:33 +01:00
override fun onDestroy() {
super.onDestroy()
2022-02-24 21:25:06 +01:00
context?.let { context ->
PreferenceManager
.getDefaultSharedPreferences(context)
.unregisterOnSharedPreferenceChangeListener(this)
}
2020-03-06 19:13:33 +01:00
}
2020-01-09 21:41:02 +01:00
private fun addPreferencesFromResourceIfEnabled(p: PluginBase?, rootKey: String?, enabled: Boolean) {
if (enabled) addPreferencesFromResourceIfEnabled(p, rootKey)
}
private fun addPreferencesFromResourceIfEnabled(p: PluginBase?, rootKey: String?) {
if (p!!.isEnabled() && p.preferencesId != -1)
addPreferencesFromResource(p.preferencesId, rootKey)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
2022-02-24 21:25:06 +01:00
context?.let { context ->
PreferenceManager
.getDefaultSharedPreferences(context)
.registerOnSharedPreferenceChangeListener(this)
}
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
2020-01-09 21:41:02 +01:00
(savedInstanceState ?: arguments)?.let { bundle ->
if (bundle.containsKey("id")) {
pluginId = bundle.getInt("id")
}
if (bundle.containsKey("filter")) {
filter = bundle.getString("filter") ?: ""
2020-01-09 21:41:02 +01:00
}
}
if (pluginId != -1) {
addPreferencesFromResource(pluginId, rootKey)
} else {
addPreferencesFromResource(R.xml.pref_general, rootKey)
addPreferencesFromResource(R.xml.pref_overview, rootKey)
2020-01-09 21:41:02 +01:00
addPreferencesFromResourceIfEnabled(safetyPlugin, rootKey)
addPreferencesFromResourceIfEnabled(eversensePlugin, rootKey)
addPreferencesFromResourceIfEnabled(dexcomPlugin, rootKey)
addPreferencesFromResourceIfEnabled(tomatoPlugin, rootKey)
2021-11-09 15:26:09 +01:00
addPreferencesFromResourceIfEnabled(glunovoPlugin, rootKey)
2022-07-31 19:34:22 +03:00
addPreferencesFromResourceIfEnabled(intelligoPlugin, rootKey)
addPreferencesFromResourceIfEnabled(poctechPlugin, rootKey)
addPreferencesFromResourceIfEnabled(aidexPlugin, rootKey)
addPreferencesFromResourceIfEnabled(glimpPlugin, rootKey)
2020-05-07 09:54:36 +02:00
addPreferencesFromResourceIfEnabled(loopPlugin, rootKey, config.APS)
addPreferencesFromResourceIfEnabled(openAPSAMAPlugin, rootKey, config.APS)
addPreferencesFromResourceIfEnabled(openAPSSMBPlugin, rootKey, config.APS)
2022-07-12 18:44:02 +02:00
addPreferencesFromResourceIfEnabled(openAPSSMBDynamicISFPlugin, rootKey, config.APS)
2020-01-10 23:14:58 +01:00
addPreferencesFromResourceIfEnabled(sensitivityAAPSPlugin, rootKey)
addPreferencesFromResourceIfEnabled(sensitivityWeightedAveragePlugin, rootKey)
addPreferencesFromResourceIfEnabled(sensitivityOref1Plugin, rootKey)
2020-05-07 09:54:36 +02:00
addPreferencesFromResourceIfEnabled(danaRPlugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(danaRKoreanPlugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(danaRv2Plugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(danaRSPlugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(localInsightPlugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(comboPlugin, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(combov2Plugin, rootKey, config.PUMPDRIVERS)
2020-05-07 09:54:36 +02:00
addPreferencesFromResourceIfEnabled(medtronicPumpPlugin, rootKey, config.PUMPDRIVERS)
2021-06-08 23:27:14 +02:00
addPreferencesFromResourceIfEnabled(diaconnG8Plugin, rootKey, config.PUMPDRIVERS)
2022-02-11 13:58:07 +09:00
addPreferencesFromResourceIfEnabled(eopatchPumpPlugin, rootKey, config.PUMPDRIVERS)
2022-11-03 17:06:59 +01:00
addPreferencesFromResource(R.xml.pref_pump, rootKey, config.PUMPDRIVERS)
addPreferencesFromResourceIfEnabled(virtualPumpPlugin, rootKey)
addPreferencesFromResourceIfEnabled(insulinOrefFreePeakPlugin, rootKey)
2020-01-10 23:14:58 +01:00
addPreferencesFromResourceIfEnabled(nsClientPlugin, rootKey)
addPreferencesFromResourceIfEnabled(tidepoolPlugin, rootKey)
addPreferencesFromResourceIfEnabled(smsCommunicatorPlugin, rootKey)
addPreferencesFromResourceIfEnabled(automationPlugin, rootKey)
2022-05-05 22:37:20 +02:00
addPreferencesFromResourceIfEnabled(autotunePlugin, rootKey)
addPreferencesFromResourceIfEnabled(wearPlugin, rootKey)
addPreferencesFromResourceIfEnabled(statusLinePlugin, rootKey)
2021-05-29 23:38:19 +02:00
addPreferencesFromResource(R.xml.pref_alerts, rootKey)
2020-01-09 21:41:02 +01:00
addPreferencesFromResource(R.xml.pref_datachoices, rootKey)
addPreferencesFromResourceIfEnabled(maintenancePlugin, rootKey)
addPreferencesFromResourceIfEnabled(openHumansUploader, rootKey)
}
initSummary(preferenceScreen, pluginId != -1)
2020-07-26 12:56:47 +02:00
preprocessPreferences()
if (filter != "") updateFilterVisibility(filter, preferenceScreen)
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
rxBus.send(EventPreferenceChange(key))
2021-11-04 10:56:12 +01:00
if (key == rh.gs(R.string.key_language)) {
rxBus.send(EventRebuildTabs(true))
//recreate() does not update language so better close settings
activity?.finish()
}
2021-11-04 10:56:12 +01:00
if (key == rh.gs(R.string.key_short_tabtitles)) {
rxBus.send(EventRebuildTabs())
}
2021-11-04 10:56:12 +01:00
if (key == rh.gs(R.string.key_units)) {
activity?.recreate()
return
}
2021-11-04 10:56:12 +01:00
if (key == rh.gs(R.string.key_openapsama_useautosens) && sp.getBoolean(R.string.key_openapsama_useautosens, false)) {
activity?.let {
2021-11-04 10:56:12 +01:00
show(it, rh.gs(R.string.configbuilder_sensitivity), rh.gs(R.string.sensitivity_warning))
}
}
checkForBiometricFallback(key)
updatePrefSummary(findPreference(key))
2020-07-26 12:56:47 +02:00
preprocessPreferences()
}
private fun preprocessPreferences() {
for (plugin in pluginStore.plugins) {
plugin.preprocessPreferences(this)
}
}
private fun checkForBiometricFallback(key: String) {
// Biometric protection activated without set master password
2021-11-04 10:56:12 +01:00
if ((rh.gs(R.string.key_settings_protection) == key ||
rh.gs(R.string.key_application_protection) == key ||
rh.gs(R.string.key_bolus_protection) == key) &&
sp.getString(R.string.key_master_password, "") == "" &&
2022-03-04 17:11:11 +01:00
sp.getInt(key, NONE.ordinal) == BIOMETRIC.ordinal
) {
activity?.let {
2021-11-04 10:56:12 +01:00
val title = rh.gs(R.string.unsecure_fallback_biometric)
val message = rh.gs(R.string.master_password_missing, rh.gs(R.string.configbuilder_general), rh.gs(R.string.protection))
show(it, title = title, message = message)
}
}
// Master password erased with activated Biometric protection
2022-03-04 17:11:11 +01:00
val isBiometricActivated = sp.getInt(R.string.key_settings_protection, NONE.ordinal) == BIOMETRIC.ordinal ||
sp.getInt(R.string.key_application_protection, NONE.ordinal) == BIOMETRIC.ordinal ||
sp.getInt(R.string.key_bolus_protection, NONE.ordinal) == BIOMETRIC.ordinal
2021-11-04 10:56:12 +01:00
if (rh.gs(R.string.key_master_password) == key && sp.getString(key, "") == "" && isBiometricActivated) {
activity?.let {
2021-11-04 10:56:12 +01:00
val title = rh.gs(R.string.unsecure_fallback_biometric)
val message = rh.gs(R.string.unsecure_fallback_descriotion_biometric)
show(it, title = title, message = message)
}
}
}
2020-12-06 13:19:53 +01:00
private fun addPreferencesFromResource(@Suppress("SameParameterValue") @XmlRes preferencesResId: Int, key: String?, enabled: Boolean) {
if (enabled) addPreferencesFromResource(preferencesResId, key)
}
2020-03-22 19:59:35 +01:00
@SuppressLint("RestrictedApi")
2020-01-10 23:14:58 +01:00
private fun addPreferencesFromResource(@XmlRes preferencesResId: Int, key: String?) {
2022-02-24 21:25:06 +01:00
context?.let { context ->
val xmlRoot = preferenceManager.inflateFromResource(context, preferencesResId, null)
val root: Preference?
if (key != null) {
root = xmlRoot.findPreference(key)
if (root == null) return
require(root is PreferenceScreen) {
("Preference object with key $key is not a PreferenceScreen")
}
preferenceScreen = root
} else {
addPreferencesFromResource(preferencesResId)
}
}
}
private fun adjustUnitDependentPrefs(pref: Preference) { // convert preferences values to current units
val unitDependent = arrayOf(
2021-11-04 10:56:12 +01:00
rh.gs(R.string.key_hypo_target),
rh.gs(R.string.key_activity_target),
rh.gs(R.string.key_eatingsoon_target),
rh.gs(R.string.key_high_mark),
rh.gs(R.string.key_low_mark)
)
2020-05-13 23:28:07 +02:00
if (unitDependent.toList().contains(pref.key) && pref is EditTextPreference) {
val converted = Profile.toCurrentUnits(profileFunction, SafeParse.stringToDouble(pref.text))
pref.summary = converted.toString()
}
}
private fun updateFilterVisibility(filter: String, p: Preference): Boolean {
var visible = false
if (p is PreferenceGroup) {
for (i in 0 until p.preferenceCount) {
visible = updateFilterVisibility(filter, p.getPreference(i)) || visible
}
if (visible && p is PreferenceCategory) {
p.initialExpandedChildrenCount = Int.MAX_VALUE
}
} else {
2022-11-04 20:43:11 +01:00
visible = visible || p.key?.contains(filter, true) == true
visible = visible || p.title?.contains(filter, true) == true
visible = visible || p.summary?.contains(filter, true) == true
}
p.isVisible = visible
return visible
}
private fun updatePrefSummary(pref: Preference?) {
if (pref is ListPreference) {
pref.setSummary(pref.entry)
2020-03-22 19:59:35 +01:00
// Preferences
2021-11-04 10:56:12 +01:00
if (pref.getKey() == rh.gs(R.string.key_settings_protection)) {
val pass: Preference? = findPreference(rh.gs(R.string.key_settings_password))
2022-03-04 17:11:11 +01:00
val usePassword = pref.value == CUSTOM_PASSWORD.ordinal.toString()
pass?.let { it.isVisible = usePassword }
val pin: Preference? = findPreference(rh.gs(R.string.key_settings_pin))
val usePin = pref.value == CUSTOM_PIN.ordinal.toString()
pin?.let { it.isVisible = usePin }
2020-03-22 19:59:35 +01:00
}
// Application
2021-11-04 10:56:12 +01:00
if (pref.getKey() == rh.gs(R.string.key_application_protection)) {
val pass: Preference? = findPreference(rh.gs(R.string.key_application_password))
2022-03-04 17:11:11 +01:00
val usePassword = pref.value == CUSTOM_PASSWORD.ordinal.toString()
pass?.let { it.isVisible = usePassword }
val pin: Preference? = findPreference(rh.gs(R.string.key_application_pin))
val usePin = pref.value == CUSTOM_PIN.ordinal.toString()
pin?.let { it.isVisible = usePin }
2020-03-22 19:59:35 +01:00
}
// Bolus
2021-11-04 10:56:12 +01:00
if (pref.getKey() == rh.gs(R.string.key_bolus_protection)) {
val pass: Preference? = findPreference(rh.gs(R.string.key_bolus_password))
2022-03-04 17:11:11 +01:00
val usePassword = pref.value == CUSTOM_PASSWORD.ordinal.toString()
pass?.let { it.isVisible = usePassword }
val pin: Preference? = findPreference(rh.gs(R.string.key_bolus_pin))
val usePin = pref.value == CUSTOM_PIN.ordinal.toString()
pin?.let { it.isVisible = usePin }
2020-03-22 19:59:35 +01:00
}
}
if (pref is EditTextPreference) {
2022-06-28 11:25:14 +02:00
if (pref.getKey().contains("password") || pref.getKey().contains("pin") || pref.getKey().contains("secret") || pref.getKey().contains("token")) {
pref.setSummary("******")
2020-01-10 23:14:58 +01:00
} else if (pref.text != null) {
pref.dialogMessage = pref.dialogMessage
pref.setSummary(pref.text)
}
}
2020-04-27 21:14:45 +02:00
for (plugin in pluginStore.plugins) {
pref?.let { it.key?.let { plugin.updatePreferenceSummary(pref) } }
2020-04-27 21:14:45 +02:00
}
val hmacPasswords = arrayOf(
2021-11-04 10:56:12 +01:00
rh.gs(R.string.key_bolus_password),
rh.gs(R.string.key_master_password),
rh.gs(R.string.key_application_password),
2022-03-04 17:11:11 +01:00
rh.gs(R.string.key_settings_password),
rh.gs(R.string.key_bolus_pin),
rh.gs(R.string.key_application_pin),
rh.gs(R.string.key_settings_pin)
)
if (pref is Preference) {
if ((pref.key != null) && (hmacPasswords.contains(pref.key))) {
if (sp.getString(pref.key, "").startsWith("hmac:")) {
pref.summary = "******"
} else {
2022-03-30 20:54:06 +02:00
if (pref.key.contains("pin")) {
2022-03-04 17:11:11 +01:00
pref.summary = rh.gs(R.string.pin_not_set)
2022-11-04 20:43:11 +01:00
} else {
2022-03-04 17:11:11 +01:00
pref.summary = rh.gs(R.string.password_not_set)
}
}
}
}
pref?.let { adjustUnitDependentPrefs(it) }
}
private fun initSummary(p: Preference, isSinglePreference: Boolean) {
p.isIconSpaceReserved = false // remove extra spacing on left after migration to androidx
// expand single plugin preference by default
if (p is PreferenceScreen && isSinglePreference) {
if (p.size > 0 && p.getPreference(0) is PreferenceCategory)
(p.getPreference(0) as PreferenceCategory).initialExpandedChildrenCount = Int.MAX_VALUE
}
if (p is PreferenceGroup) {
2020-01-10 23:14:58 +01:00
for (i in 0 until p.preferenceCount) {
initSummary(p.getPreference(i), isSinglePreference)
}
} else {
updatePrefSummary(p)
}
}
// We use Preference and custom editor instead of EditTextPreference
// to hash password while it is saved and never have to show it, even hashed
2022-02-24 21:25:06 +01:00
override fun onPreferenceTreeClick(preference: Preference): Boolean {
context?.let { context ->
2022-02-24 21:25:06 +01:00
if (preference.key == rh.gs(R.string.key_master_password)) {
passwordCheck.queryPassword(context, R.string.current_master_password, R.string.key_master_password, {
passwordCheck.setPassword(context, R.string.master_password, R.string.key_master_password)
})
return true
}
if (preference.key == rh.gs(R.string.key_settings_password)) {
passwordCheck.setPassword(context, R.string.settings_password, R.string.key_settings_password)
return true
}
if (preference.key == rh.gs(R.string.key_bolus_password)) {
passwordCheck.setPassword(context, R.string.bolus_password, R.string.key_bolus_password)
return true
}
if (preference.key == rh.gs(R.string.key_application_password)) {
passwordCheck.setPassword(context, R.string.application_password, R.string.key_application_password)
return true
}
2022-03-04 17:11:11 +01:00
if (preference.key == rh.gs(R.string.key_settings_pin)) {
passwordCheck.setPassword(context, R.string.settings_pin, R.string.key_settings_pin, pinInput = true)
return true
}
if (preference.key == rh.gs(R.string.key_bolus_pin)) {
passwordCheck.setPassword(context, R.string.bolus_pin, R.string.key_bolus_pin, pinInput = true)
return true
}
if (preference.key == rh.gs(R.string.key_application_pin)) {
passwordCheck.setPassword(context, R.string.application_pin, R.string.key_application_pin, pinInput = true)
return true
}
2022-02-24 21:25:06 +01:00
// NSClient copy settings
if (preference.key == rh.gs(R.string.key_statuslights_copy_ns)) {
nsSettingStatus.copyStatusLightsNsSettings(context)
return true
}
}
return super.onPreferenceTreeClick(preference)
}
2020-12-06 13:19:53 +01:00
fun setFilter(filter: String) {
this.filter = filter
preferenceManager?.preferenceScreen?.let { updateFilterVisibility(filter, it) }
}
}