commit
0b56b7554c
5 changed files with 180 additions and 44 deletions
|
@ -98,6 +98,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
addPreferencesFromResource(R.xml.pref_mm640g);
|
||||
if (Config.SMSCOMMUNICATORENABLED)
|
||||
addPreferencesFromResource(R.xml.pref_smscommunicator);
|
||||
addPreferencesFromResource(R.xml.pref_others);
|
||||
initSummary(getPreferenceScreen());
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@ package info.nightscout.androidaps.plugins.Actions.dialogs;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -24,6 +26,7 @@ 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.DecimalFormatter;
|
||||
import info.nightscout.utils.PlusMinusEditText;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
|
||||
|
@ -32,6 +35,10 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
|||
Button deliverButton;
|
||||
TextView insulin;
|
||||
|
||||
double amount1 = 0d;
|
||||
double amount2 = 0d;
|
||||
double amount3 = 0d;
|
||||
|
||||
PlusMinusEditText editInsulin;
|
||||
|
||||
Handler mHandler;
|
||||
|
@ -59,6 +66,42 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
|||
|
||||
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);
|
||||
|
||||
//setup preset buttons
|
||||
Button button1 = (Button) view.findViewById(R.id.fill_preset_button1);
|
||||
Button button2 = (Button) view.findViewById(R.id.fill_preset_button2);
|
||||
Button button3 = (Button) view.findViewById(R.id.fill_preset_button3);
|
||||
View divider = view.findViewById(R.id.fill_preset_divider);
|
||||
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
amount1 = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button1", "0.3"))));
|
||||
amount2 = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button2", "0"))));
|
||||
amount3 = SafeParse.stringToDouble(DecimalFormatter.to2Decimal(SafeParse.stringToDouble(sp.getString("fill_button3", "0"))));
|
||||
|
||||
if(amount1 >0) {
|
||||
button1.setVisibility(View.VISIBLE);
|
||||
button1.setText(DecimalFormatter.to2Decimal(amount1) + "U");
|
||||
button1.setOnClickListener(this);
|
||||
} else {
|
||||
button1.setVisibility(View.GONE);
|
||||
}
|
||||
if(amount2 >0) {
|
||||
button2.setVisibility(View.VISIBLE);
|
||||
button2.setText(DecimalFormatter.to2Decimal(amount2) + "U");
|
||||
button2.setOnClickListener(this);
|
||||
} else {
|
||||
button2.setVisibility(View.GONE);
|
||||
}
|
||||
if(amount3 >0) {
|
||||
button3.setVisibility(View.VISIBLE);
|
||||
button3.setText(DecimalFormatter.to2Decimal(amount3) + "U");
|
||||
button3.setOnClickListener(this);
|
||||
} else {
|
||||
button3.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (button1.getVisibility() == View.GONE && button2.getVisibility() == View.GONE && button3.getVisibility() == View.GONE ) {
|
||||
divider.setVisibility(View.GONE);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -73,53 +116,65 @@ public class FillDialog extends DialogFragment implements OnClickListener {
|
|||
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();
|
||||
}
|
||||
Double insulin = SafeParse.stringToDouble(this.insulin.getText().toString());
|
||||
confirmAndDeliver(insulin);
|
||||
break;
|
||||
case R.id.fill_preset_button1:
|
||||
confirmAndDeliver(amount1);
|
||||
break;
|
||||
case R.id.fill_preset_button2:
|
||||
confirmAndDeliver(amount2);
|
||||
break;
|
||||
case R.id.fill_preset_button3:
|
||||
confirmAndDeliver(amount3);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void confirmAndDeliver(Double insulin) {
|
||||
try {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -73,5 +73,52 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/fill_preset_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@android:color/darker_gray"/>
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_gravity="center_horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/fill_preset_button1"
|
||||
style="?android:attr/buttonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.3"
|
||||
android:padding="10dp"
|
||||
android:text="0.3U"
|
||||
android:textSize="20sp" />
|
||||
<Button
|
||||
android:id="@+id/fill_preset_button2"
|
||||
style="?android:attr/buttonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.3"
|
||||
android:padding="10dp"
|
||||
android:text="0.7U"
|
||||
android:textSize="20sp" />
|
||||
<Button
|
||||
android:id="@+id/fill_preset_button3"
|
||||
style="?android:attr/buttonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.3"
|
||||
android:padding="10dp"
|
||||
android:text="1.2U"
|
||||
android:textSize="20sp" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
|
@ -342,4 +342,9 @@
|
|||
<string name="pumpNotInitialized">Pump not initialized!</string>
|
||||
<string name="primefill">Prime/Fill</string>
|
||||
<string name="fillwarning">Please make sure the amount matches the specification of your infusion set!</string>
|
||||
<string name="othersettings_title">Other</string>
|
||||
<string name="fillbolus_title">Fill/Prime standard insulin amounts.</string>
|
||||
<string name="button1">Button 1</string>
|
||||
<string name="button2">Button 2</string>
|
||||
<string name="button3">Button 3</string>
|
||||
</resources>
|
||||
|
|
28
app/src/main/res/xml/pref_others.xml
Normal file
28
app/src/main/res/xml/pref_others.xml
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory
|
||||
android:key="others"
|
||||
android:title="@string/othersettings_title">
|
||||
<PreferenceScreen
|
||||
android:title="@string/fillbolus_title">
|
||||
<EditTextPreference
|
||||
android:title="@string/button1"
|
||||
android:key="fill_button1"
|
||||
android:defaultValue="0.3"
|
||||
android:inputType="numberDecimal">
|
||||
</EditTextPreference>
|
||||
<EditTextPreference
|
||||
android:title="@string/button2"
|
||||
android:key="fill_button2"
|
||||
android:defaultValue="0"
|
||||
android:inputType="numberDecimal">
|
||||
</EditTextPreference>
|
||||
<EditTextPreference
|
||||
android:title="@string/button3"
|
||||
android:key="fill_button3"
|
||||
android:defaultValue="0"
|
||||
android:inputType="numberDecimal">
|
||||
</EditTextPreference>
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
Loading…
Reference in a new issue