SW show pump status
This commit is contained in:
parent
bacb3fb337
commit
0060a2ba7f
|
@ -1,8 +1,10 @@
|
||||||
package info.nightscout.androidaps.startupwizard;
|
package info.nightscout.androidaps.startupwizard;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -13,13 +15,13 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.PreferencesActivity;
|
import info.nightscout.androidaps.PreferencesActivity;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
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.ConfigBuilderFragment;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
|
||||||
|
import info.nightscout.androidaps.startupwizard.events.EventSWLabel;
|
||||||
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
|
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
|
||||||
import info.nightscout.utils.LocaleHelper;
|
import info.nightscout.utils.LocaleHelper;
|
||||||
import info.nightscout.utils.PasswordProtection;
|
import info.nightscout.utils.PasswordProtection;
|
||||||
|
@ -28,14 +30,18 @@ import info.nightscout.utils.SP;
|
||||||
public class SWDefinition {
|
public class SWDefinition {
|
||||||
private static Logger log = LoggerFactory.getLogger(SWDefinition.class);
|
private static Logger log = LoggerFactory.getLogger(SWDefinition.class);
|
||||||
|
|
||||||
private Context context;
|
private Activity activity;
|
||||||
static List<SWScreen> screens = new ArrayList<>();
|
private List<SWScreen> screens = new ArrayList<>();
|
||||||
|
|
||||||
public void setContext(Context context) {
|
public void setActivity(Activity activity) {
|
||||||
this.context = context;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SWScreen> getScreens() {
|
public Activity getActivity() {
|
||||||
|
return activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<SWScreen> getScreens() {
|
||||||
return screens;
|
return screens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,10 +124,10 @@ public class SWDefinition {
|
||||||
.text(R.string.pumpsetup)
|
.text(R.string.pumpsetup)
|
||||||
.action(() -> {
|
.action(() -> {
|
||||||
final PluginBase plugin = (PluginBase) MainApp.getConfigBuilder().getActivePump();
|
final PluginBase plugin = (PluginBase) MainApp.getConfigBuilder().getActivePump();
|
||||||
PasswordProtection.QueryPassword(context, R.string.settings_password, "settings_password", () -> {
|
PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> {
|
||||||
Intent i = new Intent(context, PreferencesActivity.class);
|
Intent i = new Intent(activity, PreferencesActivity.class);
|
||||||
i.putExtra("id", plugin.getPreferencesId());
|
i.putExtra("id", plugin.getPreferencesId());
|
||||||
context.startActivity(i);
|
activity.startActivity(i);
|
||||||
}, null);
|
}, null);
|
||||||
})
|
})
|
||||||
.visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0))
|
.visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0))
|
||||||
|
@ -129,6 +135,14 @@ public class SWDefinition {
|
||||||
.text(R.string.readstatus)
|
.text(R.string.readstatus)
|
||||||
.action(() -> ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null))
|
.action(() -> ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null))
|
||||||
.visibility(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null))
|
.visibility(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null))
|
||||||
|
.add(new SWEventListener(this)
|
||||||
|
.listener(new Object() {
|
||||||
|
@Subscribe
|
||||||
|
public void onEventPumpStatusChanged(EventPumpStatusChanged event) {
|
||||||
|
MainApp.bus().post(new EventSWLabel(event.textStatus()));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
.validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null && MainApp.getConfigBuilder().getActivePump().isInitialized())
|
.validator(() -> MainApp.getSpecificPluginsList(PluginType.PUMP) != null && MainApp.getConfigBuilder().getActivePump().isInitialized())
|
||||||
)
|
)
|
||||||
.add(new SWScreen(R.string.configbuilder_aps)
|
.add(new SWScreen(R.string.configbuilder_aps)
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package info.nightscout.androidaps.startupwizard;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.startupwizard.events.EventSWLabel;
|
||||||
|
|
||||||
|
|
||||||
|
public class SWEventListener extends SWItem {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(SWEventListener.class);
|
||||||
|
|
||||||
|
TextView textView;
|
||||||
|
Object listener;
|
||||||
|
SWDefinition definition;
|
||||||
|
|
||||||
|
SWEventListener(SWDefinition definition) {
|
||||||
|
super(Type.LISTENER);
|
||||||
|
this.definition = definition;
|
||||||
|
MainApp.bus().register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SWEventListener listener(Object listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateDialog(View view, LinearLayout layout) {
|
||||||
|
Context context = view.getContext();
|
||||||
|
|
||||||
|
textView = new TextView(context);
|
||||||
|
textView.setId(view.generateViewId());
|
||||||
|
layout.addView(textView);
|
||||||
|
if (listener != null)
|
||||||
|
MainApp.bus().register(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onEventSWLabel(final EventSWLabel l) {
|
||||||
|
if (definition != null && definition.getActivity() != null)
|
||||||
|
definition.getActivity().runOnUiThread(() -> {
|
||||||
|
if (textView != null)
|
||||||
|
textView.setText(l.label);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ public class SWItem {
|
||||||
enum Type {
|
enum Type {
|
||||||
NONE,
|
NONE,
|
||||||
TEXT,
|
TEXT,
|
||||||
|
LISTENER,
|
||||||
URL,
|
URL,
|
||||||
STRING,
|
STRING,
|
||||||
NUMBER,
|
NUMBER,
|
||||||
|
|
|
@ -26,10 +26,8 @@ public class SetupWizardActivity extends AppCompatActivity {
|
||||||
//logging
|
//logging
|
||||||
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
|
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
|
||||||
|
|
||||||
private TextView screenName;
|
private SWDefinition swDefinition = new SWDefinition();
|
||||||
|
private List<SWScreen> screens = swDefinition.getScreens();
|
||||||
SWDefinition swDefinition = new SWDefinition();
|
|
||||||
List<SWScreen> screens = swDefinition.getScreens();
|
|
||||||
private int currentWizardPage = 0;
|
private int currentWizardPage = 0;
|
||||||
public static final String INTENT_MESSAGE = "WIZZARDPAGE";
|
public static final String INTENT_MESSAGE = "WIZZARDPAGE";
|
||||||
|
|
||||||
|
@ -45,7 +43,7 @@ public class SetupWizardActivity extends AppCompatActivity {
|
||||||
SWScreen currentScreen = screens.get(currentWizardPage);
|
SWScreen currentScreen = screens.get(currentWizardPage);
|
||||||
|
|
||||||
//Set screen name
|
//Set screen name
|
||||||
screenName = (TextView) findViewById(R.id.sw_content);
|
TextView screenName = (TextView) findViewById(R.id.sw_content);
|
||||||
screenName.setText(currentScreen.getHeader());
|
screenName.setText(currentScreen.getHeader());
|
||||||
|
|
||||||
//Generate layout first
|
//Generate layout first
|
||||||
|
@ -64,7 +62,7 @@ public class SetupWizardActivity extends AppCompatActivity {
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
swDefinition.setContext(this);
|
swDefinition.setActivity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package info.nightscout.androidaps.startupwizard.events;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
|
||||||
|
public class EventSWLabel extends Event {
|
||||||
|
public String label;
|
||||||
|
|
||||||
|
public EventSWLabel(String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue