From e357c7fd1bdf16557a189177c0d2fbbb9f88d8f3 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Tue, 8 May 2018 15:14:36 +0300 Subject: [PATCH 01/15] adding pump selection --- .../startupwizard/SWDefinition.java | 36 +++++++++++++++++++ .../startupwizard/SWRadioButton.java | 9 ++++- app/src/main/res/values/arrays.xml | 11 ++++++ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index 6e4cd42f2f..a7c140e3fe 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -14,9 +14,12 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.startupwizard.events.EventSWUpdate; import info.nightscout.utils.LocaleHelper; import info.nightscout.utils.SP; +//Needed for pump validation public class SWDefinition { private static Logger log = LoggerFactory.getLogger(SWDefinition.class); @@ -77,6 +80,39 @@ public class SWDefinition { .visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL))) .validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) ) + .add(new SWScreen(R.string.configbuilder_pump) + .skippable(true) + + .add(new SWPlugin() + .option(PluginType.PUMP) + .label(R.string.configbuilder_pump) + .comment(R.string.configbuilder_pump)) + .validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null) + ) + .add(new SWScreen(R.string.setupwizard_pump_test) + .skippable(true) + // Adding DanaR specific fields + .add(DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)?new SWString() + .preferenceId(R.string.key_danar_bt_name) + .label(R.string.danar_bt_name_title) + .comment(R.string.danar_bt_name_title) : new SWItem(SWItem.Type.STRING) + ) + .add(DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)?new SWString() + .preferenceId(R.string.key_danar_password) + .label(R.string.danar_password_title) + .comment(R.string.danar_password_title): new SWItem(SWItem.Type.STRING) + ) + // Virtual pump + .add(VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP)? + new SWRadioButton() + .option(R.array.trueFalseArray, R.array.trueFalseValues) + .preferenceId(R.string.key_virtualpump_uploadstatus) + .label(R.string.virtualpump_uploadstatus_title) + .comment(R.string.virtualpump_uploadstatus_title): new SWItem(SWItem.Type.STRING) + ) + .validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null) + ) + .add(new SWScreen(R.string.patientage) .skippable(false) .add(new SWRadioButton() diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java index 7cdbee3d71..9b91e289a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java @@ -10,6 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.utils.SP; public class SWRadioButton extends SWItem { @@ -41,7 +42,13 @@ public class SWRadioButton extends SWItem { public void generateDialog(View view, LinearLayout layout) { Context context = view.getContext(); // Get if there is already value in SP - String previousValue = SP.getString(preferenceId, "none"); + String previousValue = "none"; + if(preferenceId == R.string.key_virtualpump_uploadstatus) { + Boolean booleanValue = SP.getBoolean(preferenceId, false); + previousValue = booleanValue.toString(); + } else { + previousValue = SP.getString(preferenceId, "none"); + } radioGroup = new RadioGroup(context); radioGroup.clearCheck(); radioGroup.setOrientation(LinearLayout.VERTICAL); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 12492d4a50..cacea337fc 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -105,4 +105,15 @@ @string/no @string/yes + + + @string/yes + @string/no + + + + true + false + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index af30252d7c..b63c14cee2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -523,6 +523,7 @@ resistantadult Please select patient age to setup safety limits I_understand + virtualpump_uploadstatus Glimp Device does not appear to support battery optimization whitelisting! Please Allow Permission @@ -1018,6 +1019,7 @@ Skip FINISH Select your language + Test pump connection language openapsama_min_5m_carbimpact Asked: %.2fU Delivered: %.2fU Error code: %d From 85d4ef4419bda7a20f18009bb9405c1c3f88a6b1 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Tue, 8 May 2018 17:09:37 +0300 Subject: [PATCH 02/15] trying pump followup screen --- .../startupwizard/SWDefinition.java | 52 +++++++++++-------- .../startupwizard/SWRadioButton.java | 35 ++++++++++++- 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index a7c140e3fe..bdebdeca8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -9,11 +9,11 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventConfigBuilderChange; -import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; +import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.startupwizard.events.EventSWUpdate; @@ -48,7 +48,7 @@ public class SWDefinition { add(new SWScreen(R.string.language) .skippable(false) .add(new SWRadioButton() - .option(R.array.languagesArray, R.array.languagesValues) + .option("", R.array.languagesArray, R.array.languagesValues) .preferenceId(R.string.key_language).label(R.string.language) .comment(R.string.setupwizard_language_prompt)) .validator(() -> { @@ -90,33 +90,41 @@ public class SWDefinition { .validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null) ) .add(new SWScreen(R.string.setupwizard_pump_test) - .skippable(true) + .skippable(false) // Adding DanaR specific fields - .add(DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)?new SWString() - .preferenceId(R.string.key_danar_bt_name) - .label(R.string.danar_bt_name_title) - .comment(R.string.danar_bt_name_title) : new SWItem(SWItem.Type.STRING) - ) - .add(DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)?new SWString() - .preferenceId(R.string.key_danar_password) - .label(R.string.danar_password_title) - .comment(R.string.danar_password_title): new SWItem(SWItem.Type.STRING) - ) + .add(DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)?new SWString() + .preferenceId(R.string.key_danar_bt_name) + .label(R.string.danar_bt_name_title) + .comment(R.string.danar_bt_name_title) : new SWItem(SWItem.Type.STRING) + ) + .add(DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)?new SWString() + .preferenceId(R.string.key_danar_password) + .label(R.string.danar_password_title) + .comment(R.string.danar_password_title): new SWItem(SWItem.Type.STRING) + ) // Virtual pump - .add(VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP)? - new SWRadioButton() - .option(R.array.trueFalseArray, R.array.trueFalseValues) - .preferenceId(R.string.key_virtualpump_uploadstatus) - .label(R.string.virtualpump_uploadstatus_title) - .comment(R.string.virtualpump_uploadstatus_title): new SWItem(SWItem.Type.STRING) - ) - .validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null) + .add(VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP)? + // TODO: Replace with checkbox + new SWRadioButton() + .option(MainApp.instance().getApplicationContext().getResources().getString(R.string.virtualpump_uploadstatus_title), R.array.trueFalseArray, R.array.trueFalseValues) + .preferenceId(R.string.key_virtualpump_uploadstatus) + .label(R.string.virtualpump_uploadstatus_title) + .comment(R.string.virtualpump_uploadstatus_title): new SWItem(SWItem.Type.STRING) + ) + // Combo pump + .add(ComboPlugin.getPlugin().isEnabled(PluginType.PUMP)? + new SWString() + .preferenceId(R.string.combo_pump_alerts) + .label(R.string.combo_pump_state_label) + .comment(R.string.combo_pump_state_label): new SWItem(SWItem.Type.STRING) + ) + .validator(() -> ConfigBuilderPlugin.getActivePump() != null) ) .add(new SWScreen(R.string.patientage) .skippable(false) .add(new SWRadioButton() - .option(R.array.ageArray, R.array.ageValues) + .option("", R.array.ageArray, R.array.ageValues) .preferenceId(R.string.key_age) .label(R.string.patientage) .comment(R.string.patientage_summary)) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java index 9b91e289a1..c51f215c68 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java @@ -5,12 +5,22 @@ import android.view.View; import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.RadioGroup; +import android.widget.TextView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.utils.SP; public class SWRadioButton extends SWItem { @@ -18,13 +28,15 @@ public class SWRadioButton extends SWItem { int labelsArray; int valuesArray; + String groupLabel = ""; private RadioGroup radioGroup; public SWRadioButton() { super(Type.RADIOBUTTON); } - public SWRadioButton option(int labels, int values) { + public SWRadioButton option(String groupLabel, int labels, int values) { + this.groupLabel = groupLabel; this.labelsArray = labels; this.valuesArray = values; return this; @@ -49,11 +61,30 @@ public class SWRadioButton extends SWItem { } else { previousValue = SP.getString(preferenceId, "none"); } + if(!groupLabel.equals("")) { + TextView groupName = new TextView(context); + groupName.setText(groupLabel); + layout.addView(groupName); + } radioGroup = new RadioGroup(context); radioGroup.clearCheck(); radioGroup.setOrientation(LinearLayout.VERTICAL); radioGroup.setVisibility(View.VISIBLE); - + ArrayList pluginsInCategory; + pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.PUMP); + PluginBase found = null; + for (PluginBase p : pluginsInCategory) { + if (p.isEnabled(PluginType.PUMP) && found == null) { + found = p; + } else if (p.isEnabled(PluginType.PUMP)) { + // set others disabled + p.setPluginEnabled(PluginType.PUMP, false); + } + } + log.debug("Pump selected: DanaR:"+DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)); + log.debug("Pump selected: Virtual:"+VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP)); + log.debug("Pump selected: Combo:"+ ComboPlugin.getPlugin().isEnabled(PluginType.PUMP)); + log.debug("Pump selected: "+ found.getNameShort()); for (int i = 0; i < labels().length; i++) { RadioButton rdbtn = new RadioButton(context); rdbtn.setId(View.generateViewId()); From d5a3177c3583aeed97be254ed845f9c6e681cfea Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 9 May 2018 11:06:52 +0300 Subject: [PATCH 03/15] trying pump followup screen -NOT WORKING --- .../androidaps/startupwizard/SWDefinition.java | 9 +++++++++ .../startupwizard/SetupWizardActivity.java | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index bdebdeca8a..bcb31bcba4 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -91,6 +91,15 @@ public class SWDefinition { ) .add(new SWScreen(R.string.setupwizard_pump_test) .skippable(false) + // add refresh button + .add(new SWButton() + .text(R.string.combo_refresh) + .action(() -> { + log.debug("Tryng to get the current pump selected: "+ConfigBuilderPlugin.getActivePump()); + MainApp.bus().post(new EventConfigBuilderChange()); + MainApp.bus().post(new EventSWUpdate(true)); + }) + .visibility(() -> true)) // Adding DanaR specific fields .add(DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)?new SWString() .preferenceId(R.string.key_danar_bt_name) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java index 3da44618ab..a124635cc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java @@ -30,14 +30,14 @@ public class SetupWizardActivity extends AppCompatActivity { SWDefinition swDefinition = SWDefinition.getInstance(); List screens = swDefinition.getScreens(); private int currentWizardPage = 0; - public static final String INTENT_MESSAGE = "WIZZARDPAGE"; + public static final String INTENT_MESSAGE = "WIZZARDPAGE"; + public static final String RESTART = "RESTART"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LocaleHelper.onCreate(this, "en"); setContentView(R.layout.activity_setupwizard); - Intent intent = getIntent(); currentWizardPage = intent.getIntExtra(SetupWizardActivity.INTENT_MESSAGE, 0); if (screens.size() > 0 && currentWizardPage < screens.size()) { @@ -61,6 +61,14 @@ public class SetupWizardActivity extends AppCompatActivity { @Override protected void onResume() { + + Intent intent = new Intent(this, SetupWizardActivity.class); + intent.putExtra(INTENT_MESSAGE, 0); + if(intent.getBooleanExtra(RESTART, false)) { + intent.putExtra(RESTART, false); + this.finish(); + startActivity(intent); + } super.onResume(); MainApp.bus().register(this); } @@ -110,6 +118,9 @@ public class SetupWizardActivity extends AppCompatActivity { this.finish(); Intent intent = new Intent(this, SetupWizardActivity.class); intent.putExtra(INTENT_MESSAGE, currentWizardPage + 1); + +// screens = SWDefinition.getInstance().getScreens(); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } @@ -120,6 +131,7 @@ public class SetupWizardActivity extends AppCompatActivity { intent.putExtra(INTENT_MESSAGE, currentWizardPage - 1); else intent.putExtra(INTENT_MESSAGE, 0); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } From 1f2f2f54fc9bd1a2cd1e2d21338de79099f347a1 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 9 May 2018 14:15:53 +0300 Subject: [PATCH 04/15] added SWCheckbox item --- .../androidaps/startupwizard/SWCheckbox.java | 59 +++++++++++++++++++ .../startupwizard/SWDefinition.java | 5 +- .../startupwizard/SWRadioButton.java | 4 -- 3 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/startupwizard/SWCheckbox.java diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWCheckbox.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWCheckbox.java new file mode 100644 index 0000000000..238c4ad4c7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWCheckbox.java @@ -0,0 +1,59 @@ +package info.nightscout.androidaps.startupwizard; + +import android.content.Context; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.LinearLayout; +import android.widget.CheckBox; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.utils.SP; + +/** + * Created by Rumen Georgiev on 5/9/2018. + */ + +public class SWCheckbox extends SWItem { + private static Logger log = LoggerFactory.getLogger(SWCheckbox.class); + + int labelsArray; + int valuesArray; + String label = ""; + int preferenceID; + private CheckBox checkBox; + + public SWCheckbox() { + super(Type.CHECKBOX); + } + + public SWCheckbox option(String label, int preferenceID) { + this.label = label; + this.preferenceID = preferenceID; + return this; + } + + @Override + public void generateDialog(View view, LinearLayout layout) { + Context context = view.getContext(); + // Get if there is already value in SP + Boolean previousValue; + previousValue = SP.getBoolean(preferenceId, false); + checkBox = new CheckBox(context); + checkBox.setText(label); + checkBox.setChecked(previousValue); + checkBox.setVisibility(View.VISIBLE); + checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + save(checkBox.isChecked()); + } + }); + layout.addView(checkBox); + super.generateDialog(view, layout); + } + public void save(boolean value){ + SP.putBoolean(preferenceID, value); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index bcb31bcba4..b2299326f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -113,9 +113,8 @@ public class SWDefinition { ) // Virtual pump .add(VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP)? - // TODO: Replace with checkbox - new SWRadioButton() - .option(MainApp.instance().getApplicationContext().getResources().getString(R.string.virtualpump_uploadstatus_title), R.array.trueFalseArray, R.array.trueFalseValues) + new SWCheckbox() + .option(MainApp.instance().getApplicationContext().getResources().getString(R.string.virtualpump_uploadstatus_title), R.string.key_virtualpump_uploadstatus) .preferenceId(R.string.key_virtualpump_uploadstatus) .label(R.string.virtualpump_uploadstatus_title) .comment(R.string.virtualpump_uploadstatus_title): new SWItem(SWItem.Type.STRING) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java index c51f215c68..db54de78dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java @@ -81,10 +81,6 @@ public class SWRadioButton extends SWItem { p.setPluginEnabled(PluginType.PUMP, false); } } - log.debug("Pump selected: DanaR:"+DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)); - log.debug("Pump selected: Virtual:"+VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP)); - log.debug("Pump selected: Combo:"+ ComboPlugin.getPlugin().isEnabled(PluginType.PUMP)); - log.debug("Pump selected: "+ found.getNameShort()); for (int i = 0; i < labels().length; i++) { RadioButton rdbtn = new RadioButton(context); rdbtn.setId(View.generateViewId()); From 0e8f0669c5667c5974ad662fceff3d5655fa55d3 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 9 May 2018 14:48:35 +0300 Subject: [PATCH 05/15] Update SWDefinition.java --- .../startupwizard/SWDefinition.java | 114 +++++++----------- 1 file changed, 45 insertions(+), 69 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index b2299326f4..256b7db870 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -1,5 +1,8 @@ package info.nightscout.androidaps.startupwizard; +import android.content.Context; +import android.content.Intent; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,32 +10,31 @@ import java.util.ArrayList; import java.util.List; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.PreferencesActivity; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventConfigBuilderChange; +import info.nightscout.androidaps.events.EventRefreshGui; +import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; -import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.startupwizard.events.EventSWUpdate; import info.nightscout.utils.LocaleHelper; +import info.nightscout.utils.PasswordProtection; import info.nightscout.utils.SP; -//Needed for pump validation public class SWDefinition { private static Logger log = LoggerFactory.getLogger(SWDefinition.class); - private static SWDefinition swDefinition = null; - - public static SWDefinition getInstance() { - if (swDefinition == null) - swDefinition = new SWDefinition(); - return swDefinition; - } + private Context context; static List screens = new ArrayList<>(); + public void setContext(Context context) { + this.context = context; + } + public static List getScreens() { return screens; } @@ -45,10 +47,14 @@ public class SWDefinition { SWDefinition() { // List all the screens here - add(new SWScreen(R.string.language) + add(new SWScreen(R.string.nav_setupwizard) + .add(new SWInfotext() + .label(R.string.welcometosetupwizard) ) + ) + .add(new SWScreen(R.string.language) .skippable(false) .add(new SWRadioButton() - .option("", R.array.languagesArray, R.array.languagesValues) + .option(R.array.languagesArray, R.array.languagesValues) .preferenceId(R.string.key_language).label(R.string.language) .comment(R.string.setupwizard_language_prompt)) .validator(() -> { @@ -80,59 +86,10 @@ public class SWDefinition { .visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL))) .validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) ) - .add(new SWScreen(R.string.configbuilder_pump) - .skippable(true) - - .add(new SWPlugin() - .option(PluginType.PUMP) - .label(R.string.configbuilder_pump) - .comment(R.string.configbuilder_pump)) - .validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null) - ) - .add(new SWScreen(R.string.setupwizard_pump_test) - .skippable(false) - // add refresh button - .add(new SWButton() - .text(R.string.combo_refresh) - .action(() -> { - log.debug("Tryng to get the current pump selected: "+ConfigBuilderPlugin.getActivePump()); - MainApp.bus().post(new EventConfigBuilderChange()); - MainApp.bus().post(new EventSWUpdate(true)); - }) - .visibility(() -> true)) - // Adding DanaR specific fields - .add(DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)?new SWString() - .preferenceId(R.string.key_danar_bt_name) - .label(R.string.danar_bt_name_title) - .comment(R.string.danar_bt_name_title) : new SWItem(SWItem.Type.STRING) - ) - .add(DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP)?new SWString() - .preferenceId(R.string.key_danar_password) - .label(R.string.danar_password_title) - .comment(R.string.danar_password_title): new SWItem(SWItem.Type.STRING) - ) - // Virtual pump - .add(VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP)? - new SWCheckbox() - .option(MainApp.instance().getApplicationContext().getResources().getString(R.string.virtualpump_uploadstatus_title), R.string.key_virtualpump_uploadstatus) - .preferenceId(R.string.key_virtualpump_uploadstatus) - .label(R.string.virtualpump_uploadstatus_title) - .comment(R.string.virtualpump_uploadstatus_title): new SWItem(SWItem.Type.STRING) - ) - // Combo pump - .add(ComboPlugin.getPlugin().isEnabled(PluginType.PUMP)? - new SWString() - .preferenceId(R.string.combo_pump_alerts) - .label(R.string.combo_pump_state_label) - .comment(R.string.combo_pump_state_label): new SWItem(SWItem.Type.STRING) - ) - .validator(() -> ConfigBuilderPlugin.getActivePump() != null) - ) - .add(new SWScreen(R.string.patientage) .skippable(false) .add(new SWRadioButton() - .option("", R.array.ageArray, R.array.ageValues) + .option(R.array.ageArray, R.array.ageValues) .preferenceId(R.string.key_age) .label(R.string.patientage) .comment(R.string.patientage_summary)) @@ -142,24 +99,43 @@ public class SWDefinition { .skippable(false) .add(new SWPlugin() .option(PluginType.INSULIN) - .label(R.string.configbuilder_insulin) - .comment(R.string.configbuilder_insulin)) + .label(R.string.configbuilder_insulin)) .validator(() -> MainApp.getSpecificPluginsList(PluginType.INSULIN) != null) ) .add(new SWScreen(R.string.configbuilder_bgsource) .skippable(false) .add(new SWPlugin() .option(PluginType.BGSOURCE) - .label(R.string.configbuilder_bgsource) - .comment(R.string.configbuilder_bgsource)) + .label(R.string.configbuilder_bgsource)) .validator(() -> MainApp.getSpecificPluginsList(PluginType.BGSOURCE) != null) ) + .add(new SWScreen(R.string.configbuilder_pump) + .skippable(false) + .add(new SWPlugin() + .option(PluginType.PUMP) + .label(R.string.configbuilder_pump)) + .add(new SWButton() + .text(R.string.pumpsetup) + .action(() -> { + final PluginBase plugin = (PluginBase) MainApp.getConfigBuilder().getActivePump(); + PasswordProtection.QueryPassword(context, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(context, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + context.startActivity(i); + }, null); + }) + .visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0)) + .add(new SWButton() + .text(R.string.readstatus) + .action(() -> ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null)) + .visibility(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null)) + .validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null && MainApp.getConfigBuilder().getActivePump().isInitialized()) + ) .add(new SWScreen(R.string.configbuilder_aps) .skippable(false) .add(new SWPlugin() .option(PluginType.APS) - .label(R.string.configbuilder_aps) - .comment(R.string.configbuilder_aps)) + .label(R.string.configbuilder_aps)) .validator(() -> MainApp.getSpecificPluginsList(PluginType.APS) != null) ) ; From 41d736e1763a126faa0794e17fb5b593549e1cc2 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 9 May 2018 15:06:34 +0300 Subject: [PATCH 06/15] updated to latest from Milos --- .../androidaps/startupwizard/SWCheckbox.java | 18 ++ .../startupwizard/SWDefinition.java | 174 +++++++++--------- .../startupwizard/SWRadioButton.java | 42 +---- .../startupwizard/SetupWizardActivity.java | 6 +- 4 files changed, 111 insertions(+), 129 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWCheckbox.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWCheckbox.java index 238c4ad4c7..fa909953fe 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWCheckbox.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWCheckbox.java @@ -9,6 +9,12 @@ import android.widget.CheckBox; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.utils.SP; /** @@ -47,6 +53,18 @@ public class SWCheckbox extends SWItem { checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + ArrayList pluginsInCategory; + pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.PUMP); + PluginBase found = null; + for (PluginBase p : pluginsInCategory) { + if (p.isEnabled(PluginType.PUMP) && found == null) { + found = p; + } else if (p.isEnabled(PluginType.PUMP)) { + // set others disabled + p.setPluginEnabled(PluginType.PUMP, false); + } + } + log.debug("Enabled pump plugin:"+found.getClass()); save(checkBox.isChecked()); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index 256b7db870..1627006db8 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -51,94 +51,94 @@ public class SWDefinition { .add(new SWInfotext() .label(R.string.welcometosetupwizard) ) ) - .add(new SWScreen(R.string.language) - .skippable(false) - .add(new SWRadioButton() - .option(R.array.languagesArray, R.array.languagesValues) - .preferenceId(R.string.key_language).label(R.string.language) - .comment(R.string.setupwizard_language_prompt)) - .validator(() -> { - String lang = SP.getString("language", "en"); - LocaleHelper.setLocale(MainApp.instance().getApplicationContext(), lang); - return SP.contains(R.string.key_language); - }) - ) - .add(new SWScreen(R.string.nsclientinternal_title) - .skippable(true) - .add(new SWUrl() - .preferenceId(R.string.key_nsclientinternal_url) - .label(R.string.nsclientinternal_url_title) - .comment(R.string.nsclientinternal_url_dialogmessage)) - .add(new SWString() - .preferenceId(R.string.key_nsclientinternal_api_secret) - .label(R.string.nsclientinternal_secret_dialogtitle) - .comment(R.string.nsclientinternal_secret_dialogmessage)) - .add(new SWButton() - .text(R.string.enable_nsclient) - .action(() -> { - NSClientPlugin.getPlugin().setPluginEnabled(PluginType.GENERAL, true); - NSClientPlugin.getPlugin().setFragmentVisible(PluginType.GENERAL, true); - ConfigBuilderFragment.processOnEnabledCategoryChanged(NSClientPlugin.getPlugin(), PluginType.GENERAL); - ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); - MainApp.bus().post(new EventConfigBuilderChange()); - MainApp.bus().post(new EventSWUpdate(true)); + .add(new SWScreen(R.string.language) + .skippable(false) + .add(new SWRadioButton() + .option(R.array.languagesArray, R.array.languagesValues) + .preferenceId(R.string.key_language).label(R.string.language) + .comment(R.string.setupwizard_language_prompt)) + .validator(() -> { + String lang = SP.getString("language", "en"); + LocaleHelper.setLocale(MainApp.instance().getApplicationContext(), lang); + return SP.contains(R.string.key_language); }) - .visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL))) - .validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) - ) - .add(new SWScreen(R.string.patientage) - .skippable(false) - .add(new SWRadioButton() - .option(R.array.ageArray, R.array.ageValues) - .preferenceId(R.string.key_age) - .label(R.string.patientage) - .comment(R.string.patientage_summary)) - .validator(() -> SP.contains(R.string.key_age)) - ) - .add(new SWScreen(R.string.configbuilder_insulin) - .skippable(false) - .add(new SWPlugin() - .option(PluginType.INSULIN) - .label(R.string.configbuilder_insulin)) - .validator(() -> MainApp.getSpecificPluginsList(PluginType.INSULIN) != null) - ) - .add(new SWScreen(R.string.configbuilder_bgsource) - .skippable(false) - .add(new SWPlugin() - .option(PluginType.BGSOURCE) - .label(R.string.configbuilder_bgsource)) - .validator(() -> MainApp.getSpecificPluginsList(PluginType.BGSOURCE) != null) - ) - .add(new SWScreen(R.string.configbuilder_pump) - .skippable(false) - .add(new SWPlugin() - .option(PluginType.PUMP) - .label(R.string.configbuilder_pump)) - .add(new SWButton() - .text(R.string.pumpsetup) - .action(() -> { - final PluginBase plugin = (PluginBase) MainApp.getConfigBuilder().getActivePump(); - PasswordProtection.QueryPassword(context, R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(context, PreferencesActivity.class); - i.putExtra("id", plugin.getPreferencesId()); - context.startActivity(i); - }, null); - }) - .visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0)) - .add(new SWButton() - .text(R.string.readstatus) - .action(() -> ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null)) - .visibility(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null)) - .validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null && MainApp.getConfigBuilder().getActivePump().isInitialized()) - ) - .add(new SWScreen(R.string.configbuilder_aps) - .skippable(false) - .add(new SWPlugin() - .option(PluginType.APS) - .label(R.string.configbuilder_aps)) - .validator(() -> MainApp.getSpecificPluginsList(PluginType.APS) != null) - ) + ) + .add(new SWScreen(R.string.nsclientinternal_title) + .skippable(true) + .add(new SWUrl() + .preferenceId(R.string.key_nsclientinternal_url) + .label(R.string.nsclientinternal_url_title) + .comment(R.string.nsclientinternal_url_dialogmessage)) + .add(new SWString() + .preferenceId(R.string.key_nsclientinternal_api_secret) + .label(R.string.nsclientinternal_secret_dialogtitle) + .comment(R.string.nsclientinternal_secret_dialogmessage)) + .add(new SWButton() + .text(R.string.enable_nsclient) + .action(() -> { + NSClientPlugin.getPlugin().setPluginEnabled(PluginType.GENERAL, true); + NSClientPlugin.getPlugin().setFragmentVisible(PluginType.GENERAL, true); + ConfigBuilderFragment.processOnEnabledCategoryChanged(NSClientPlugin.getPlugin(), PluginType.GENERAL); + ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); + MainApp.bus().post(new EventConfigBuilderChange()); + MainApp.bus().post(new EventSWUpdate(true)); + }) + .visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL))) + .validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) + ) + .add(new SWScreen(R.string.patientage) + .skippable(false) + .add(new SWRadioButton() + .option(R.array.ageArray, R.array.ageValues) + .preferenceId(R.string.key_age) + .label(R.string.patientage) + .comment(R.string.patientage_summary)) + .validator(() -> SP.contains(R.string.key_age)) + ) + .add(new SWScreen(R.string.configbuilder_insulin) + .skippable(false) + .add(new SWPlugin() + .option(PluginType.INSULIN) + .label(R.string.configbuilder_insulin)) + .validator(() -> MainApp.getSpecificPluginsList(PluginType.INSULIN) != null) + ) + .add(new SWScreen(R.string.configbuilder_bgsource) + .skippable(false) + .add(new SWPlugin() + .option(PluginType.BGSOURCE) + .label(R.string.configbuilder_bgsource)) + .validator(() -> MainApp.getSpecificPluginsList(PluginType.BGSOURCE) != null) + ) + .add(new SWScreen(R.string.configbuilder_pump) + .skippable(false) + .add(new SWPlugin() + .option(PluginType.PUMP) + .label(R.string.configbuilder_pump)) + .add(new SWButton() + .text(R.string.pumpsetup) + .action(() -> { + final PluginBase plugin = (PluginBase) MainApp.getConfigBuilder().getActivePump(); + PasswordProtection.QueryPassword(context, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(context, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + context.startActivity(i); + }, null); + }) + .visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0)) + .add(new SWButton() + .text(R.string.readstatus) + .action(() -> ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null)) + .visibility(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null)) + .validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null && MainApp.getConfigBuilder().getActivePump().isInitialized()) + ) + .add(new SWScreen(R.string.configbuilder_aps) + .skippable(false) + .add(new SWPlugin() + .option(PluginType.APS) + .label(R.string.configbuilder_aps)) + .validator(() -> MainApp.getSpecificPluginsList(PluginType.APS) != null) + ) ; } -} +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java index db54de78dd..b40922dd21 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java @@ -5,22 +5,11 @@ import android.view.View; import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.RadioGroup; -import android.widget.TextView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; - import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; -import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.utils.SP; public class SWRadioButton extends SWItem { @@ -28,15 +17,13 @@ public class SWRadioButton extends SWItem { int labelsArray; int valuesArray; - String groupLabel = ""; private RadioGroup radioGroup; public SWRadioButton() { super(Type.RADIOBUTTON); } - public SWRadioButton option(String groupLabel, int labels, int values) { - this.groupLabel = groupLabel; + public SWRadioButton option(int labels, int values) { this.labelsArray = labels; this.valuesArray = values; return this; @@ -54,33 +41,12 @@ public class SWRadioButton extends SWItem { public void generateDialog(View view, LinearLayout layout) { Context context = view.getContext(); // Get if there is already value in SP - String previousValue = "none"; - if(preferenceId == R.string.key_virtualpump_uploadstatus) { - Boolean booleanValue = SP.getBoolean(preferenceId, false); - previousValue = booleanValue.toString(); - } else { - previousValue = SP.getString(preferenceId, "none"); - } - if(!groupLabel.equals("")) { - TextView groupName = new TextView(context); - groupName.setText(groupLabel); - layout.addView(groupName); - } + String previousValue = SP.getString(preferenceId, "none"); radioGroup = new RadioGroup(context); radioGroup.clearCheck(); radioGroup.setOrientation(LinearLayout.VERTICAL); radioGroup.setVisibility(View.VISIBLE); - ArrayList pluginsInCategory; - pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.PUMP); - PluginBase found = null; - for (PluginBase p : pluginsInCategory) { - if (p.isEnabled(PluginType.PUMP) && found == null) { - found = p; - } else if (p.isEnabled(PluginType.PUMP)) { - // set others disabled - p.setPluginEnabled(PluginType.PUMP, false); - } - } + for (int i = 0; i < labels().length; i++) { RadioButton rdbtn = new RadioButton(context); rdbtn.setId(View.generateViewId()); @@ -98,4 +64,4 @@ public class SWRadioButton extends SWItem { layout.addView(radioGroup); super.generateDialog(view, layout); } -} +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java index 5cc3896906..29fb95ce0f 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java @@ -126,9 +126,7 @@ public class SetupWizardActivity extends AppCompatActivity { this.finish(); Intent intent = new Intent(this, SetupWizardActivity.class); intent.putExtra(INTENT_MESSAGE, currentWizardPage + 1); - -// screens = SWDefinition.getInstance().getScreens(); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); +// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } @@ -139,7 +137,7 @@ public class SetupWizardActivity extends AppCompatActivity { intent.putExtra(INTENT_MESSAGE, currentWizardPage - 1); else intent.putExtra(INTENT_MESSAGE, 0); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); +// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } From bfd61a65a04e78f0bce524946d7e8289240874c6 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 9 May 2018 15:44:40 +0300 Subject: [PATCH 07/15] fix for screens adding up --- .../androidaps/startupwizard/SWDefinition.java | 2 ++ .../startupwizard/SetupWizardActivity.java | 13 +------------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index 1627006db8..5a56883b2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -47,6 +47,8 @@ public class SWDefinition { SWDefinition() { // List all the screens here + if(screens.size() >0) + return; add(new SWScreen(R.string.nav_setupwizard) .add(new SWInfotext() .label(R.string.welcometosetupwizard) ) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java index 29fb95ce0f..8812a94369 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java @@ -31,9 +31,8 @@ public class SetupWizardActivity extends AppCompatActivity { SWDefinition swDefinition = new SWDefinition(); List screens = swDefinition.getScreens(); private int currentWizardPage = 0; - public static final String INTENT_MESSAGE = "WIZZARDPAGE"; - public static final String RESTART = "RESTART"; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -62,14 +61,6 @@ public class SetupWizardActivity extends AppCompatActivity { @Override protected void onResume() { - - Intent intent = new Intent(this, SetupWizardActivity.class); - intent.putExtra(INTENT_MESSAGE, 0); - if(intent.getBooleanExtra(RESTART, false)) { - intent.putExtra(RESTART, false); - this.finish(); - startActivity(intent); - } super.onResume(); MainApp.bus().register(this); swDefinition.setContext(this); @@ -126,7 +117,6 @@ public class SetupWizardActivity extends AppCompatActivity { this.finish(); Intent intent = new Intent(this, SetupWizardActivity.class); intent.putExtra(INTENT_MESSAGE, currentWizardPage + 1); -// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } @@ -137,7 +127,6 @@ public class SetupWizardActivity extends AppCompatActivity { intent.putExtra(INTENT_MESSAGE, currentWizardPage - 1); else intent.putExtra(INTENT_MESSAGE, 0); -// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } From 50f8bf2d1857e3db76d5a1476b33525f4cd9f469 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 9 May 2018 15:55:02 +0300 Subject: [PATCH 08/15] fix for screens adding up --- .../nightscout/androidaps/startupwizard/SWDefinition.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index 5a56883b2c..a3f9ee4b82 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -46,9 +46,10 @@ public class SWDefinition { SWDefinition() { - // List all the screens here + // Don't allow for screens to add up if(screens.size() >0) - return; + screens = new ArrayList<>(); + // List all the screens here add(new SWScreen(R.string.nav_setupwizard) .add(new SWInfotext() .label(R.string.welcometosetupwizard) ) From e3153230e073449371ab8e8fa276b1a4c5a53501 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 9 May 2018 17:11:07 +0300 Subject: [PATCH 09/15] added NSClient followup --- .../androidaps/startupwizard/SWDefinition.java | 18 +++++++++++++++++- app/src/main/res/values/strings.xml | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index a3f9ee4b82..5411f92cad 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -89,6 +89,22 @@ public class SWDefinition { .visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL))) .validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) ) + .add(NSClientPlugin.getPlugin().nsClientService != null ? new SWScreen(R.string.nsclientinternal_title) + .skippable(true) + .add(new SWButton() + .text(R.string.nsclient_prefs) + .action(() -> { + final PluginBase plugin = (PluginBase) NSClientPlugin.getPlugin(); + PasswordProtection.QueryPassword(context, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(context, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + context.startActivity(i); + }, null); + }) + .visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0)): new SWScreen(R.string.nav_setupwizard) + .add(new SWInfotext() + .label(R.string.settings_incorrect) ) + ) .add(new SWScreen(R.string.patientage) .skippable(false) .add(new SWRadioButton() @@ -139,7 +155,7 @@ public class SWDefinition { .add(new SWPlugin() .option(PluginType.APS) .label(R.string.configbuilder_aps)) - .validator(() -> MainApp.getSpecificPluginsList(PluginType.APS) != null) + .validator(() -> MainApp.getSpecificPluginsList(PluginType.APS) != null ) ) ; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 58293191af..9cd3e4ca58 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1061,9 +1061,11 @@ General Settings DUMMY\nCONTENT - Enable NSClient + Connect to NightScout + Additional NSClient options Welcome to setup wizard. It will guide you through the setup process Pump setup Read status + Incorrect settings! Press \'BACK\' and try again From 33a6135e75048c012843e6a5fe3d0e3a78c2dde6 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 10 May 2018 13:48:18 +0300 Subject: [PATCH 10/15] Added insulin descriptions to SW screen --- .../androidaps/startupwizard/SWDefinition.java | 6 ++++++ .../androidaps/startupwizard/SWInfotext.java | 11 ++++++++++- app/src/main/res/values/strings.xml | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index dfaaf7a5d3..302a5b9f69 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -119,6 +119,12 @@ public class SWDefinition { .add(new SWPlugin() .option(PluginType.INSULIN) .label(R.string.configbuilder_insulin)) + .add(new SWInfotext() + .label(MainApp.gs(R.string.fastactinginsulincomment)+" = "+MainApp.gs(R.string.rapid_acting_oref))) + .add(new SWInfotext() + .label(MainApp.gs(R.string.ultrafastactinginsulincomment)+" = "+MainApp.gs(R.string.ultrarapid_oref))) + .add(new SWInfotext() + .label(MainApp.gs(R.string.free_peak_oref_description)+" = "+MainApp.gs(R.string.free_peak_oref))) .validator(() -> MainApp.getConfigBuilder().getActiveInsulin() != null) ) .add(new SWScreen(R.string.configbuilder_bgsource) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWInfotext.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWInfotext.java index 92f36e2498..1e155d3551 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWInfotext.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWInfotext.java @@ -15,18 +15,27 @@ import org.slf4j.LoggerFactory; public class SWInfotext extends SWItem { private static Logger log = LoggerFactory.getLogger(SWInfotext.class); + private String textLabel = null; public SWInfotext() { super(Type.TEXT); } + public SWInfotext label(String newLabel){ + this.textLabel = newLabel; + return this; + } + @Override public void generateDialog(View view, LinearLayout layout) { Context context = view.getContext(); TextView l = new TextView(context); l.setId(view.generateViewId()); - l.setText(label); + if(textLabel != null) + l.setText(textLabel); + else + l.setText(label); layout.addView(l); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 758bafd78c..7a9cd09105 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -668,6 +668,8 @@ Free-Peak Oref Rapid-Acting Oref Ultra-Rapid Oref + Custom insulin + Rapid-Acting Oref DIA of %f too short - using %f instead! Activate profile Date From 2fa77d2a8cd8ce999c60d699680b937865bf3cd2 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 10 May 2018 13:49:13 +0300 Subject: [PATCH 11/15] Added insulin descriptions to SW screen --- .../androidaps/startupwizard/SWDefinition.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index 302a5b9f69..9800a8dd80 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -116,15 +116,15 @@ public class SWDefinition { ) .add(new SWScreen(R.string.configbuilder_insulin) .skippable(false) + .add(new SWInfotext() + .label(MainApp.gs(R.string.fastactinginsulincomment)+" = "+MainApp.gs(R.string.rapid_acting_oref))) + .add(new SWInfotext() + .label(MainApp.gs(R.string.ultrafastactinginsulincomment)+" = "+MainApp.gs(R.string.ultrarapid_oref))) + .add(new SWInfotext() + .label(MainApp.gs(R.string.free_peak_oref_description)+" = "+MainApp.gs(R.string.free_peak_oref))) .add(new SWPlugin() .option(PluginType.INSULIN) .label(R.string.configbuilder_insulin)) - .add(new SWInfotext() - .label(MainApp.gs(R.string.fastactinginsulincomment)+" = "+MainApp.gs(R.string.rapid_acting_oref))) - .add(new SWInfotext() - .label(MainApp.gs(R.string.ultrafastactinginsulincomment)+" = "+MainApp.gs(R.string.ultrarapid_oref))) - .add(new SWInfotext() - .label(MainApp.gs(R.string.free_peak_oref_description)+" = "+MainApp.gs(R.string.free_peak_oref))) .validator(() -> MainApp.getConfigBuilder().getActiveInsulin() != null) ) .add(new SWScreen(R.string.configbuilder_bgsource) From 016aa1c06909f0db417c84eeafe8211364d7cc2e Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 10 May 2018 13:56:50 +0300 Subject: [PATCH 12/15] Added insulin descriptions to SW screen --- .../nightscout/androidaps/startupwizard/SWDefinition.java | 3 --- .../nightscout/androidaps/startupwizard/SWRadioButton.java | 2 +- .../androidaps/startupwizard/SetupWizardActivity.java | 1 + app/src/main/res/values/strings.xml | 4 ---- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index 9800a8dd80..e5d3b68b0e 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -62,9 +62,6 @@ public class SWDefinition { SWDefinition() { - // Don't allow for screens to add up - if(screens.size() >0) - screens = new ArrayList<>(); // List all the screens here add(new SWScreen(R.string.nav_setupwizard) .add(new SWInfotext() diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java index b40922dd21..7cdbee3d71 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java @@ -64,4 +64,4 @@ public class SWRadioButton extends SWItem { layout.addView(radioGroup); super.generateDialog(view, layout); } -} \ No newline at end of file +} diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java index b905487118..67af63326b 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java @@ -38,6 +38,7 @@ public class SetupWizardActivity extends AppCompatActivity { super.onCreate(savedInstanceState); LocaleHelper.onCreate(this, "en"); setContentView(R.layout.activity_setupwizard); + Intent intent = getIntent(); currentWizardPage = intent.getIntExtra(SetupWizardActivity.INTENT_MESSAGE, 0); if (screens.size() > 0 && currentWizardPage < screens.size()) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7a9cd09105..bae0a5698f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1022,7 +1022,6 @@ Skip FINISH Select your language - Test pump connection language openapsama_min_5m_carbimpact Asked: %.2fU Delivered: %.2fU Error code: %d @@ -1061,9 +1060,6 @@ Calculations included in the Wizard result: Display Settings General Settings - DUMMY\nCONTENT - Additional NSClient options - Incorrect settings! Press \'BACK\' and try again Enable NSClient Welcome to setup wizard. It will guide you through the setup process Pump setup From 9ac081dd1ddf025d082df05fb2a1d3dbbaf827f3 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 10 May 2018 14:01:17 +0300 Subject: [PATCH 13/15] arrays.xml clean --- app/src/main/res/values/arrays.xml | 11 ----------- app/src/main/res/values/strings.xml | 1 - 2 files changed, 12 deletions(-) diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index c21941198e..181ce1d8dd 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -109,15 +109,4 @@ @string/no @string/yes - - - @string/yes - @string/no - - - - true - false - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bae0a5698f..a49b8e98b4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -524,7 +524,6 @@ resistantadult Please select patient age to setup safety limits I_understand - virtualpump_uploadstatus Glimp Device does not appear to support battery optimization whitelisting! Please Allow Permission From 61afdd6e4ce337045fb33714fcde0b97d0297c5b Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 10 May 2018 14:05:33 +0300 Subject: [PATCH 14/15] cleanup --- app/src/main/res/values/strings.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a49b8e98b4..f033174b6e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -668,7 +668,6 @@ Rapid-Acting Oref Ultra-Rapid Oref Custom insulin - Rapid-Acting Oref DIA of %f too short - using %f instead! Activate profile Date From 91c0b1a2ec1c4b2b0f11ae7465eede303a927fce Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Thu, 10 May 2018 14:36:05 +0300 Subject: [PATCH 15/15] make Objectives visible --- .../startupwizard/SWDefinition.java | 22 +++++++++++++++++++ app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 25 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index e5d3b68b0e..76cb43d12a 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialo import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment; @@ -126,6 +127,8 @@ public class SWDefinition { ) .add(new SWScreen(R.string.configbuilder_bgsource) .skippable(false) + .add(new SWInfotext() + .label(R.string.setupwizard_bgsource_description)) .add(new SWPlugin() .option(PluginType.BGSOURCE) .label(R.string.configbuilder_bgsource)) @@ -216,6 +219,8 @@ public class SWDefinition { ) .add(new SWScreen(R.string.configbuilder_loop) .skippable(false) + .add(new SWInfotext() + .label(R.string.setupwizard_loop_description)) .add(new SWButton() .text(R.string.enableloop) .action(() -> { @@ -229,6 +234,23 @@ public class SWDefinition { .validator(() -> LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) .visibility(() -> !LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) ) + .add(new SWScreen(R.string.objectives) + .skippable(false) + .add(new SWInfotext() + .label(R.string.setupwizard_objectives_description)) + .add(new SWButton() + .text(R.string.objectives_button_start) + .action(() -> { + ObjectivesPlugin.getPlugin().setPluginEnabled(PluginType.CONSTRAINTS, true); + ObjectivesPlugin.getPlugin().setFragmentVisible(PluginType.CONSTRAINTS, true); + ConfigBuilderFragment.processOnEnabledCategoryChanged(ObjectivesPlugin.getPlugin(), PluginType.CONSTRAINTS); + ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); + MainApp.bus().post(new EventConfigBuilderChange()); + MainApp.bus().post(new EventSWUpdate(true)); + })) + .validator(() -> ObjectivesPlugin.getPlugin().isEnabled(PluginType.CONSTRAINTS)) + .visibility(() -> !ObjectivesPlugin.getPlugin().isFragmentVisible()) + ) ; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f033174b6e..35fff2ce20 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1064,5 +1064,8 @@ Read status Changes must be done in NS Exit setup wizard? + Where should blood glucose(BG) data be comming from ? + Press the button below to enable AndroidAPS to suggest/make basal changes + Press the button below to enable Objectives. Look in the Objectives tab, after you finish this wizard, to make AndroidAPS completely functional.