extended bolus dialog

This commit is contained in:
Milos Kozak 2016-06-20 22:55:49 +02:00
parent 4645c2bc4d
commit fdf09b9daf
11 changed files with 246 additions and 12 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -334,7 +334,6 @@ public class DataService extends IntentService {
@Nullable
public static Treatment findById(String _id) {
try {
QueryBuilder<Treatment, String> qb = null;
Dao<Treatment, Long> daoTreatments = MainApp.getDbHelper().getDaoTreatments();
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
Where where = queryBuilder.where();

View file

@ -0,0 +1,96 @@
package info.nightscout.androidaps.plugins.Overview.Dialogs;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Result;
import info.nightscout.androidaps.interfaces.PumpInterface;
public class NewExtendedBolusDialog extends DialogFragment implements View.OnClickListener {
Button okButton;
EditText insulinEdit;
RadioButton h05Radio;
RadioButton h10Radio;
RadioButton h20Radio;
RadioButton h30Radio;
RadioButton h40Radio;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.overview_newextendedbolus_fragment, container, false);
okButton = (Button) view.findViewById(R.id.overview_newextendedbolus_okbutton);
insulinEdit = (EditText) view.findViewById(R.id.overview_newextendedbolus_insulin);
h05Radio = (RadioButton) view.findViewById(R.id.overview_newextendedbolus_05h);
h10Radio = (RadioButton) view.findViewById(R.id.overview_newextendedbolus_1h);
h20Radio = (RadioButton) view.findViewById(R.id.overview_newextendedbolus_2h);
h30Radio = (RadioButton) view.findViewById(R.id.overview_newextendedbolus_3h);
h40Radio = (RadioButton) view.findViewById(R.id.overview_newextendedbolus_4h);
okButton.setOnClickListener(this);
return view;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.overview_newextendedbolus_okbutton:
try {
int basalPercent = 100;
String insulinText = insulinEdit.getText().toString().replace(",", ".");
Double insulin = Double.parseDouble(!insulinText.equals("") ? insulinText : "0");
int durationInMinutes = 30;
if (h10Radio.isChecked()) durationInMinutes = 60;
if (h20Radio.isChecked()) durationInMinutes = 120;
if (h30Radio.isChecked()) durationInMinutes = 180;
if (h40Radio.isChecked()) durationInMinutes = 240;
String confirmMessage = getString(R.string.setextendedbolusquestion);
Double insulinAfterConstraint = MainActivity.getConfigBuilder().applyBolusConstraints(insulin);
confirmMessage += " " + insulinAfterConstraint + " U ";
confirmMessage += getString(R.string.duration) + " " + durationInMinutes + "min ?";
if (insulinAfterConstraint != insulin)
confirmMessage += "\n" + getString(R.string.constraintapllied);
insulin = insulinAfterConstraint;
final Double finalInsulin = insulin;
final int finalDurationInMinutes = durationInMinutes;
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(this.getContext().getString(R.string.confirmation));
builder.setMessage(confirmMessage);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
Result result = pump.setExtendedBolus(finalInsulin, finalDurationInMinutes);
if (!result.success) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror));
builder.setMessage(result.comment);
builder.setPositiveButton(getContext().getString(R.string.ok), null);
builder.show();
}
}
});
builder.setNegativeButton(getString(R.string.cancel), null);
builder.show();
dismiss();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View file

