2018-07-29 00:08:28 +02:00
|
|
|
package info.nightscout.androidaps.activities;
|
2016-06-19 20:06:00 +02:00
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
2016-07-07 17:17:54 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.EditTextPreference;
|
|
|
|
import android.preference.ListPreference;
|
|
|
|
import android.preference.Preference;
|
2016-06-19 20:06:00 +02:00
|
|
|
import android.preference.PreferenceActivity;
|
|
|
|
import android.preference.PreferenceFragment;
|
2016-07-07 17:17:54 +02:00
|
|
|
import android.preference.PreferenceGroup;
|
2016-06-19 20:06:00 +02:00
|
|
|
import android.preference.PreferenceManager;
|
2018-06-17 22:41:34 +02:00
|
|
|
import android.preference.PreferenceScreen;
|
2017-09-20 13:54:05 +02:00
|
|
|
import android.text.TextUtils;
|
2017-01-26 12:07:25 +01:00
|
|
|
|
2018-07-29 00:08:28 +02:00
|
|
|
import info.nightscout.androidaps.Config;
|
|
|
|
import info.nightscout.androidaps.MainApp;
|
|
|
|
import info.nightscout.androidaps.R;
|
2016-06-19 20:06:00 +02:00
|
|
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
2016-07-06 22:50:25 +02:00
|
|
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
2016-07-15 20:56:07 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
2018-03-31 00:36:03 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginType;
|
2019-03-02 21:24:53 +01:00
|
|
|
import info.nightscout.androidaps.plugins.PumpMedtronic.MedtronicPumpPlugin;
|
2019-02-28 23:16:50 +01:00
|
|
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
2019-03-02 21:24:53 +01:00
|
|
|
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
|
2019-02-26 20:38:27 +01:00
|
|
|
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
|
|
|
|
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
2019-02-28 23:16:50 +01:00
|
|
|
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin;
|
|
|
|
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
|
|
|
|
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin;
|
2019-02-26 20:38:27 +01:00
|
|
|
import info.nightscout.androidaps.utils.LocaleHelper;
|
|
|
|
import info.nightscout.androidaps.utils.OKDialog;
|
|
|
|
import info.nightscout.androidaps.utils.SP;
|
2016-06-19 20:06:00 +02:00
|
|
|
|
|
|
|
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2016-07-07 17:17:54 +02:00
|
|
|
MyPreferenceFragment myPreferenceFragment;
|
|
|
|
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2016-06-19 20:06:00 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2016-07-07 17:17:54 +02:00
|
|
|
myPreferenceFragment = new MyPreferenceFragment();
|
2017-11-08 10:20:49 +01:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("id", getIntent().getIntExtra("id", -1));
|
|
|
|
myPreferenceFragment.setArguments(args);
|
2016-07-07 17:17:54 +02:00
|
|
|
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
|
2016-06-19 20:06:00 +02:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2016-06-19 20:06:00 +02:00
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
2017-02-17 16:16:20 +01:00
|
|
|
MainApp.bus().post(new EventPreferenceChange(key));
|
2016-07-06 22:50:25 +02:00
|
|
|
if (key.equals("language")) {
|
2016-07-07 17:17:54 +02:00
|
|
|
String lang = sharedPreferences.getString("language", "en");
|
2016-07-06 22:50:25 +02:00
|
|
|
LocaleHelper.setLocale(getApplicationContext(), lang);
|
2017-12-31 16:44:13 +01:00
|
|
|
MainApp.bus().post(new EventRefreshGui(true));
|
2019-03-02 21:24:53 +01:00
|
|
|
// recreate() does not update language so better close settings
|
2017-12-31 16:44:13 +01:00
|
|
|
finish();
|
2016-07-06 22:50:25 +02:00
|
|
|
}
|
2017-01-21 23:48:05 +01:00
|
|
|
if (key.equals("short_tabtitles")) {
|
2017-06-16 08:37:07 +02:00
|
|
|
MainApp.bus().post(new EventRefreshGui());
|
2017-01-21 23:48:05 +01:00
|
|
|
}
|
2019-03-02 21:24:53 +01:00
|
|
|
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens))
|
|
|
|
&& SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
|
|
|
|
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity),
|
|
|
|
MainApp.gs(R.string.sensitivity_warning), null);
|
2017-07-04 00:16:35 +02:00
|
|
|
}
|
2016-07-07 17:17:54 +02:00
|
|
|
updatePrefSummary(myPreferenceFragment.getPreference(key));
|
2017-02-09 10:41:02 +01:00
|
|
|
}
|
2016-07-07 17:17:54 +02:00
|
|
|
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2017-04-14 15:33:39 +02:00
|
|
|
private static void updatePrefSummary(Preference pref) {
|
2017-11-08 18:02:13 +01:00
|
|
|
if (pref instanceof ListPreference) {
|
2019-03-02 21:24:53 +01:00
|
|
|
ListPreference listPref = (ListPreference)pref;
|
2016-07-07 17:17:54 +02:00
|
|
|
pref.setSummary(listPref.getEntry());
|
|
|
|
}
|
|
|
|
if (pref instanceof EditTextPreference) {
|
2019-03-02 21:24:53 +01:00
|
|
|
EditTextPreference editTextPref = (EditTextPreference)pref;
|
2017-04-14 15:33:39 +02:00
|
|
|
if (pref.getKey().contains("password") || pref.getKey().contains("secret")) {
|
2016-07-07 17:17:54 +02:00
|
|
|
pref.setSummary("******");
|
2018-04-21 20:46:55 +02:00
|
|
|
} else if (pref.getKey().equals(MainApp.gs(R.string.key_danars_name))) {
|
2017-11-01 20:43:59 +01:00
|
|
|
pref.setSummary(SP.getString(R.string.key_danars_name, ""));
|
2018-09-11 20:08:59 +02:00
|
|
|
} else if (editTextPref.getText() != null) {
|
2019-03-02 21:24:53 +01:00
|
|
|
((EditTextPreference)pref).setDialogMessage(editTextPref.getDialogMessage());
|
2017-01-25 20:19:00 +01:00
|
|
|
pref.setSummary(editTextPref.getText());
|
2019-03-02 21:24:53 +01:00
|
|
|
} else if (pref.getKey().contains("smscommunicator_allowednumbers")
|
|
|
|
&& TextUtils.isEmpty(editTextPref.getText().trim())) {
|
2018-04-21 20:46:55 +02:00
|
|
|
pref.setSummary(MainApp.gs(R.string.smscommunicator_allowednumbers_summary));
|
2017-09-20 13:54:05 +02:00
|
|
|
}
|
2017-11-01 20:43:59 +01:00
|
|
|
}
|
2016-07-07 17:17:54 +02:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2017-02-22 20:29:41 +01:00
|
|
|
public static void initSummary(Preference p) {
|
2016-07-07 17:17:54 +02:00
|
|
|
if (p instanceof PreferenceGroup) {
|
2019-03-02 21:24:53 +01:00
|
|
|
PreferenceGroup pGrp = (PreferenceGroup)p;
|
2016-07-07 17:17:54 +02:00
|
|
|
for (int i = 0; i < pGrp.getPreferenceCount(); i++) {
|
|
|
|
initSummary(pGrp.getPreference(i));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
updatePrefSummary(p);
|
|
|
|
}
|
2016-06-19 20:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class MyPreferenceFragment extends PreferenceFragment {
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2017-11-08 10:20:49 +01:00
|
|
|
private Integer id;
|
2017-11-01 20:43:59 +01:00
|
|
|
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2017-11-08 10:20:49 +01:00
|
|
|
@Override
|
|
|
|
public void setArguments(Bundle args) {
|
|
|
|
super.setArguments(args);
|
|
|
|
id = args.getInt("id");
|
2017-11-01 20:43:59 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2018-03-31 00:36:03 +02:00
|
|
|
void addPreferencesFromResourceIfEnabled(PluginBase p, PluginType type) {
|
2017-11-01 20:43:59 +01:00
|
|
|
if (p.isEnabled(type) && p.getPreferencesId() != -1)
|
|
|
|
addPreferencesFromResource(p.getPreferencesId());
|
|
|
|
}
|
|
|
|
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2016-06-19 20:06:00 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2017-11-01 20:43:59 +01:00
|
|
|
|
2017-11-08 18:02:13 +01:00
|
|
|
if (savedInstanceState != null && savedInstanceState.containsKey("id")) {
|
|
|
|
id = savedInstanceState.getInt("id");
|
|
|
|
}
|
|
|
|
|
2017-11-01 20:43:59 +01:00
|
|
|
if (id != -1) {
|
|
|
|
addPreferencesFromResource(id);
|
|
|
|
} else {
|
2018-02-15 21:00:09 +01:00
|
|
|
|
2018-08-07 21:45:35 +02:00
|
|
|
if (!Config.NSCLIENT) {
|
2017-11-01 20:43:59 +01:00
|
|
|
addPreferencesFromResource(R.xml.pref_password);
|
2017-01-29 19:22:49 +01:00
|
|
|
}
|
2017-11-01 20:43:59 +01:00
|
|
|
addPreferencesFromResource(R.xml.pref_age);
|
|
|
|
addPreferencesFromResource(R.xml.pref_language);
|
|
|
|
|
2018-04-21 21:31:42 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_overview);
|
|
|
|
|
2018-03-31 00:36:03 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(SourceDexcomG5Plugin.getPlugin(), PluginType.BGSOURCE);
|
|
|
|
addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginType.GENERAL);
|
|
|
|
addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginType.CONSTRAINTS);
|
2017-11-01 20:43:59 +01:00
|
|
|
if (Config.APS) {
|
2018-03-31 00:36:03 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginType.LOOP);
|
|
|
|
addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginType.APS);
|
|
|
|
addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginType.APS);
|
|
|
|
addPreferencesFromResourceIfEnabled(OpenAPSSMBPlugin.getPlugin(), PluginType.APS);
|
2017-04-30 21:08:00 +02:00
|
|
|
}
|
2017-11-01 20:43:59 +01:00
|
|
|
|
2018-03-31 00:36:03 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY);
|
2019-03-02 21:24:53 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(),
|
|
|
|
PluginType.SENSITIVITY);
|
2018-03-31 00:36:03 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginType.SENSITIVITY);
|
2018-06-19 20:41:40 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(SensitivityOref1Plugin.getPlugin(), PluginType.SENSITIVITY);
|
2017-11-01 20:43:59 +01:00
|
|
|
|
2018-08-07 21:07:43 +02:00
|
|
|
if (Config.PUMPDRIVERS) {
|
2018-03-31 00:36:03 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(DanaRPlugin.getPlugin(), PluginType.PUMP);
|
|
|
|
addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginType.PUMP);
|
|
|
|
addPreferencesFromResourceIfEnabled(DanaRv2Plugin.getPlugin(), PluginType.PUMP);
|
|
|
|
addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginType.PUMP);
|
2019-02-25 19:33:01 +01:00
|
|
|
addPreferencesFromResourceIfEnabled(LocalInsightPlugin.getPlugin(), PluginType.PUMP);
|
2018-04-24 00:11:52 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(ComboPlugin.getPlugin(), PluginType.PUMP);
|
2018-05-07 13:05:53 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(MedtronicPumpPlugin.getPlugin(), PluginType.PUMP);
|
2018-03-31 00:36:03 +02:00
|
|
|
|
|
|
|
if (DanaRPlugin.getPlugin().isEnabled(PluginType.PROFILE)
|
2019-03-02 21:24:53 +01:00
|
|
|
|| DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PROFILE)
|
|
|
|
|| DanaRv2Plugin.getPlugin().isEnabled(PluginType.PROFILE)
|
|
|
|
|| DanaRSPlugin.getPlugin().isEnabled(PluginType.PROFILE)) {
|
2017-11-01 20:43:59 +01:00
|
|
|
addPreferencesFromResource(R.xml.pref_danarprofile);
|
|
|
|
}
|
2016-07-15 20:56:07 +02:00
|
|
|
}
|
2017-08-14 13:20:09 +02:00
|
|
|
|
2018-08-07 21:45:35 +02:00
|
|
|
if (!Config.NSCLIENT) {
|
2018-03-31 00:36:03 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginType.PUMP);
|
2017-11-29 16:07:26 +01:00
|
|
|
}
|
2017-02-18 18:13:13 +01:00
|
|
|
|
2018-03-31 00:36:03 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginType.INSULIN);
|
2017-11-01 20:43:59 +01:00
|
|
|
|
2018-03-31 00:36:03 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(NSClientPlugin.getPlugin(), PluginType.GENERAL);
|
|
|
|
addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginType.GENERAL);
|
2017-11-01 20:43:59 +01:00
|
|
|
|
2018-09-11 20:08:59 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_others);
|
2018-04-24 00:11:52 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_datachoices);
|
2017-04-14 15:33:39 +02:00
|
|
|
|
2018-03-31 00:36:03 +02:00
|
|
|
addPreferencesFromResourceIfEnabled(WearPlugin.getPlugin(), PluginType.GENERAL);
|
|
|
|
addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), PluginType.GENERAL);
|
2017-05-06 15:18:19 +02:00
|
|
|
}
|
|
|
|
|
2018-08-19 14:37:42 +02:00
|
|
|
if (Config.NSCLIENT) {
|
2018-06-17 22:41:34 +02:00
|
|
|
PreferenceScreen scrnAdvancedSettings = (PreferenceScreen)findPreference(getString(R.string.key_advancedsettings));
|
|
|
|
if (scrnAdvancedSettings != null) {
|
2019-03-02 21:24:53 +01:00
|
|
|
scrnAdvancedSettings
|
|
|
|
.removePreference(getPreference(getString(R.string.key_statuslights_res_warning)));
|
|
|
|
scrnAdvancedSettings
|
|
|
|
.removePreference(getPreference(getString(R.string.key_statuslights_res_critical)));
|
|
|
|
scrnAdvancedSettings
|
|
|
|
.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning)));
|
|
|
|
scrnAdvancedSettings
|
|
|
|
.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical)));
|
2018-06-17 22:41:34 +02:00
|
|
|
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-14 15:33:39 +02:00
|
|
|
initSummary(getPreferenceScreen());
|
2016-07-07 17:17:54 +02:00
|
|
|
}
|
2016-06-19 20:06:00 +02:00
|
|
|
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2017-11-08 18:02:13 +01:00
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
outState.putInt("id", id);
|
|
|
|
}
|
|
|
|
|
2019-03-02 21:24:53 +01:00
|
|
|
|
2017-04-14 15:33:39 +02:00
|
|
|
public Preference getPreference(String key) {
|
2016-07-07 17:17:54 +02:00
|
|
|
return findPreference(key);
|
2016-06-19 20:06:00 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-07 01:02:08 +01:00
|
|
|
}
|