2016-06-19 20:06:00 +02:00
|
|
|
package info.nightscout.androidaps;
|
|
|
|
|
|
|
|
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.MultiSelectListPreference;
|
|
|
|
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;
|
2017-09-20 13:54:05 +02:00
|
|
|
import android.text.TextUtils;
|
2017-01-26 12:07:25 +01:00
|
|
|
|
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;
|
2017-08-31 22:00:45 +02:00
|
|
|
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
|
2017-04-21 12:15:08 +02:00
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaR.BluetoothDevicePreference;
|
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
2017-02-17 13:18:36 +01:00
|
|
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
|
2017-01-08 14:21:29 +01:00
|
|
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
2017-09-13 00:35:03 +02:00
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
|
2017-04-30 21:08:00 +02:00
|
|
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
2017-04-21 12:15:08 +02:00
|
|
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
2017-06-30 11:56:36 +02:00
|
|
|
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
|
|
|
|
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
|
2017-07-07 15:08:21 +02:00
|
|
|
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
|
2017-02-18 18:13:13 +01:00
|
|
|
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
2017-05-06 15:18:19 +02:00
|
|
|
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
2016-07-06 22:50:25 +02:00
|
|
|
import info.nightscout.utils.LocaleHelper;
|
2017-07-04 00:16:35 +02:00
|
|
|
import info.nightscout.utils.OKDialog;
|
|
|
|
import info.nightscout.utils.SP;
|
2016-06-19 20:06:00 +02:00
|
|
|
|
|
|
|
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2016-07-07 17:17:54 +02:00
|
|
|
MyPreferenceFragment myPreferenceFragment;
|
|
|
|
|
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();
|
|
|
|
getFragmentManager().beginTransaction().replace(android.R.id.content, myPreferenceFragment).commit();
|
2016-06-19 20:06:00 +02:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
recreate();
|
2017-06-16 08:37:07 +02:00
|
|
|
MainApp.bus().post(new EventRefreshGui());
|
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
|
|
|
}
|
2017-07-04 00:16:35 +02:00
|
|
|
if (key.equals("openapsama_useautosens") && SP.getBoolean("openapsama_useautosens", false)) {
|
|
|
|
OKDialog.show(this, MainApp.sResources.getString(R.string.configbuilder_sensitivity), MainApp.sResources.getString(R.string.sensitivity_warning), null);
|
|
|
|
}
|
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
|
|
|
|
2017-04-14 15:33:39 +02:00
|
|
|
private static void updatePrefSummary(Preference pref) {
|
2016-07-07 17:17:54 +02:00
|
|
|
if (pref instanceof ListPreference || pref instanceof BluetoothDevicePreference) {
|
|
|
|
ListPreference listPref = (ListPreference) pref;
|
|
|
|
pref.setSummary(listPref.getEntry());
|
|
|
|
}
|
|
|
|
if (pref instanceof EditTextPreference) {
|
|
|
|
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("******");
|
2017-09-13 00:35:03 +02:00
|
|
|
} else if (pref.getKey().equals(MainApp.sResources.getString(R.string.key_danars_name))) {
|
|
|
|
pref.setSummary(SP.getString(R.string.key_danars_name,""));
|
2017-01-25 20:19:00 +01:00
|
|
|
} else if (editTextPref.getText() != null && !editTextPref.getText().equals("")) {
|
|
|
|
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
|
|
|
|
pref.setSummary(editTextPref.getText());
|
2016-07-07 17:17:54 +02:00
|
|
|
}
|
2017-09-20 13:54:05 +02:00
|
|
|
else if(pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().toString().trim())){
|
|
|
|
pref.setSummary(MainApp.sResources.getString(R.string.smscommunicator_allowednumbers_summary));
|
|
|
|
}
|
|
|
|
}
|
2016-07-07 17:17:54 +02:00
|
|
|
if (pref instanceof MultiSelectListPreference) {
|
|
|
|
EditTextPreference editTextPref = (EditTextPreference) pref;
|
|
|
|
pref.setSummary(editTextPref.getText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
PreferenceGroup pGrp = (PreferenceGroup) p;
|
|
|
|
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 {
|
|
|
|
@Override
|
|
|
|
public void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2017-02-23 20:00:33 +01:00
|
|
|
if (Config.ALLPREFERENCES) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_password);
|
|
|
|
}
|
2017-07-07 15:08:21 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_age);
|
2016-07-06 22:50:25 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_language);
|
2017-02-23 20:00:33 +01:00
|
|
|
if (Config.ALLPREFERENCES) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_quickwizard);
|
|
|
|
}
|
|
|
|
addPreferencesFromResource(R.xml.pref_careportal);
|
|
|
|
if (Config.ALLPREFERENCES) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_treatments);
|
|
|
|
}
|
2016-06-26 11:43:26 +02:00
|
|
|
if (Config.APS)
|
|
|
|
addPreferencesFromResource(R.xml.pref_closedmode);
|
2017-02-23 20:00:33 +01:00
|
|
|
if (Config.OPENAPSENABLED) {
|
2016-06-19 20:06:00 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_openapsma);
|
2017-02-23 20:00:33 +01:00
|
|
|
if (MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class) != null && MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class).isEnabled(PluginBase.APS))
|
|
|
|
addPreferencesFromResource(R.xml.pref_openapsama);
|
|
|
|
}
|
2017-07-07 15:08:21 +02:00
|
|
|
if (MainApp.getSpecificPlugin(SensitivityAAPSPlugin.class) != null && MainApp.getSpecificPlugin(SensitivityAAPSPlugin.class).isEnabled(PluginBase.SENSITIVITY)
|
|
|
|
|| MainApp.getSpecificPlugin(SensitivityWeightedAveragePlugin.class) != null && MainApp.getSpecificPlugin(SensitivityWeightedAveragePlugin.class).isEnabled(PluginBase.SENSITIVITY))
|
2017-06-30 11:56:36 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_absorption_aaps);
|
|
|
|
if (MainApp.getSpecificPlugin(SensitivityOref0Plugin.class) != null && MainApp.getSpecificPlugin(SensitivityOref0Plugin.class).isEnabled(PluginBase.SENSITIVITY))
|
|
|
|
addPreferencesFromResource(R.xml.pref_absorption_oref0);
|
2017-02-23 20:00:33 +01:00
|
|
|
if (Config.ALLPREFERENCES) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_profile);
|
|
|
|
}
|
2016-07-15 20:56:07 +02:00
|
|
|
if (Config.DANAR) {
|
2017-08-19 03:22:43 +02:00
|
|
|
DanaRPlugin danaRPlugin = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
|
|
|
DanaRKoreanPlugin danaRKoreanPlugin = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
|
|
|
|
DanaRv2Plugin danaRv2Plugin = MainApp.getSpecificPlugin(DanaRv2Plugin.class);
|
2017-09-13 00:35:03 +02:00
|
|
|
DanaRSPlugin danaRSPlugin = MainApp.getSpecificPlugin(DanaRSPlugin.class);
|
2016-12-03 17:42:08 +01:00
|
|
|
if (danaRPlugin.isEnabled(PluginBase.PUMP) || danaRKoreanPlugin.isEnabled(PluginBase.PUMP)) {
|
2016-09-10 15:37:37 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_danar);
|
2017-01-29 19:22:49 +01:00
|
|
|
}
|
2017-05-11 18:54:50 +02:00
|
|
|
if (danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PUMP)) {
|
2017-04-30 21:08:00 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_danarv2);
|
|
|
|
}
|
2017-09-13 00:35:03 +02:00
|
|
|
if (danaRSPlugin != null && danaRSPlugin.isEnabled(PluginBase.PUMP)) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_danars);
|
|
|
|
}
|
2017-05-11 18:54:50 +02:00
|
|
|
if (danaRPlugin.isEnabled(PluginBase.PROFILE) || danaRKoreanPlugin.isEnabled(PluginBase.PROFILE) || danaRv2Plugin != null && danaRv2Plugin.isEnabled(PluginBase.PROFILE)) {
|
2016-07-15 20:56:07 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_danarprofile);
|
|
|
|
}
|
|
|
|
}
|
2017-08-19 03:22:43 +02:00
|
|
|
VirtualPumpPlugin virtualPumpPlugin = MainApp.getSpecificPlugin(VirtualPumpPlugin.class);
|
2017-02-14 15:41:30 +01:00
|
|
|
if (virtualPumpPlugin != null && virtualPumpPlugin.isEnabled(PluginBase.PUMP)) {
|
2017-04-14 15:33:39 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_virtualpump);
|
2017-02-14 15:41:30 +01:00
|
|
|
}
|
2017-08-19 03:22:43 +02:00
|
|
|
InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin = MainApp.getSpecificPlugin(InsulinOrefFreePeakPlugin.class);
|
2017-09-13 00:35:03 +02:00
|
|
|
if (insulinOrefFreePeakPlugin.isEnabled(PluginBase.INSULIN)) {
|
2017-08-14 13:20:09 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_insulinoreffreepeak);
|
|
|
|
}
|
|
|
|
|
2017-08-19 03:22:43 +02:00
|
|
|
NSClientInternalPlugin nsClientInternalPlugin = MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
|
2017-02-17 13:18:36 +01:00
|
|
|
if (nsClientInternalPlugin != null && nsClientInternalPlugin.isEnabled(PluginBase.GENERAL)) {
|
2017-04-14 15:33:39 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_nsclientinternal);
|
2017-02-17 13:18:36 +01:00
|
|
|
}
|
2016-07-14 23:29:21 +02:00
|
|
|
if (Config.SMSCOMMUNICATORENABLED)
|
|
|
|
addPreferencesFromResource(R.xml.pref_smscommunicator);
|
2017-02-23 20:00:33 +01:00
|
|
|
if (Config.ALLPREFERENCES) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_others);
|
|
|
|
}
|
2017-06-20 19:52:46 +02:00
|
|
|
addPreferencesFromResource(R.xml.pref_advanced);
|
2017-02-18 18:13:13 +01:00
|
|
|
|
2017-02-23 20:00:33 +01:00
|
|
|
if (Config.WEAR) {
|
2017-08-19 03:22:43 +02:00
|
|
|
WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class);
|
2017-02-23 20:00:33 +01:00
|
|
|
if (wearPlugin != null && wearPlugin.isEnabled(PluginBase.GENERAL)) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_wear);
|
|
|
|
}
|
2017-02-18 18:13:13 +01:00
|
|
|
}
|
2017-04-14 15:33:39 +02:00
|
|
|
|
2017-08-19 03:22:43 +02:00
|
|
|
StatuslinePlugin statuslinePlugin = MainApp.getSpecificPlugin(StatuslinePlugin.class);
|
2017-05-06 15:18:19 +02:00
|
|
|
if (statuslinePlugin != null && statuslinePlugin.isEnabled(PluginBase.GENERAL)) {
|
|
|
|
addPreferencesFromResource(R.xml.pref_xdripstatus);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|