@ -64,12 +64,14 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
String confirmMessage = getString(R.string.setbasalquestion);
if (setAsPercent) {
basalPercent = MainActivity.getConfigBuilder().applyBasalConstraints(basal.intValue());
confirmMessage += " " + basalPercent + "% ?";
confirmMessage += "\n " + basalPercent + "% ";
confirmMessage += getString(R.string.duration) + " " + durationInMinutes + "min ?";
if (basalPercent != basal.intValue())
confirmMessage += "\n" + getString(R.string.constraintapllied);
} else {
Double basalAfterConstraint = MainActivity.getConfigBuilder().applyBasalConstraints(basal);
confirmMessage += " " + basalAfterConstraint + " U/h ?";
confirmMessage += "\n " + basalAfterConstraint + " U/h ";
confirmMessage += getString(R.string.duration) + " " + durationInMinutes + "min ?";
if (basalAfterConstraint != basal)
confirmMessage += "\n" + getString(R.string.constraintapllied);
basal = basalAfterConstraint;

View file

@ -1,9 +1,11 @@
package info.nightscout.androidaps.plugins.Overview.Dialogs;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.*;
@ -18,7 +20,9 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Result;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
@ -108,8 +112,48 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
switch (view.getId()) {
case R.id.treatments_wizard_deliverButton:
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d){
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
String confirmMessage = getString(R.string.entertreatmentquestion);
Double insulinAfterConstraints = MainActivity.getConfigBuilder().applyBolusConstraints(calculatedTotalInsulin);
Integer carbsAfterConstraints = MainActivity.getConfigBuilder().applyCarbsConstraints(calculatedCarbs);
confirmMessage += "\n" + getString(R.string.bolus) + ": " + formatNumber2decimalplaces.format(insulinAfterConstraints) + "U";
confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g";
if (insulinAfterConstraints != calculatedTotalInsulin || carbsAfterConstraints != calculatedCarbs) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror));
builder.setMessage(getString(R.string.constraints_violation) + "\n" + getString(R.string.changeyourinput));
builder.setPositiveButton(getContext().getString(R.string.ok), null);
builder.show();
return;
}
final Double finalInsulinAfterConstraints = insulinAfterConstraints;
final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(this.getContext().getString(R.string.confirmation));
builder.setMessage(confirmMessage);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
PumpInterface pump = MainActivity.getConfigBuilder().getActivePump();
Result result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints);
if (!result.success) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror));
builder.setMessage(result.comment);
builder.setPositiveButton(getContext().getString(R.string.ok), null);
builder.show();
}
}
}
});
builder.setNegativeButton(getString(R.string.cancel), null);
builder.show();
dismiss();
MainActivity.getConfigBuilder().getActivePump().deliverTreatment(calculatedTotalInsulin, calculatedCarbs);
}
break;
}
@ -169,10 +213,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
}
private void calculateInsulin() {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
Double maxbolus = Double.parseDouble(SP.getString("treatmentssafety_maxbolus", "3"));
Double maxcarbs = Double.parseDouble(SP.getString("treatmentssafety_maxcarbs", "48"));
NSProfile profile = MainActivity.getConfigBuilder().getActiveProfile().getProfile();
// Entered values
@ -186,12 +226,12 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
c_carbs = (Integer) Math.round(c_carbs);
Double c_correction = 0d;
try { c_correction = Double.parseDouble(i_correction.equals("") ? "0" : i_correction); } catch (Exception e) {}
if(c_correction > maxbolus) {
if(c_correction != MainActivity.getConfigBuilder().applyBolusConstraints(c_correction)) {
this.correctionInput.setText("");
wizardDialogDeliverButton.setVisibility(Button.GONE);
return;
}
if(c_carbs > maxcarbs) {
if(c_carbs != MainActivity.getConfigBuilder().applyCarbsConstraints(c_carbs)) {
this.carbsInput.setText("");
wizardDialogDeliverButton.setVisibility(Button.GONE);
return;

View file

@ -41,6 +41,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
@ -147,6 +148,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
cancelTempButton = (Button) view.findViewById(R.id.overview_canceltemp);
treatmentButton = (Button) view.findViewById(R.id.overview_treatment);
wizardButton = (Button) view.findViewById(R.id.overview_wizard);
setExtenedButton = (Button) view.findViewById(R.id.overview_extendedbolus);
setTempButton = (Button) view.findViewById(R.id.overview_settempbasal);
cancelTempButton = (Button) view.findViewById(R.id.overview_canceltemp);
setTempLayout = (LinearLayout) view.findViewById(R.id.overview_settemplayout);
@ -190,6 +192,15 @@ public class OverviewFragment extends Fragment implements PluginBase {
}
});
setExtenedButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentManager manager = getFragmentManager();
NewExtendedBolusDialog newExtendedDialog = new NewExtendedBolusDialog();
newExtendedDialog.show(manager, "NewExtendedDialog");
}
});
updateGUI();
return view;
}

View file

@ -14,6 +14,7 @@ import android.widget.TextView;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
@ -110,6 +111,8 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
*/
QueryBuilder<TempBasal, Long> queryBuilder = dao.queryBuilder();
queryBuilder.orderBy("timeIndex", false);
Where where = queryBuilder.where();
where.eq("isExtended", false);
queryBuilder.limit(30l);
PreparedQuery<TempBasal> preparedQuery = queryBuilder.prepare();
tempBasals = dao.query(preparedQuery);

View file

@ -306,6 +306,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
extendedBolus.isExtended = true;
extendedBolus.absolute = insulin * 60d / durationInMinutes;
extendedBolus.duration = durationInMinutes;
extendedBolus.isAbsolute = true;
result.success = true;
result.enacted = true;
result.comment = getString(R.string.virtualpump_resultok);

View file

@ -20,7 +20,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|top"
android:textSize="60dp" />
android:textSize="80dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"

View file

@ -0,0 +1,79 @@
<?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:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<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" />
<EditText
android:id="@+id/overview_newextendedbolus_insulin"
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" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.5 h"
android:id="@+id/overview_newextendedbolus_05h"
android:checked="true" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 h"
android:id="@+id/overview_newextendedbolus_1h" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2 h"
android:id="@+id/overview_newextendedbolus_2h" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3 h"
android:id="@+id/overview_newextendedbolus_3h" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4 h"
android:id="@+id/overview_newextendedbolus_4h" />
</RadioGroup>
<Button
android:id="@+id/overview_newextendedbolus_okbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="OK"
android:textSize="20sp" />
</LinearLayout>

View file

@ -140,5 +140,7 @@
<string name="entertreatmentquestion">Enter new treatment:</string>
<string name="bolus">Bolus</string>
<string name="carbs">Carbs</string>
<string name="changeyourinput">Change your input!</string>
<string name="setextendedbolusquestion">Set new extended bolus:</string>
</resources>