stop extended bolus in actions

This commit is contained in:
Milos Kozak 2017-05-24 20:37:58 +02:00
parent 2ae30fe9b4
commit 86af9eab3d
4 changed files with 87 additions and 9 deletions

View file

@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.Actions;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -10,13 +12,21 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog;
import info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog; import info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog;
@ -38,10 +48,20 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
Button profileSwitch; Button profileSwitch;
Button tempTarget; Button tempTarget;
Button extendedBolus; Button extendedBolus;
Button extendedBolusCancel;
Button tempBasal; Button tempBasal;
Button fill; Button fill;
private static Handler sHandler;
private static HandlerThread sHandlerThread;
public ActionsFragment() { public ActionsFragment() {
super();
if (sHandlerThread == null) {
sHandlerThread = new HandlerThread(ActionsFragment.class.getSimpleName());
sHandlerThread.start();
sHandler = new Handler(sHandlerThread.getLooper());
}
} }
@ -53,12 +73,14 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch); profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch);
tempTarget = (Button) view.findViewById(R.id.actions_temptarget); tempTarget = (Button) view.findViewById(R.id.actions_temptarget);
extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus); extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus);
extendedBolusCancel = (Button) view.findViewById(R.id.actions_extendedbolus_cancel);
tempBasal = (Button) view.findViewById(R.id.actions_settempbasal); tempBasal = (Button) view.findViewById(R.id.actions_settempbasal);
fill = (Button) view.findViewById(R.id.actions_fill); fill = (Button) view.findViewById(R.id.actions_fill);
profileSwitch.setOnClickListener(this); profileSwitch.setOnClickListener(this);
tempTarget.setOnClickListener(this); tempTarget.setOnClickListener(this);
extendedBolus.setOnClickListener(this); extendedBolus.setOnClickListener(this);
extendedBolusCancel.setOnClickListener(this);
tempBasal.setOnClickListener(this); tempBasal.setOnClickListener(this);
fill.setOnClickListener(this); fill.setOnClickListener(this);
@ -91,6 +113,16 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
updateGUIIfVisible(); updateGUIIfVisible();
} }
@Subscribe
public void onStatusEvent(final EventExtendedBolusChange ev) {
updateGUIIfVisible();
}
@Subscribe
public void onStatusEvent(final EventTempBasalChange ev) {
updateGUIIfVisible();
}
void updateGUIIfVisible() { void updateGUIIfVisible() {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null) if (activity != null)
@ -101,11 +133,19 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
profileSwitch.setVisibility(View.GONE); profileSwitch.setVisibility(View.GONE);
else else
profileSwitch.setVisibility(View.VISIBLE); profileSwitch.setVisibility(View.VISIBLE);
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isExtendedBoluslInProgress())
extendedBolus.setVisibility(View.GONE); extendedBolus.setVisibility(View.GONE);
else else {
extendedBolus.setVisibility(View.VISIBLE); extendedBolus.setVisibility(View.VISIBLE);
if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) }
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isExtendedBoluslInProgress())
extendedBolusCancel.setVisibility(View.GONE);
else {
extendedBolusCancel.setVisibility(View.VISIBLE);
ExtendedBolus running = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime());
extendedBolusCancel.setText(MainApp.instance().getString(R.string.cancel) + " " + running.toString());
}
if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isTempBasalInProgress())
tempBasal.setVisibility(View.GONE); tempBasal.setVisibility(View.GONE);
else else
tempBasal.setVisibility(View.VISIBLE); tempBasal.setVisibility(View.VISIBLE);
@ -125,6 +165,7 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
FragmentManager manager = getFragmentManager(); FragmentManager manager = getFragmentManager();
final PumpInterface pump = MainApp.getConfigBuilder();
switch (view.getId()) { switch (view.getId()) {
case R.id.actions_profileswitch: case R.id.actions_profileswitch:
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
@ -144,6 +185,17 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
NewExtendedBolusDialog newExtendedDialog = new NewExtendedBolusDialog(); NewExtendedBolusDialog newExtendedDialog = new NewExtendedBolusDialog();
newExtendedDialog.show(manager, "NewExtendedDialog"); newExtendedDialog.show(manager, "NewExtendedDialog");
break; break;
case R.id.actions_extendedbolus_cancel:
if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) {
sHandler.post(new Runnable() {
@Override
public void run() {
pump.cancelExtendedBolus();
Answers.getInstance().logCustom(new CustomEvent("CancelExtended"));
}
});
}
break;
case R.id.actions_settempbasal: case R.id.actions_settempbasal:
NewTempBasalDialog newTempDialog = new NewTempBasalDialog(); NewTempBasalDialog newTempDialog = new NewTempBasalDialog();
newTempDialog.show(manager, "NewTempDialog"); newTempDialog.show(manager, "NewTempDialog");
@ -153,12 +205,26 @@ public class ActionsFragment extends Fragment implements View.OnClickListener {
fillDialog.show(manager, "FillDialog"); fillDialog.show(manager, "FillDialog");
break; break;
case R.id.actions_50_30: case R.id.actions_50_30:
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
sHandler.post(new Runnable() {
@Override
public void run() {
DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class);
danaRv2Plugin.setHighTempBasalPercent(50); danaRv2Plugin.setHighTempBasalPercent(50);
}
});
}
break; break;
case R.id.actions_400_15: case R.id.actions_400_15:
danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
sHandler.post(new Runnable() {
@Override
public void run() {
DanaRv2Plugin danaRv2Plugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class);
danaRv2Plugin.setHighTempBasalPercent(400); danaRv2Plugin.setHighTempBasalPercent(400);
}
});
}
break; break;
} }
} }

View file

@ -232,8 +232,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
treatmentButton.setOnClickListener(this); treatmentButton.setOnClickListener(this);
wizardButton = (Button) view.findViewById(R.id.overview_wizardbutton); wizardButton = (Button) view.findViewById(R.id.overview_wizardbutton);
wizardButton.setOnClickListener(this); wizardButton.setOnClickListener(this);
cancelTempButton = (Button) view.findViewById(R.id.overview_canceltempbutton);
cancelTempButton.setOnClickListener(this);
acceptTempButton = (Button) view.findViewById(R.id.overview_accepttempbutton); acceptTempButton = (Button) view.findViewById(R.id.overview_accepttempbutton);
acceptTempButton.setOnClickListener(this); acceptTempButton.setOnClickListener(this);
quickWizardButton = (Button) view.findViewById(R.id.overview_quickwizardbutton); quickWizardButton = (Button) view.findViewById(R.id.overview_quickwizardbutton);

View file

@ -65,6 +65,19 @@
android:text="@string/overview_extendedbolus_button" android:text="@string/overview_extendedbolus_button"
android:textColor="@color/colorSetExtendedButton" /> android:textColor="@color/colorSetExtendedButton" />
<Button
android:id="@+id/actions_extendedbolus_cancel"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="3dp"
android:layout_weight="0.5"
android:text="@string/overview_extendedbolus_cancel_button"
android:textColor="@color/colorSetExtendedButton" />
<Button <Button
android:id="@+id/actions_fill" android:id="@+id/actions_fill"
style="?android:attr/buttonStyle" style="?android:attr/buttonStyle"

View file

@ -614,4 +614,5 @@
<string name="bolus_step">Bolus Step</string> <string name="bolus_step">Bolus Step</string>
<string name="extendedbolus">ExtendedBolus</string> <string name="extendedbolus">ExtendedBolus</string>
<string name="temptarget">TempTarget</string> <string name="temptarget">TempTarget</string>
<string name="overview_extendedbolus_cancel_button">Cancel Extended Bolus</string>
</resources> </resources>