diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWButton.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWButton.java index f781a9a3c6..902d7d66e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWButton.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWButton.java @@ -15,6 +15,8 @@ public class SWButton extends SWItem { int buttonText; SWValidator buttonValidator; + Button button; + public SWButton() { super(Type.BUTTON); } @@ -38,15 +40,22 @@ public class SWButton extends SWItem { public void generateDialog(View view, LinearLayout layout) { Context context = view.getContext(); - Button button = new Button(context); + button = new Button(context); button.setText(buttonText); button.setOnClickListener((v) -> { if (buttonRunnable != null) buttonRunnable.run(); }); - if (buttonValidator != null && !buttonValidator.isValid()) - return; + processVisibility(); layout.addView(button); super.generateDialog(view, layout); } + + @Override + public void processVisibility() { + if (buttonValidator != null && !buttonValidator.isValid()) + button.setVisibility(View.GONE); + else + button.setVisibility(View.VISIBLE); + } } 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 2fe85a4978..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,29 +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.startupwizard.events.EventSWUpdate; import info.nightscout.utils.LocaleHelper; +import info.nightscout.utils.PasswordProtection; import info.nightscout.utils.SP; 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; } @@ -94,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) ) ; diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWItem.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWItem.java index 4d8dfe1bc5..7d6efd8d59 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWItem.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWItem.java @@ -82,4 +82,6 @@ public class SWItem { public void generateDialog(View view, LinearLayout layout) { } + public void processVisibility() { + } } diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWScreen.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWScreen.java index 61fed74ffa..85c9e074ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWScreen.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWScreen.java @@ -34,4 +34,9 @@ public class SWScreen { this.validator = validator; return this; } + + public void processVisibility() { + for (SWItem i : items) + i.processVisibility(); + } } 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 35c4549bd3..c2336bfcc4 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java @@ -17,6 +17,7 @@ import java.util.List; import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus; import info.nightscout.androidaps.startupwizard.events.EventSWUpdate; import info.nightscout.utils.LocaleHelper; @@ -27,7 +28,7 @@ public class SetupWizardActivity extends AppCompatActivity { private TextView screenName; - SWDefinition swDefinition = SWDefinition.getInstance(); + SWDefinition swDefinition = new SWDefinition(); List screens = swDefinition.getScreens(); private int currentWizardPage = 0; public static final String INTENT_MESSAGE = "WIZZARDPAGE"; @@ -63,6 +64,7 @@ public class SetupWizardActivity extends AppCompatActivity { protected void onResume() { super.onResume(); MainApp.bus().register(this); + swDefinition.setContext(this); } @Subscribe @@ -73,7 +75,12 @@ public class SetupWizardActivity extends AppCompatActivity { } @Subscribe - public void onContentUpdate(EventNSClientStatus ev) { + public void onEventNSClientStatus(EventNSClientStatus ignored) { + updateButtons(); + } + + @Subscribe + public void onEventPumpStatusChanged(EventPumpStatusChanged ignored) { updateButtons(); } @@ -104,6 +111,7 @@ public class SetupWizardActivity extends AppCompatActivity { findViewById(R.id.previous_button).setVisibility(View.GONE); else findViewById(R.id.previous_button).setVisibility(View.VISIBLE); + currentScreen.processVisibility(); } public void showNextPage(View view) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 306f23a314..d47a956a06 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1061,5 +1061,7 @@ DUMMY\nCONTENT Enable NSClient Welcome to setup wizard. It will guide you through the setup process + Pump setup + Read status