Fix wear preferences, expand single preference by default

This commit is contained in:
Milos Kozak 2020-03-27 21:32:47 +01:00
parent 459ba955ad
commit c477649276
2 changed files with 33 additions and 30 deletions

View file

@ -50,7 +50,6 @@ 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.CryptoUtil
import info.nightscout.androidaps.utils.OKDialog.show
import info.nightscout.androidaps.utils.SafeParse
import info.nightscout.androidaps.utils.protection.PasswordCheck
@ -189,7 +188,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
addPreferencesFromResource(R.xml.pref_datachoices, rootKey)
addPreferencesFromResourceIfEnabled(maintenancePlugin, rootKey)
}
initSummary(preferenceScreen)
initSummary(preferenceScreen, pluginId != -1)
for (plugin in pluginStore.plugins) {
plugin.preprocessPreferences(this)
}
@ -287,22 +286,27 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
}
if (pref is Preference) {
if ((pref.getKey() != null) && (pref.getKey().contains("_password"))) {
if (sp.getString(pref.getKey(), "").startsWith("hmac:")) {
pref.setSummary("******")
if ((pref.key != null) && (pref.key.contains("_password"))) {
if (sp.getString(pref.key, "").startsWith("hmac:")) {
pref.summary = "******"
} else {
pref.setSummary(resourceHelper.gs(R.string.password_not_set))
pref.summary = resourceHelper.gs(R.string.password_not_set)
}
}
}
pref?.let { adjustUnitDependentPrefs(it) }
}
private fun initSummary(p: Preference) {
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) {
for (i in 0 until p.preferenceCount) {
initSummary(p.getPreference(i))
initSummary(p.getPreference(i), isSinglePreference)
}
} else {
updatePrefSummary(p)
@ -313,22 +317,24 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
// to hash password while it is saved and never have to show it, even hashed
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
if (preference != null) {
if (preference.key == resourceHelper.gs(R.string.key_master_password)) {
passwordCheck.setPassword(this.context!!, R.string.master_password, R.string.key_master_password)
return true;
}
if (preference.key == resourceHelper.gs(R.string.key_settings_password)) {
passwordCheck.setPassword(this.context!!, R.string.settings_password, R.string.key_settings_password)
return true;
}
if (preference.key == resourceHelper.gs(R.string.key_bolus_password)) {
passwordCheck.setPassword(this.context!!, R.string.bolus_password, R.string.key_bolus_password)
return true;
}
if (preference.key == resourceHelper.gs(R.string.key_application_password)) {
passwordCheck.setPassword(this.context!!, R.string.application_password, R.string.key_application_password)
return true;
context?.let { context ->
if (preference != null) {
if (preference.key == resourceHelper.gs(R.string.key_master_password)) {
passwordCheck.setPassword(context, R.string.master_password, R.string.key_master_password)
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
}
}
}
return super.onPreferenceTreeClick(preference)

View file

@ -15,8 +15,7 @@
<PreferenceCategory
android:dependency="wearcontrol"
android:summary="@string/wear_wizard_settings_summary"
android:title="@string/wear_wizard_settings"
app:initialExpandedChildrenCount="0">
android:title="@string/wear_wizard_settings">
<CheckBoxPreference
android:defaultValue="true"
@ -57,8 +56,7 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/wear_display_settings"
app:initialExpandedChildrenCount="0">
android:title="@string/wear_display_settings">
<SwitchPreference
android:defaultValue="false"
@ -86,8 +84,7 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/wear_general_settings"
app:initialExpandedChildrenCount="0">
android:title="@string/wear_general_settings">
<SwitchPreference
android:defaultValue="true"