2020-01-08 20:20:20 +01:00
|
|
|
package info.nightscout.androidaps.activities
|
|
|
|
|
2020-03-22 19:59:35 +01:00
|
|
|
import android.annotation.SuppressLint
|
2020-01-08 20:20:20 +01:00
|
|
|
import android.content.Context
|
|
|
|
import android.content.SharedPreferences
|
|
|
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
|
|
|
import android.os.Bundle
|
|
|
|
import androidx.annotation.XmlRes
|
|
|
|
import androidx.preference.*
|
|
|
|
import dagger.android.AndroidInjector
|
|
|
|
import dagger.android.DispatchingAndroidInjector
|
|
|
|
import dagger.android.HasAndroidInjector
|
|
|
|
import dagger.android.support.AndroidSupportInjection
|
|
|
|
import info.nightscout.androidaps.Config
|
|
|
|
import info.nightscout.androidaps.R
|
|
|
|
import info.nightscout.androidaps.data.Profile
|
|
|
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
|
|
|
import info.nightscout.androidaps.events.EventRebuildTabs
|
|
|
|
import info.nightscout.androidaps.interfaces.PluginBase
|
|
|
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
2020-03-16 21:40:29 +01:00
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
2020-05-07 09:54:36 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
2020-01-08 20:20:20 +01:00
|
|
|
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin
|
2020-01-09 21:41:02 +01:00
|
|
|
import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin
|
2020-01-08 20:20:20 +01:00
|
|
|
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin
|
2020-04-23 22:54:28 +02:00
|
|
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus
|
2020-01-08 20:20:20 +01:00
|
|
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.general.wear.WearPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatusLinePlugin
|
|
|
|
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
|
2020-05-09 20:18:12 +02:00
|
|
|
import info.nightscout.androidaps.danars.DanaRSPlugin
|
2020-01-08 20:20:20 +01:00
|
|
|
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
|
|
|
|
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
|
|
|
|
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.PoctechPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.source.TomatoPlugin
|
|
|
|
import info.nightscout.androidaps.utils.SafeParse
|
2020-04-23 22:54:28 +02:00
|
|
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.show
|
2020-03-24 22:22:23 +01:00
|
|
|
import info.nightscout.androidaps.utils.protection.PasswordCheck
|
2020-03-22 19:59:35 +01:00
|
|
|
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
2020-01-08 20:20:20 +01:00
|
|
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
|
|
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListener, HasAndroidInjector {
|
|
|
|
private var pluginId = -1
|
|
|
|
|
|
|
|
@Inject lateinit var rxBus: RxBusWrapper
|
|
|
|
@Inject lateinit var resourceHelper: 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
|
2020-01-08 20:20:20 +01:00
|
|
|
|
|
|
|
@Inject lateinit var automationPlugin: AutomationPlugin
|
|
|
|
@Inject lateinit var danaRPlugin: DanaRPlugin
|
|
|
|
@Inject lateinit var danaRKoreanPlugin: DanaRKoreanPlugin
|
|
|
|
@Inject lateinit var danaRv2Plugin: DanaRv2Plugin
|
|
|
|
@Inject lateinit var danaRSPlugin: DanaRSPlugin
|
|
|
|
@Inject lateinit var careportalPlugin: CareportalPlugin
|
2020-01-10 23:14:58 +01:00
|
|
|
@Inject lateinit var comboPlugin: ComboPlugin
|
2020-01-08 20:20:20 +01:00
|
|
|
@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
|
2020-01-08 20:20:20 +01:00
|
|
|
@Inject lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
|
|
|
|
@Inject lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
|
|
|
|
@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
|
2020-01-08 20:20:20 +01:00
|
|
|
@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
|
|
|
|
@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
|
2020-01-08 20:20:20 +01:00
|
|
|
|
2020-03-24 22:22:23 +01:00
|
|
|
@Inject lateinit var passwordCheck: PasswordCheck
|
2020-04-23 22:54:28 +02:00
|
|
|
@Inject lateinit var nsSettingStatus: NSSettingsStatus
|
2020-03-24 22:22:23 +01:00
|
|
|
|
2020-05-07 09:54:36 +02:00
|
|
|
// TODO why?
|
2020-01-08 20:20:20 +01:00
|
|
|
@Inject lateinit var androidInjector: DispatchingAndroidInjector<Any>
|
|
|
|
|
|
|
|
override fun androidInjector(): AndroidInjector<Any> = androidInjector
|
|
|
|
|
|
|
|
override fun onAttach(context: Context) {
|
|
|
|
AndroidSupportInjection.inject(this)
|
|
|
|
super.onAttach(context)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun setArguments(args: Bundle?) {
|
|
|
|
super.setArguments(args)
|
|
|
|
pluginId = args?.getInt("id") ?: -1
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSaveInstanceState(outState: Bundle) {
|
|
|
|
super.onSaveInstanceState(outState)
|
|
|
|
outState.putInt("id", pluginId)
|
|
|
|
}
|
|
|
|
|
2020-03-06 19:13:33 +01:00
|
|
|
override fun onDestroy() {
|
|
|
|
super.onDestroy()
|
|
|
|
PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(context)
|
|
|
|
.unregisterOnSharedPreferenceChangeListener(this)
|
|
|
|
}
|
|
|
|
|
2020-01-09 21:41:02 +01:00
|
|
|
private fun addPreferencesFromResourceIfEnabled(p: PluginBase?, rootKey: String?, enabled: Boolean) {
|
|
|
|
if (enabled) addPreferencesFromResourceIfEnabled(p, rootKey)
|
|
|
|
}
|
|
|
|
|
2020-01-08 20:20:20 +01:00
|
|
|
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)
|
|
|
|
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")
|
|
|
|
}
|
2020-01-08 20:20:20 +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)
|
2020-01-08 20:20:20 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(eversensePlugin, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(dexcomPlugin, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(tomatoPlugin, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(poctechPlugin, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(glimpPlugin, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(careportalPlugin, rootKey)
|
2020-05-07 09:54:36 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(loopPlugin, rootKey, config.APS)
|
|
|
|
addPreferencesFromResourceIfEnabled(openAPSAMAPlugin, rootKey, config.APS)
|
|
|
|
addPreferencesFromResourceIfEnabled(openAPSSMBPlugin, 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(medtronicPumpPlugin, rootKey, config.PUMPDRIVERS)
|
|
|
|
addPreferencesFromResourceIfEnabled(virtualPumpPlugin, rootKey, !config.NSCLIENT)
|
2020-01-08 20:20:20 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(insulinOrefFreePeakPlugin, rootKey)
|
2020-01-10 23:14:58 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(nsClientPlugin, rootKey)
|
2020-01-08 20:20:20 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(tidepoolPlugin, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(smsCommunicatorPlugin, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(automationPlugin, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(wearPlugin, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(statusLinePlugin, rootKey)
|
2020-01-09 21:41:02 +01:00
|
|
|
addPreferencesFromResource(R.xml.pref_alerts, rootKey) // TODO not organized well
|
|
|
|
addPreferencesFromResource(R.xml.pref_datachoices, rootKey)
|
|
|
|
addPreferencesFromResourceIfEnabled(maintenancePlugin, rootKey)
|
2020-01-08 20:20:20 +01:00
|
|
|
}
|
2020-03-27 21:32:47 +01:00
|
|
|
initSummary(preferenceScreen, pluginId != -1)
|
2020-03-16 21:40:29 +01:00
|
|
|
for (plugin in pluginStore.plugins) {
|
2020-01-08 20:20:20 +01:00
|
|
|
plugin.preprocessPreferences(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
|
|
|
|
rxBus.send(EventPreferenceChange(key))
|
|
|
|
if (key == resourceHelper.gs(R.string.key_language)) {
|
|
|
|
rxBus.send(EventRebuildTabs(true))
|
|
|
|
//recreate() does not update language so better close settings
|
|
|
|
activity?.finish()
|
|
|
|
}
|
|
|
|
if (key == resourceHelper.gs(R.string.key_short_tabtitles)) {
|
|
|
|
rxBus.send(EventRebuildTabs())
|
|
|
|
}
|
|
|
|
if (key == resourceHelper.gs(R.string.key_units)) {
|
|
|
|
activity?.recreate()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (key == resourceHelper.gs(R.string.key_openapsama_useautosens) && sp.getBoolean(R.string.key_openapsama_useautosens, false))
|
|
|
|
activity?.let {
|
|
|
|
show(it, resourceHelper.gs(R.string.configbuilder_sensitivity), resourceHelper.gs(R.string.sensitivity_warning))
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePrefSummary(findPreference(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?) {
|
2020-01-08 20:20:20 +01:00
|
|
|
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(
|
|
|
|
resourceHelper.gs(R.string.key_hypo_target),
|
|
|
|
resourceHelper.gs(R.string.key_activity_target),
|
|
|
|
resourceHelper.gs(R.string.key_eatingsoon_target),
|
|
|
|
resourceHelper.gs(R.string.key_high_mark),
|
|
|
|
resourceHelper.gs(R.string.key_low_mark)
|
|
|
|
)
|
2020-01-10 23:14:58 +01:00
|
|
|
if (listOf(*unitDependent).contains(pref.key)) {
|
2020-01-08 20:20:20 +01:00
|
|
|
val editTextPref = pref as EditTextPreference
|
2020-03-10 18:58:27 +01:00
|
|
|
val converted = Profile.toCurrentUnitsString(profileFunction, SafeParse.stringToDouble(editTextPref.text))
|
2020-01-08 20:20:20 +01:00
|
|
|
editTextPref.summary = converted
|
|
|
|
editTextPref.text = converted
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun updatePrefSummary(pref: Preference?) {
|
|
|
|
if (pref is ListPreference) {
|
|
|
|
pref.setSummary(pref.entry)
|
2020-03-22 19:59:35 +01:00
|
|
|
// Preferences
|
|
|
|
// Preferences
|
|
|
|
if (pref.getKey() == resourceHelper.gs(R.string.key_settings_protection)) {
|
|
|
|
val pass: Preference? = findPreference(resourceHelper.gs(R.string.key_settings_password))
|
2020-03-24 22:22:23 +01:00
|
|
|
if (pass != null) pass.isEnabled = pref.value == ProtectionCheck.ProtectionType.CUSTOM_PASSWORD.ordinal.toString()
|
2020-03-22 19:59:35 +01:00
|
|
|
}
|
|
|
|
// Application
|
|
|
|
// Application
|
|
|
|
if (pref.getKey() == resourceHelper.gs(R.string.key_application_protection)) {
|
|
|
|
val pass: Preference? = findPreference(resourceHelper.gs(R.string.key_application_password))
|
2020-03-24 22:22:23 +01:00
|
|
|
if (pass != null) pass.isEnabled = pref.value == ProtectionCheck.ProtectionType.CUSTOM_PASSWORD.ordinal.toString()
|
2020-03-22 19:59:35 +01:00
|
|
|
}
|
|
|
|
// Bolus
|
|
|
|
// Bolus
|
|
|
|
if (pref.getKey() == resourceHelper.gs(R.string.key_bolus_protection)) {
|
|
|
|
val pass: Preference? = findPreference(resourceHelper.gs(R.string.key_bolus_password))
|
2020-03-24 22:22:23 +01:00
|
|
|
if (pass != null) pass.isEnabled = pref.value == ProtectionCheck.ProtectionType.CUSTOM_PASSWORD.ordinal.toString()
|
2020-03-22 19:59:35 +01:00
|
|
|
}
|
2020-01-08 20:20:20 +01:00
|
|
|
}
|
|
|
|
if (pref is EditTextPreference) {
|
|
|
|
if (pref.getKey().contains("password") || pref.getKey().contains("secret")) {
|
|
|
|
pref.setSummary("******")
|
2020-01-10 23:14:58 +01:00
|
|
|
} else if (pref.text != null) {
|
|
|
|
pref.dialogMessage = pref.dialogMessage
|
|
|
|
pref.setSummary(pref.text)
|
2020-01-08 20:20:20 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 22:22:23 +01:00
|
|
|
|
2020-04-27 21:14:45 +02:00
|
|
|
for (plugin in pluginStore.plugins) {
|
2020-05-05 22:42:16 +02:00
|
|
|
pref?.let { it.key?.let { plugin.updatePreferenceSummary(pref) }}
|
2020-04-27 21:14:45 +02:00
|
|
|
}
|
|
|
|
|
2020-04-02 19:14:50 +02:00
|
|
|
val hmacPasswords = arrayOf(
|
|
|
|
resourceHelper.gs(R.string.key_bolus_password),
|
|
|
|
resourceHelper.gs(R.string.key_master_password),
|
|
|
|
resourceHelper.gs(R.string.key_application_password),
|
|
|
|
resourceHelper.gs(R.string.key_settings_password)
|
|
|
|
)
|
|
|
|
|
2020-03-24 22:22:23 +01:00
|
|
|
if (pref is Preference) {
|
2020-04-02 19:14:50 +02:00
|
|
|
if ((pref.key != null) && (hmacPasswords.contains(pref.key))) {
|
2020-03-27 21:32:47 +01:00
|
|
|
if (sp.getString(pref.key, "").startsWith("hmac:")) {
|
|
|
|
pref.summary = "******"
|
2020-03-24 22:22:23 +01:00
|
|
|
} else {
|
2020-03-27 21:32:47 +01:00
|
|
|
pref.summary = resourceHelper.gs(R.string.password_not_set)
|
2020-03-24 22:22:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-08 20:20:20 +01:00
|
|
|
pref?.let { adjustUnitDependentPrefs(it) }
|
|
|
|
}
|
|
|
|
|
2020-03-27 21:32:47 +01:00
|
|
|
private fun initSummary(p: Preference, isSinglePreference: Boolean) {
|
2020-01-08 20:20:20 +01:00
|
|
|
p.isIconSpaceReserved = false // remove extra spacing on left after migration to androidx
|
2020-03-27 21:32:47 +01:00
|
|
|
// 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
|
|
|
|
}
|
2020-01-08 20:20:20 +01:00
|
|
|
if (p is PreferenceGroup) {
|
2020-01-10 23:14:58 +01:00
|
|
|
for (i in 0 until p.preferenceCount) {
|
2020-03-27 21:32:47 +01:00
|
|
|
initSummary(p.getPreference(i), isSinglePreference)
|
2020-01-08 20:20:20 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
updatePrefSummary(p)
|
|
|
|
}
|
|
|
|
}
|
2020-03-24 22:22:23 +01:00
|
|
|
|
|
|
|
// We use Preference and custom editor instead of EditTextPreference
|
|
|
|
// to hash password while it is saved and never have to show it, even hashed
|
|
|
|
|
|
|
|
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
|
2020-03-27 21:32:47 +01:00
|
|
|
context?.let { context ->
|
|
|
|
if (preference != null) {
|
|
|
|
if (preference.key == resourceHelper.gs(R.string.key_master_password)) {
|
2020-04-21 14:50:28 +02:00
|
|
|
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)
|
|
|
|
})
|
2020-03-27 21:32:47 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (preference.key == resourceHelper.gs(R.string.key_settings_password)) {
|
|
|
|
passwordCheck.setPassword(context, R.string.settings_password, R.string.key_settings_password)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (preference.key == resourceHelper.gs(R.string.key_bolus_password)) {
|
|
|
|
passwordCheck.setPassword(context, R.string.bolus_password, R.string.key_bolus_password)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if (preference.key == resourceHelper.gs(R.string.key_application_password)) {
|
|
|
|
passwordCheck.setPassword(context, R.string.application_password, R.string.key_application_password)
|
|
|
|
return true
|
|
|
|
}
|
2020-04-23 22:54:28 +02:00
|
|
|
// NSClient copy settings
|
|
|
|
if (preference.key == resourceHelper.gs(R.string.key_statuslights_copy_ns)) {
|
|
|
|
nsSettingStatus.copyStatusLightsNsSettings(context)
|
|
|
|
return true
|
|
|
|
}
|
2020-03-24 22:22:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onPreferenceTreeClick(preference)
|
|
|
|
}
|
2020-01-08 20:20:20 +01:00
|
|
|
}
|