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

View file

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