SW show pump status

This commit is contained in:
Milos Kozak 2018-05-09 15:10:47 +02:00
parent bacb3fb337
commit 0060a2ba7f
5 changed files with 96 additions and 17 deletions

View file

@ -1,8 +1,10 @@
package info.nightscout.androidaps.startupwizard;
import android.content.Context;
import android.app.Activity;
import android.content.Intent;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -13,13 +15,13 @@ 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.events.EventPumpStatusChanged;
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.EventSWLabel;
import info.nightscout.androidaps.startupwizard.events.EventSWUpdate;
import info.nightscout.utils.LocaleHelper;
import info.nightscout.utils.PasswordProtection;
@ -28,14 +30,18 @@ import info.nightscout.utils.SP;
public class SWDefinition {
private static Logger log = LoggerFactory.getLogger(SWDefinition.class);
private Context context;
static List<SWScreen> screens = new ArrayList<>();
private Activity activity;
private List<SWScreen> screens = new ArrayList<>();
public void setContext(Context context) {
this.context = context;
public void setActivity(Activity activity) {
this.activity = activity;
}
public static List<SWScreen> getScreens() {
public Activity getActivity() {
return activity;
}
public List<SWScreen> getScreens() {
return screens;
}
@ -118,10 +124,10 @@ public class SWDefinition {
.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);
PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> {
Intent i = new Intent(activity, PreferencesActivity.class);
i.putExtra("id", plugin.getPreferencesId());
context.startActivity(i);
activity.startActivity(i);
}, null);
})
.visibility(() -> ((PluginBase) MainApp.getConfigBuilder().getActivePump()).getPreferencesId() > 0))
@ -129,6 +135,14 @@ public class SWDefinition {
.text(R.string.readstatus)
.action(() -> ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to 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())
)
.add(new SWScreen(R.string.configbuilder_aps)

View file

@ -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);
});
}
}

View file

@ -17,6 +17,7 @@ public class SWItem {
enum Type {
NONE,
TEXT,
LISTENER,
URL,
STRING,
NUMBER,

View file

@ -26,10 +26,8 @@ public class SetupWizardActivity extends AppCompatActivity {
//logging
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
private TextView screenName;
SWDefinition swDefinition = new SWDefinition();
List<SWScreen> screens = swDefinition.getScreens();
private SWDefinition swDefinition = new SWDefinition();
private List<SWScreen> screens = swDefinition.getScreens();
private int currentWizardPage = 0;
public static final String INTENT_MESSAGE = "WIZZARDPAGE";
@ -45,7 +43,7 @@ public class SetupWizardActivity extends AppCompatActivity {
SWScreen currentScreen = screens.get(currentWizardPage);
//Set screen name
screenName = (TextView) findViewById(R.id.sw_content);
TextView screenName = (TextView) findViewById(R.id.sw_content);
screenName.setText(currentScreen.getHeader());
//Generate layout first
@ -64,7 +62,7 @@ public class SetupWizardActivity extends AppCompatActivity {
protected void onResume() {
super.onResume();
MainApp.bus().register(this);
swDefinition.setContext(this);
swDefinition.setActivity(this);
}
@Subscribe

View file

@ -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;
}
}