temp basal dialog plus/minus buttons

This commit is contained in:
Milos Kozak 2016-07-03 13:25:23 +02:00
parent 000fafced3
commit 5cad7f1cb4
9 changed files with 195 additions and 57 deletions

View file

@ -23,8 +23,8 @@ android {
applicationId "info.nightscout.androidaps" applicationId "info.nightscout.androidaps"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 23 targetSdkVersion 23
versionCode 1002 versionCode 1003
versionName "1.0.02" versionName "1.0.03"
} }
buildTypes { buildTypes {
release { release {

View file

@ -30,6 +30,8 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
getDialog().setTitle(getString(R.string.overview_extendedbolus_button));
View view = inflater.inflate(R.layout.overview_newextendedbolus_fragment, container, false); View view = inflater.inflate(R.layout.overview_newextendedbolus_fragment, container, false);
okButton = (Button) view.findViewById(R.id.overview_newextendedbolus_okbutton); okButton = (Button) view.findViewById(R.id.overview_newextendedbolus_okbutton);
insulinEdit = (EditText) view.findViewById(R.id.overview_newextendedbolus_insulin); insulinEdit = (EditText) view.findViewById(R.id.overview_newextendedbolus_insulin);

View file

@ -9,41 +9,73 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RadioGroup;
import java.text.DecimalFormat;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.PlusMinusEditText;
import info.nightscout.utils.SafeParse; import info.nightscout.utils.SafeParse;
public class NewTempBasalDialog extends DialogFragment implements View.OnClickListener { public class NewTempBasalDialog extends DialogFragment implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
Button okButton; Button okButton;
EditText basalEdit; EditText basalPercentEdit;
EditText basalAbsoluteEdit;
RadioButton percentRadio; RadioButton percentRadio;
RadioButton absoluteRadio; RadioButton absoluteRadio;
RadioGroup basalTypeRadioGroup;
RadioButton h05Radio; RadioButton h05Radio;
RadioButton h10Radio; RadioButton h10Radio;
RadioButton h20Radio; RadioButton h20Radio;
RadioButton h30Radio; RadioButton h30Radio;
RadioButton h40Radio; RadioButton h40Radio;
LinearLayout percentLayout;
LinearLayout absoluteLayout;
PlusMinusEditText basalPercentPM;
PlusMinusEditText basalAbsolutePM;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
getDialog().setTitle(getString(R.string.overview_tempbasal_button));
View view = inflater.inflate(R.layout.overview_newtempbasal_fragment, container, false); View view = inflater.inflate(R.layout.overview_newtempbasal_fragment, container, false);
okButton = (Button) view.findViewById(R.id.overview_newtempbasal_okbutton); okButton = (Button) view.findViewById(R.id.overview_newtempbasal_okbutton);
basalEdit = (EditText) view.findViewById(R.id.overview_newtempbasal_basal); basalPercentEdit = (EditText) view.findViewById(R.id.overview_newtempbasal_basalpercentinput);
percentRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_percent); basalAbsoluteEdit = (EditText) view.findViewById(R.id.overview_newtempbasal_basalabsoluteinput);
absoluteRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_absolute); percentLayout = (LinearLayout) view.findViewById(R.id.overview_newtempbasal_percent_layout);
absoluteLayout = (LinearLayout) view.findViewById(R.id.overview_newtempbasal_absolute_layout);
percentRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_percent_radio);
basalTypeRadioGroup = (RadioGroup) view.findViewById(R.id.overview_newtempbasal_radiogroup);
absoluteRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_absolute_radio);
h05Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_05h); h05Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_05h);
h10Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_1h); h10Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_1h);
h20Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_2h); h20Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_2h);
h30Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_3h); h30Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_3h);
h40Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_4h); h40Radio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_4h);
Integer maxPercent = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalPercentOnlyForCheckLimit);
basalPercentPM = new PlusMinusEditText(view, R.id.overview_newtempbasal_basalpercentinput, R.id.overview_newtempbasal_basalpercent_plus, R.id.overview_newtempbasal_basalpercent_minus, 100d, 0d, (double) maxPercent, 5d, new DecimalFormat("0"), true);
Double maxAbsolute = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalAbsoluteOnlyForCheckLimit);
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
Double currentBasal = 0d;
if (profile != null) currentBasal = profile.getBasal(NSProfile.secondsFromMidnight());
basalAbsolutePM = new PlusMinusEditText(view, R.id.overview_newtempbasal_basalabsoluteinput, R.id.overview_newtempbasal_basalabsolute_plus, R.id.overview_newtempbasal_basalabsolute_minus, currentBasal, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true);
absoluteLayout.setVisibility(View.GONE);
okButton.setOnClickListener(this); okButton.setOnClickListener(this);
basalTypeRadioGroup.setOnCheckedChangeListener(this);
return view; return view;
} }
@ -52,8 +84,8 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
switch (view.getId()) { switch (view.getId()) {
case R.id.overview_newtempbasal_okbutton: case R.id.overview_newtempbasal_okbutton:
try { try {
int basalPercent = 100; int basalPercent = 0;
Double basal = SafeParse.stringToDouble(basalEdit.getText().toString()); Double basalAbsolute = 0d;
final boolean setAsPercent = percentRadio.isChecked(); final boolean setAsPercent = percentRadio.isChecked();
int durationInMinutes = 30; int durationInMinutes = 30;
if (h10Radio.isChecked()) durationInMinutes = 60; if (h10Radio.isChecked()) durationInMinutes = 60;
@ -63,22 +95,23 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
String confirmMessage = getString(R.string.setbasalquestion); String confirmMessage = getString(R.string.setbasalquestion);
if (setAsPercent) { if (setAsPercent) {
basalPercent = MainApp.getConfigBuilder().applyBasalConstraints(basal.intValue()); int basalPercentInput = SafeParse.stringToDouble(basalPercentEdit.getText().toString()).intValue();
confirmMessage += "\n " + basalPercent + "% "; basalPercent = MainApp.getConfigBuilder().applyBasalConstraints(basalPercentInput);
confirmMessage += getString(R.string.duration) + " " + durationInMinutes + "min ?"; confirmMessage += "\n" + basalPercent + "% ";
if (basalPercent != basal.intValue()) confirmMessage += "\n" + getString(R.string.duration) + " " + durationInMinutes + "min ?";
if (basalPercent != basalPercentInput)
confirmMessage += "\n" + getString(R.string.constraintapllied); confirmMessage += "\n" + getString(R.string.constraintapllied);
} else { } else {
Double basalAfterConstraint = MainApp.getConfigBuilder().applyBasalConstraints(basal); Double basalAbsoluteInput = SafeParse.stringToDouble(basalAbsoluteEdit.getText().toString());
confirmMessage += "\n " + basalAfterConstraint + " U/h "; basalAbsolute = MainApp.getConfigBuilder().applyBasalConstraints(basalAbsoluteInput);
confirmMessage += getString(R.string.duration) + " " + durationInMinutes + "min ?"; confirmMessage += "\n" + basalAbsolute + " U/h ";
if (basalAfterConstraint != basal) confirmMessage += "\n" + getString(R.string.duration) + " " + durationInMinutes + "min ?";
if (basalAbsolute - basalAbsoluteInput != 0d)
confirmMessage += "\n" + getString(R.string.constraintapllied); confirmMessage += "\n" + getString(R.string.constraintapllied);
basal = basalAfterConstraint;
} }
final int finalBasalPercent = basalPercent; final int finalBasalPercent = basalPercent;
final Double finalBasal = basal; final Double finalBasal = basalAbsolute;
final int finalDurationInMinutes = durationInMinutes; final int finalDurationInMinutes = durationInMinutes;
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
@ -111,4 +144,18 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
} }
} }
} }
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.overview_newtempbasal_percent_radio:
percentLayout.setVisibility(View.VISIBLE);
absoluteLayout.setVisibility(View.GONE);
break;
case R.id.overview_newtempbasal_absolute_radio:
percentLayout.setVisibility(View.GONE);
absoluteLayout.setVisibility(View.VISIBLE);
break;
}
}
} }

