fill action
This commit is contained in:
parent
5f4a8330e1
commit
a6d5d68938
6 changed files with 230 additions and 1 deletions
|
@ -10,6 +10,7 @@ import android.view.ViewGroup;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||||
|
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog;
|
import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog;
|
||||||
|
@ -37,6 +38,7 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl
|
||||||
view.findViewById(R.id.actions_profileswitch).setOnClickListener(this);
|
view.findViewById(R.id.actions_profileswitch).setOnClickListener(this);
|
||||||
view.findViewById(R.id.actions_extendedbolus).setOnClickListener(this);
|
view.findViewById(R.id.actions_extendedbolus).setOnClickListener(this);
|
||||||
view.findViewById(R.id.actions_settempbasal).setOnClickListener(this);
|
view.findViewById(R.id.actions_settempbasal).setOnClickListener(this);
|
||||||
|
view.findViewById(R.id.actions_fill).setOnClickListener(this);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -60,6 +62,10 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl
|
||||||
NewTempBasalDialog newTempDialog = new NewTempBasalDialog();
|
NewTempBasalDialog newTempDialog = new NewTempBasalDialog();
|
||||||
newTempDialog.show(manager, "NewTempDialog");
|
newTempDialog.show(manager, "NewTempDialog");
|
||||||
break;
|
break;
|
||||||
|
case R.id.actions_fill:
|
||||||
|
FillDialog fillDialog = new FillDialog();
|
||||||
|
fillDialog.show(manager, "FillDialog");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,125 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Actions.dialogs;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Constants;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.utils.PlusMinusEditText;
|
||||||
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
|
public class FillDialog extends DialogFragment implements OnClickListener {
|
||||||
|
|
||||||
|
Button deliverButton;
|
||||||
|
TextView insulin;
|
||||||
|
|
||||||
|
PlusMinusEditText editInsulin;
|
||||||
|
|
||||||
|
Handler mHandler;
|
||||||
|
public static HandlerThread mHandlerThread;
|
||||||
|
|
||||||
|
public FillDialog() {
|
||||||
|
mHandlerThread = new HandlerThread(FillDialog.class.getSimpleName());
|
||||||
|
mHandlerThread.start();
|
||||||
|
this.mHandler = new Handler(mHandlerThread.getLooper());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.actions_fill_dialog, null, false);
|
||||||
|
|
||||||
|
deliverButton = (Button) view.findViewById(R.id.treatments_newtreatment_deliverbutton);
|
||||||
|
|
||||||
|
deliverButton.setOnClickListener(this);
|
||||||
|
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||||
|
|
||||||
|
insulin = (TextView) view.findViewById(R.id.treatments_newtreatment_insulinamount);
|
||||||
|
Double maxInsulin = MainApp.getConfigBuilder().applyBolusConstraints(Constants.bolusOnlyForCheckLimit);
|
||||||
|
|
||||||
|
editInsulin = new PlusMinusEditText(view, R.id.treatments_newtreatment_insulinamount, R.id.treatments_newtreatment_insulinamount_plus, R.id.treatments_newtreatment_insulinamount_minus, 0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (getDialog() != null)
|
||||||
|
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
switch (view.getId()) {
|
||||||
|
case R.id.treatments_newtreatment_deliverbutton:
|
||||||
|
|
||||||
|
try {
|
||||||
|
Double insulin = SafeParse.stringToDouble(this.insulin.getText().toString());
|
||||||
|
|
||||||
|
String confirmMessage = getString(R.string.fillwarning) + "\n";
|
||||||
|
|
||||||
|
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(insulin);
|
||||||
|
confirmMessage += getString(R.string.bolus) + ": " + insulinAfterConstraints + "U";
|
||||||
|
if (insulinAfterConstraints - insulin != 0)
|
||||||
|
confirmMessage += "\n" + getString(R.string.constraintapllied);
|
||||||
|
|
||||||
|
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
|
||||||
|
|
||||||
|
final Context context = getContext();
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
|
||||||
|
builder.setTitle(this.getContext().getString(R.string.confirmation));
|
||||||
|
builder.setMessage(confirmMessage);
|
||||||
|
builder.setPositiveButton(getString(R.string.primefill), new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
if (finalInsulinAfterConstraints > 0) {
|
||||||
|
final ConfigBuilderPlugin pump = MainApp.getConfigBuilder();
|
||||||
|
mHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, 0, context, false);
|
||||||
|
if (!result.success) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
|
||||||
|
builder.setMessage(result.comment);
|
||||||
|
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(getString(R.string.cancel), null);
|
||||||
|
builder.show();
|
||||||
|
dismiss();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -390,6 +390,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
|
||||||
|
return deliverTreatment(insulin, carbs, context, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context, boolean createTreatment) {
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
insulin = applyBolusConstraints(insulin);
|
insulin = applyBolusConstraints(insulin);
|
||||||
carbs = applyCarbsConstraints(carbs);
|
carbs = applyCarbsConstraints(carbs);
|
||||||
|
@ -416,7 +420,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
if (Config.logCongigBuilderActions)
|
if (Config.logCongigBuilderActions)
|
||||||
log.debug("deliverTreatment insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered);
|
log.debug("deliverTreatment insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success && createTreatment) {
|
||||||
Treatment t = new Treatment();
|
Treatment t = new Treatment();
|
||||||
t.insulin = result.bolusDelivered;
|
t.insulin = result.bolusDelivered;
|
||||||
t.carbs = (double) result.carbsDelivered;
|
t.carbs = (double) result.carbsDelivered;
|
||||||
|
@ -435,6 +439,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopBolusDelivering() {
|
public void stopBolusDelivering() {
|
||||||
activePump.stopBolusDelivering();
|
activePump.stopBolusDelivering();
|
||||||
|
|
77
app/src/main/res/layout/actions_fill_dialog.xml
Normal file
77
app/src/main/res/layout/actions_fill_dialog.xml
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:text="@string/treatments_newtreatment_insulinamount_label"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/treatments_newtreatment_insulinamount_minus"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/circle"
|
||||||
|
android:backgroundTint="#ffffff"
|
||||||
|
android:src="@drawable/ic_action_minus"
|
||||||
|
android:tint="#ffffff" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/treatments_newtreatment_insulinamount"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:inputType="numberDecimal"
|
||||||
|
android:minWidth="200dp"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:text=""
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
android:gravity="center_horizontal" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/treatments_newtreatment_insulinamount_plus"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:background="@drawable/circle"
|
||||||
|
android:backgroundTint="#ffffff"
|
||||||
|
android:src="@drawable/ic_action_add"
|
||||||
|
android:tint="#ffffff" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/treatments_newtreatment_deliverbutton"
|
||||||
|
style="?android:attr/buttonStyle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:text="@string/primefill"
|
||||||
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -48,6 +48,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_fill"
|
||||||
|
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/primefill"
|
||||||
|
android:textColor="@color/colorTreatmentButton" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
|
@ -339,4 +339,6 @@
|
||||||
<string name="ns_upload_only">NS upload only (disabled sync)</string>
|
<string name="ns_upload_only">NS upload only (disabled sync)</string>
|
||||||
<string name="ns_upload_only_summary">NS upload only. Not effective on SGV unless a local source like xDrip is selected. Not effective on Profiles while NS-Profiles is used.</string>
|
<string name="ns_upload_only_summary">NS upload only. Not effective on SGV unless a local source like xDrip is selected. Not effective on Profiles while NS-Profiles is used.</string>
|
||||||
<string name="ns_upload_only_enabled">Please deactivate "NS upload only" to use this feature.</string>
|
<string name="ns_upload_only_enabled">Please deactivate "NS upload only" to use this feature.</string>
|
||||||
|
<string name="primefill">Prime/Fill</string>
|
||||||
|
<string name="fillwarning">Please make sure the amount matches the specification of your infusion set!</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue