From e5bfa1fb1d65ee1376617fa49dc177d22dabfd45 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 23 Mar 2018 22:08:05 +0100 Subject: [PATCH 01/44] Show boluses with the precision the pump actually supports. --- .../info/nightscout/androidaps/db/Treatment.java | 2 +- .../androidaps/plugins/Loop/APSResult.java | 4 ++-- .../plugins/Overview/Dialogs/NewInsulinDialog.java | 6 ++++-- .../plugins/Overview/Dialogs/WizardDialog.java | 10 ++-------- .../plugins/Overview/OverviewFragment.java | 2 +- .../fragments/TreatmentsBolusFragment.java | 2 +- .../TreatmentsExtendedBolusesFragment.java | 2 +- .../info/nightscout/utils/DecimalFormatter.java | 14 ++++++++++++++ 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java index 4b4bfcb08d..bf65dcc043 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java @@ -128,7 +128,7 @@ public class Treatment implements DataPointWithLabelInterface { @Override public String getLabel() { String label = ""; - if (insulin > 0) label += DecimalFormatter.to2Decimal(insulin) + "U"; + if (insulin > 0) label += DecimalFormatter.toPumpSupportedBolus(insulin) + "U"; if (carbs > 0) label += "~" + DecimalFormatter.to0Decimal(carbs) + "g"; return label; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java index 9b851c64c1..7a9c4deae9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java @@ -62,7 +62,7 @@ public class APSResult { // smb if (smb != 0) - ret += ("SMB: " + DecimalFormatter.to2Decimal(smb) + " U\n"); + ret += ("SMB: " + DecimalFormatter.toPumpSupportedBolus(smb) + " U\n"); // reason ret += MainApp.sResources.getString(R.string.reason) + ": " + reason; @@ -87,7 +87,7 @@ public class APSResult { // smb if (smb != 0) - ret += ("" + "SMB" + ": " + DecimalFormatter.to2Decimal(smb) + " U
"); + ret += ("" + "SMB" + ": " + DecimalFormatter.toPumpSupportedBolus(smb) + " U
"); // reason ret += "" + MainApp.sResources.getString(R.string.reason) + ": " + reason.replace("<", "<").replace(">", ">"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java index 11eabfb3c6..6455a3cd0c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java @@ -48,6 +48,7 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DateUtil; +import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.NumberPicker; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; @@ -124,7 +125,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newinsulin_amount); - editInsulin.setParams(0d, 0d, maxInsulin, ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep, new DecimalFormat("0.00"), false, textWatcher); + editInsulin.setParams(0d, 0d, maxInsulin, ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep, DecimalFormatter.pumpSupportedBolusFormat(), false, textWatcher); dateButton = (TextView) view.findViewById(R.id.newinsulin_eventdate); timeButton = (TextView) view.findViewById(R.id.newinsulin_eventtime); @@ -160,7 +161,8 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, } private String toSignedString(double value) { - return value > 0 ? "+" + value : String.valueOf(value); + String formatted = DecimalFormatter.toPumpSupportedBolus(value); + return value < 0 ? "-" + formatted : formatted; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 34980b054a..6f6acc9dd3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -243,7 +243,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com editBg.setParams(0d, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, textWatcher); editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); double bolusstep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep; - editCorr.setParams(0d, -maxCorrection, maxCorrection, bolusstep, new DecimalFormat("0.00"), false, textWatcher); + editCorr.setParams(0d, -maxCorrection, maxCorrection, bolusstep, DecimalFormatter.pumpSupportedBolusFormat(), false, textWatcher); editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false); initDialog(); @@ -260,19 +260,13 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } private void saveCheckedStates() { - //SP.putBoolean(getString(R.string.key_wizard_include_bg), bgCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_cob), cobCheckbox.isChecked()); SP.putBoolean(getString(R.string.key_wizard_include_trend_bg), bgtrendCheckbox.isChecked()); - //SP.putBoolean(getString(R.string.key_wizard_include_bolus_iob), bolusIobCheckbox.isChecked()); - //SP.putBoolean(getString(R.string.key_wizard_include_basal_iob), basalIobCheckbox.isChecked()); } private void loadCheckedStates() { - //bgCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bg), true)); bgtrendCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_trend_bg), false)); cobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_cob), false)); - //bolusIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_bolus_iob), true)); - //basalIobCheckbox.setChecked(SP.getBoolean(getString(R.string.key_wizard_include_basal_iob), true)); } @Override @@ -534,7 +528,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) { - String insulinText = calculatedTotalInsulin > 0d ? (DecimalFormatter.to2Decimal(calculatedTotalInsulin) + "U") : ""; + String insulinText = calculatedTotalInsulin > 0d ? (DecimalFormatter.toPumpSupportedBolus(calculatedTotalInsulin) + "U") : ""; String carbsText = calculatedCarbs > 0d ? (DecimalFormatter.to0Decimal(calculatedCarbs) + "g") : ""; total.setText(MainApp.gs(R.string.result) + ": " + insulinText + " " + carbsText); okButton.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index dc0cb27ed7..cd5650ffa5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -1194,7 +1194,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, quickWizardButton.setVisibility(View.VISIBLE); String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g"; BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, lastBG, false); - text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U"; + text += " " + DecimalFormatter.toPumpSupportedBolus(wizard.calculatedTotalInsulin) + "U"; quickWizardButton.setText(text); if (wizard.calculatedTotalInsulin <= 0) quickWizardButton.setVisibility(View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java index baf1e43d55..39f659aefc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java @@ -76,7 +76,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View. return; Treatment t = treatments.get(position); holder.date.setText(DateUtil.dateAndTimeString(t.date)); - holder.insulin.setText(DecimalFormatter.to2Decimal(t.insulin) + " U"); + holder.insulin.setText(DecimalFormatter.toPumpSupportedBolus(t.insulin) + " U"); holder.carbs.setText(DecimalFormatter.to0Decimal(t.carbs) + " g"); Iob iob = t.iobCalc(System.currentTimeMillis(), profile.getDia()); holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " U"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java index 1cb6d04614..2bf7684c94 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java @@ -80,7 +80,7 @@ public class TreatmentsExtendedBolusesFragment extends SubscriberFragment { holder.date.setText(DateUtil.dateAndTimeString(extendedBolus.date) + " - " + DateUtil.timeString(extendedBolus.end())); } holder.duration.setText(DecimalFormatter.to0Decimal(extendedBolus.durationInMinutes) + " min"); - holder.insulin.setText(DecimalFormatter.to2Decimal(extendedBolus.insulin) + " U"); + holder.insulin.setText(DecimalFormatter.toPumpSupportedBolus(extendedBolus.insulin) + " U"); holder.realDuration.setText(DecimalFormatter.to0Decimal(extendedBolus.getRealDuration()) + " min"); IobTotal iob = extendedBolus.iobCalc(System.currentTimeMillis()); holder.iob.setText(DecimalFormatter.to2Decimal(iob.iob) + " U"); diff --git a/app/src/main/java/info/nightscout/utils/DecimalFormatter.java b/app/src/main/java/info/nightscout/utils/DecimalFormatter.java index 1a70b43c30..d821f5ba37 100644 --- a/app/src/main/java/info/nightscout/utils/DecimalFormatter.java +++ b/app/src/main/java/info/nightscout/utils/DecimalFormatter.java @@ -2,6 +2,8 @@ package info.nightscout.utils; import java.text.DecimalFormat; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; + /** * Created by mike on 11.07.2016. */ @@ -26,4 +28,16 @@ public class DecimalFormatter { public static String to3Decimal(double value) { return format3dec.format(value); } + + public static String toPumpSupportedBolus(double value) { + return ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep <= 0.01 + ? to2Decimal(value) + : to1Decimal(value); + } + + public static DecimalFormat pumpSupportedBolusFormat() { + return ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep <= 0.01 + ? new DecimalFormat("0.00") + : new DecimalFormat("0.0"); + } } From 9838e2fabb74741f33a3204c5c05a78390ff516e Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 23 Mar 2018 22:09:09 +0100 Subject: [PATCH 02/44] Rework prime/fill button. --- .../plugins/Actions/dialogs/FillDialog.java | 128 +++++++------ .../PumpVirtual/VirtualPumpPlugin.java | 2 +- .../java/info/nightscout/utils/NSUpload.java | 41 ++-- .../main/res/layout/actions_fill_dialog.xml | 177 ++++++++---------- app/src/main/res/layout/actions_fragment.xml | 2 +- app/src/main/res/values/strings.xml | 2 + 6 files changed, 175 insertions(+), 177 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java index c0e668439c..146831440c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java @@ -1,11 +1,11 @@ package info.nightscout.androidaps.plugins.Actions.dialogs; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; +import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -13,17 +13,23 @@ import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.Button; +import android.widget.CheckBox; import com.crashlytics.android.answers.CustomEvent; +import com.google.common.base.Joiner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.Constants; import java.text.DecimalFormat; +import java.util.LinkedList; +import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; @@ -31,6 +37,7 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.FabricPrivacy; +import info.nightscout.utils.NSUpload; import info.nightscout.utils.NumberPicker; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; @@ -38,13 +45,13 @@ import info.nightscout.utils.SafeParse; public class FillDialog extends DialogFragment implements OnClickListener { private static Logger log = LoggerFactory.getLogger(FillDialog.class); - Button deliverButton; - double amount1 = 0d; double amount2 = 0d; double amount3 = 0d; NumberPicker editInsulin; + CheckBox pumpSiteChangeCheckbox; + CheckBox insulinCartridgeChangeCheckbox; public FillDialog() { } @@ -54,22 +61,24 @@ public class FillDialog extends DialogFragment implements OnClickListener { Bundle savedInstanceState) { View view = inflater.inflate(R.layout.actions_fill_dialog, null, false); - deliverButton = (Button) view.findViewById(R.id.treatments_newtreatment_deliverbutton); + view.findViewById(R.id.ok).setOnClickListener(this); + view.findViewById(R.id.cancel).setOnClickListener(this); - deliverButton.setOnClickListener(this); getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); + pumpSiteChangeCheckbox = view.findViewById(R.id.catheter_change); + insulinCartridgeChangeCheckbox = view.findViewById(R.id.cartridge_change); + Double maxInsulin = MainApp.getConstraintChecker().getMaxBolusAllowed().value(); double bolusstep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep; - editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newtreatment_insulinamount); - editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, new DecimalFormat("0.00"), false); + editInsulin = view.findViewById(R.id.treatments_newtreatment_insulinamount); + editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, DecimalFormatter.pumpSupportedBolusFormat(), 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); amount1 = SP.getDouble("fill_button1", 0.3); amount2 = SP.getDouble("fill_button2", 0d); @@ -77,103 +86,108 @@ public class FillDialog extends DialogFragment implements OnClickListener { if (amount1 > 0) { button1.setVisibility(View.VISIBLE); - button1.setText(DecimalFormatter.to2Decimal(amount1) + "U"); + button1.setText(DecimalFormatter.toPumpSupportedBolus(amount1)); // + "U"); button1.setOnClickListener(this); } else { button1.setVisibility(View.GONE); } if (amount2 > 0) { button2.setVisibility(View.VISIBLE); - button2.setText(DecimalFormatter.to2Decimal(amount2) + "U"); + button2.setText(DecimalFormatter.toPumpSupportedBolus(amount2)); // + "U"); button2.setOnClickListener(this); } else { button2.setVisibility(View.GONE); } if (amount3 > 0) { button3.setVisibility(View.VISIBLE); - button3.setText(DecimalFormatter.to2Decimal(amount3) + "U"); + button3.setText(DecimalFormatter.toPumpSupportedBolus(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); - } - setCancelable(true); getDialog().setCanceledOnTouchOutside(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: - Double insulin = SafeParse.stringToDouble(editInsulin.getText().toString()); - confirmAndDeliver(insulin); + case R.id.ok: + confirmAndDeliver(); + break; + case R.id.cancel: + dismiss(); break; case R.id.fill_preset_button1: - confirmAndDeliver(amount1); + editInsulin.setValue(amount1); break; case R.id.fill_preset_button2: - confirmAndDeliver(amount2); + editInsulin.setValue(amount2); break; case R.id.fill_preset_button3: - confirmAndDeliver(amount3); + editInsulin.setValue(amount3); break; } } - private void confirmAndDeliver(Double insulin) { + private void confirmAndDeliver() { try { + Double insulin = SafeParse.stringToDouble(editInsulin.getText()); - String confirmMessage = getString(R.string.fillwarning) + "\n"; + List confirmMessage = new LinkedList<>(); Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(insulin)).value(); - confirmMessage += getString(R.string.bolus) + ": " + insulinAfterConstraints + "U"; - if (insulinAfterConstraints - insulin != 0) - confirmMessage += "\n" + getString(R.string.constraintapllied); + if (insulinAfterConstraints > 0) { + confirmMessage.add(MainApp.gs(R.string.fillwarning)); + confirmMessage.add(""); + confirmMessage.add(MainApp.gs(R.string.bolus) + ": " + "" + insulinAfterConstraints + "U" + ""); + if (!insulinAfterConstraints.equals(insulin)) + confirmMessage.add("" + MainApp.gs(R.string.bolusconstraintapplied) + ""); + } + + if (pumpSiteChangeCheckbox.isChecked()) + confirmMessage.add("" + "" + getString(R.string.record_pump_site_change) + ""); + + if (insulinCartridgeChangeCheckbox.isChecked()) + confirmMessage.add("" + "" + getString(R.string.record_insulin_cartridge_change) + ""); 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) { - DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - detailedBolusInfo.insulin = finalInsulinAfterConstraints; - detailedBolusInfo.context = context; - detailedBolusInfo.source = Source.USER; - detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history) - ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() { - @Override - public void run() { - if (!result.success) { - Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); - i.putExtra("soundid", R.raw.boluserror); - i.putExtra("status", result.comment); - i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - MainApp.instance().startActivity(i); - } + if (confirmMessage.isEmpty()) + confirmMessage.add(MainApp.gs(R.string.no_action_selected)); + + builder.setTitle(MainApp.gs(R.string.confirmation)); + builder.setMessage(Html.fromHtml(Joiner.on("
").join(confirmMessage))); + builder.setPositiveButton(getString(R.string.primefill), (dialog, id) -> { + if (finalInsulinAfterConstraints > 0) { + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + detailedBolusInfo.insulin = finalInsulinAfterConstraints; + detailedBolusInfo.context = context; + detailedBolusInfo.source = Source.USER; + detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history) + ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() { + @Override + public void run() { + if (!result.success) { + Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); + i.putExtra("soundid", R.raw.boluserror); + i.putExtra("status", result.comment); + i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror)); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + MainApp.instance().startActivity(i); } - }); - FabricPrivacy.getInstance().logCustom(new CustomEvent("Fill")); - } + } + }); + FabricPrivacy.getInstance().logCustom(new CustomEvent("Fill")); } + if (pumpSiteChangeCheckbox.isChecked()) NSUpload.uploadEvent(CareportalEvent.SITECHANGE); + if (insulinCartridgeChangeCheckbox.isChecked()) NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE); }); builder.setNegativeButton(getString(R.string.cancel), null); builder.show(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index 00ff2fc7a4..480736ec95 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -98,7 +98,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { pumpDescription.basalStep = 0.01d; pumpDescription.basalMinimumRate = 0.01d; - pumpDescription.isRefillingCapable = false; + pumpDescription.isRefillingCapable = true; pumpDescription.storesCarbInfo = false; pumpDescription.is30minBasalRatesCapable = true; diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index a75377aae1..a102d28b1b 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -16,8 +16,10 @@ import org.slf4j.LoggerFactory; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -384,39 +386,32 @@ public class NSUpload { } public static void uploadOpenAPSOffline(double durationInMinutes) { - try { - Context context = MainApp.instance().getApplicationContext(); - JSONObject data = new JSONObject(); - data.put("eventType", "OpenAPS Offline"); - data.put("duration", durationInMinutes); - data.put("created_at", DateUtil.toISOString(new Date())); - data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name)); - Bundle bundle = new Bundle(); - bundle.putString("action", "dbAdd"); - bundle.putString("collection", "treatments"); - bundle.putString("data", data.toString()); - Intent intent = new Intent(Intents.ACTION_DATABASE); - intent.putExtras(bundle); - intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); - DbLogger.dbAdd(intent, data.toString()); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } + Map map = new HashMap<>(); + map.put("duration", durationInMinutes); + uploadEvent(CareportalEvent.OPENAPSOFFLINE, map); } public static void uploadError(String error) { + HashMap map = new HashMap<>(); + map.put("notes", error); + map.put("isAnnouncement", true); + uploadEvent(CareportalEvent.ANNOUNCEMENT, map); + } + + public static void uploadEvent(String event) { + uploadEvent(event, null); + } + + public static void uploadEvent(String event, Map map) { Context context = MainApp.instance().getApplicationContext(); Bundle bundle = new Bundle(); bundle.putString("action", "dbAdd"); bundle.putString("collection", "treatments"); - JSONObject data = new JSONObject(); + JSONObject data = map != null ? new JSONObject(map) : new JSONObject(); try { - data.put("eventType", "Announcement"); + data.put("eventType", event); data.put("created_at", DateUtil.toISOString(new Date())); data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name))); - data.put("notes", error); - data.put("isAnnouncement", true); } catch (JSONException e) { log.error("Unhandled exception", e); } diff --git a/app/src/main/res/layout/actions_fill_dialog.xml b/app/src/main/res/layout/actions_fill_dialog.xml index 55e44f4bc7..18a5886246 100644 --- a/app/src/main/res/layout/actions_fill_dialog.xml +++ b/app/src/main/res/layout/actions_fill_dialog.xml @@ -1,110 +1,97 @@ - + - - - + android:orientation="vertical" + android:focusableInTouchMode="true" + android:padding="10dp"> - + - + - + - + -