View file

@ -317,7 +317,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) { if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
String insulinText = calculatedTotalInsulin > 0d ? (numberFormat.format(calculatedTotalInsulin) + "U") : ""; String insulinText = calculatedTotalInsulin > 0d ? (numberFormat.format(calculatedTotalInsulin) + "U") : "";
String carbsText = calculatedCarbs > 0d ? (intFormat.format(calculatedCarbs) + "g") : ""; String carbsText = calculatedCarbs > 0d ? (intFormat.format(calculatedCarbs) + "g") : "";
wizardDialogDeliverButton.setText("SEND " + insulinText + " " + carbsText); wizardDialogDeliverButton.setText(getString(R.string.send) + " " + insulinText + " " + carbsText);
wizardDialogDeliverButton.setVisibility(Button.VISIBLE); wizardDialogDeliverButton.setVisibility(Button.VISIBLE);
} else { } else {
wizardDialogDeliverButton.setVisibility(Button.INVISIBLE); wizardDialogDeliverButton.setVisibility(Button.INVISIBLE);

View file

@ -22,7 +22,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="NSClient version:" /> android:text="@string/configbuilder_nsclientversion_label" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -42,7 +42,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Nightscout version:" /> android:text="@string/configbuilder_nightscoutversion_label" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -12,24 +12,25 @@
android:orientation="horizontal"> android:orientation="horizontal">
<RadioGroup <RadioGroup
android:id="@+id/overview_newtempbasal_radiogroup"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<RadioButton <RadioButton
android:id="@+id/overview_newtempbasal_percent" android:id="@+id/overview_newtempbasal_percent_radio"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/overview_newtempbasal_percent_label" android:layout_marginRight="20dp"
android:checked="true" android:checked="true"
android:layout_marginRight="20dp" /> android:text="@string/overview_newtempbasal_percent_label" />
<RadioButton <RadioButton
android:id="@+id/overview_newtempbasal_absolute" android:id="@+id/overview_newtempbasal_absolute_radio"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="U/h" android:layout_marginLeft="20dp"
android:layout_marginLeft="20dp" /> android:text="U/h" />
</RadioGroup> </RadioGroup>
</LinearLayout> </LinearLayout>
@ -47,16 +48,99 @@
android:text="@string/overview_newtempbasal_basal_label" android:text="@string/overview_newtempbasal_basal_label"
android:textAppearance="?android:attr/textAppearanceLarge" /> android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:id="@+id/overview_newtempbasal_percent_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<ImageView
android:id="@+id/overview_newtempbasal_basalpercent_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"
android:layout_weight="0.5" />
<EditText <EditText
android:id="@+id/overview_newtempbasal_basal" android:id="@+id/overview_newtempbasal_basalpercentinput"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:inputType="numberDecimal" android:inputType="numberDecimal"
android:minWidth="200dp" android:minWidth="100dp"
android:padding="10dp" android:padding="10dp"
android:text="" android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" /> android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_horizontal" />
<ImageView
android:id="@+id/overview_newtempbasal_basalpercent_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"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:id="@+id/overview_newtempbasal_absolute_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<ImageView
android:id="@+id/overview_newtempbasal_basalabsolute_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"
android:layout_weight="0.5" />
<EditText
android:id="@+id/overview_newtempbasal_basalabsoluteinput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:inputType="numberDecimal"
android:minWidth="100dp"
android:padding="10dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_horizontal" />
<ImageView
android:id="@+id/overview_newtempbasal_basalabsolute_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"
android:layout_weight="0.5" />
</LinearLayout>
</LinearLayout> </LinearLayout>
<RadioGroup <RadioGroup
@ -65,35 +149,35 @@
android:layout_gravity="center_horizontal"> android:layout_gravity="center_horizontal">
<RadioButton <RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.5 h"
android:id="@+id/overview_newtempbasal_05h" android:id="@+id/overview_newtempbasal_05h"
android:checked="true" />
<RadioButton
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="1 h" android:checked="true"
android:id="@+id/overview_newtempbasal_1h" /> android:text="0.5 h" />
<RadioButton <RadioButton
android:id="@+id/overview_newtempbasal_1h"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="2 h" android:text="1 h" />
android:id="@+id/overview_newtempbasal_2h" />
<RadioButton <RadioButton
android:id="@+id/overview_newtempbasal_2h"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="3 h" android:text="2 h" />
android:id="@+id/overview_newtempbasal_3h" />
<RadioButton <RadioButton
android:id="@+id/overview_newtempbasal_3h"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="4 h" android:text="3 h" />
android:id="@+id/overview_newtempbasal_4h" />
<RadioButton
android:id="@+id/overview_newtempbasal_4h"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4 h" />
</RadioGroup> </RadioGroup>
<Button <Button

View file

@ -202,7 +202,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/treatments_wizard_bg_label" android:text="@string/treatments_wizard_bg_label"
android:width="50dp" android:width="80dp"
android:id="@+id/textView" /> android:id="@+id/textView" />
<TextView <TextView
@ -237,7 +237,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/treatments_wizard_carbs_label" android:text="@string/treatments_wizard_carbs_label"
android:width="50dp" /> android:width="80dp" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -273,7 +273,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/treatments_wizard_bolusiob_label" android:text="@string/treatments_wizard_bolusiob_label"
android:width="100dp" /> android:width="130dp" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -309,7 +309,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/treatments_wizard_basaliob_label" android:text="@string/treatments_wizard_basaliob_label"
android:width="100dp" /> android:width="130dp" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -343,7 +343,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/treatments_wizard_correction_label" android:text="@string/treatments_wizard_correction_label"
android:width="50dp" /> android:width="80dp" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -378,7 +378,7 @@
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold" android:textStyle="bold"
android:text="@string/treatments_wizard_total_label" android:text="@string/treatments_wizard_total_label"
android:width="50dp" android:width="80dp"
android:height="30dp" android:height="30dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:textColor="@color/accent_material_light" /> android:textColor="@color/accent_material_light" />

View file

@ -4,7 +4,6 @@
<string name="closedloop">Uzavřená smyčka</string> <string name="closedloop">Uzavřená smyčka</string>
<string name="openloop">Otevřená smyčka</string> <string name="openloop">Otevřená smyčka</string>
<string name="alert">Výstaha</string> <string name="alert">Výstaha</string>
<string name="apsmode_summary">Typ smyčky</string>
<string name="apsmode_title">Typ smyčky</string> <string name="apsmode_title">Typ smyčky</string>
<string name="avgdelta">Prům. změna</string> <string name="avgdelta">Prům. změna</string>
<string name="basal">Bazál</string> <string name="basal">Bazál</string>
@ -193,4 +192,7 @@
<string name="careportal_newnstreatment_glucosetype">Zadání glykémie</string> <string name="careportal_newnstreatment_glucosetype">Zadání glykémie</string>
<string name="title_activity_main">AndroidAPS</string> <string name="title_activity_main">AndroidAPS</string>
<string name="openapsma">OpenAPS MA</string> <string name="openapsma">OpenAPS MA</string>
<string name="configbuilder_nightscoutversion_label">Verze Nightscoutu:</string>
<string name="configbuilder_nsclientversion_label">Verze NSClienta:</string>
<string name="send">POSLAT</string>
</resources> </resources>

View file

@ -200,5 +200,8 @@
<string name="noprofile">No profile loaded from NS yet</string> <string name="noprofile">No profile loaded from NS yet</string>
<string name="overview_tempbasal_button">TempBasal</string> <string name="overview_tempbasal_button">TempBasal</string>
<string name="overview_extendedbolus_button">Extended Bolus</string> <string name="overview_extendedbolus_button">Extended Bolus</string>
<string name="configbuilder_nsclientversion_label">NSClient version:</string>
<string name="configbuilder_nightscoutversion_label">Nightscout version:</string>
<string name="send">SEND</string>
</resources> </resources>