Merge branch 'dev' into smb060

This commit is contained in:
Milos Kozak 2017-12-26 00:35:16 +01:00
commit 162e73e64d
13 changed files with 538 additions and 168 deletions

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.Overview;
package info.nightscout.androidaps.data;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
@ -9,11 +9,7 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.utils.DateUtil;
/**
* Created by mike on 12.10.2016.
@ -22,84 +18,7 @@ import info.nightscout.utils.DateUtil;
public class QuickWizard {
private static Logger log = LoggerFactory.getLogger(QuickWizard.class);
public class QuickWizardEntry {
public JSONObject storage;
public int position;
/*
{
buttonText: "Meal",
carbs: 36,
validFrom: 8 * 60 * 60, // seconds from midnight
validTo: 9 * 60 * 60, // seconds from midnight
}
*/
public QuickWizardEntry() {
String emptyData = "{\"buttonText\":\"\",\"carbs\":0,\"validFrom\":0,\"validTo\":86340}";
try {
storage = new JSONObject(emptyData);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
position = -1;
}
public QuickWizardEntry(JSONObject entry, int position) {
storage = entry;
this.position = position;
}
public Boolean isActive() {
return Profile.secondsFromMidnight() >= validFrom() && Profile.secondsFromMidnight() <= validTo();
}
public String buttonText() {
try {
return storage.getString("buttonText");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return "";
}
public Integer carbs() {
try {
return storage.getInt("carbs");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return 0;
}
public Date validFromDate() {
return DateUtil.toDate(validFrom());
}
public Date validToDate() {
return DateUtil.toDate(validTo());
}
public Integer validFrom() {
try {
return storage.getInt("validFrom");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return 0;
}
public Integer validTo() {
try {
return storage.getInt("validTo");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return 0;
}
}
JSONArray storage = new JSONArray();
private JSONArray storage = new JSONArray();
public void setData(JSONArray newData) {
storage = newData;

View file

@ -0,0 +1,242 @@
package info.nightscout.androidaps.data;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP;
/**
* Created by mike on 25.12.2017.
*/
public class QuickWizardEntry {
private static Logger log = LoggerFactory.getLogger(QuickWizardEntry.class);
public JSONObject storage;
public int position;
public static final int YES = 0;
public static final int NO = 1;
public static final int POSITIVE_ONLY = 2;
public static final int NEGATIVE_ONLY = 3;
/*
{
buttonText: "Meal",
carbs: 36,
validFrom: 8 * 60 * 60, // seconds from midnight
validTo: 9 * 60 * 60, // seconds from midnight
useBG: 0,
useCOB: 0,
useBolusIOB: 0,
useBasalIOB: 0,
useTrend: 0,
useSuperBolus: 0,
useTemptarget: 0
}
*/
public QuickWizardEntry() {
String emptyData = "{\"buttonText\":\"\",\"carbs\":0,\"validFrom\":0,\"validTo\":86340}";
try {
storage = new JSONObject(emptyData);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
position = -1;
}
public QuickWizardEntry(JSONObject entry, int position) {
storage = entry;
this.position = position;
}
public Boolean isActive() {
return Profile.secondsFromMidnight() >= validFrom() && Profile.secondsFromMidnight() <= validTo();
}
public BolusWizard doCalc(Profile profile, TempTarget tempTarget, BgReading lastBG) {
BolusWizard wizard = new BolusWizard();
//BG
double bg = 0;
if (lastBG != null && useBG() == YES) {
bg = lastBG.valueToUnits(profile.getUnits());
}
// COB
double cob = 0d;
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis());
if (autosensData != null && useCOB() == YES) {
cob = autosensData.cob;
}
// Temp target
if (useTempTarget() == NO) {
tempTarget = null;
}
// Bolus IOB
boolean bolusIOB = false;
if (useBolusIOB() == YES) {
bolusIOB = true;
}
// Basal IOB
TreatmentsInterface treatments = MainApp.getConfigBuilder();
treatments.updateTotalIOBTempBasals();
IobTotal basalIob = treatments.getLastCalculationTempBasals().round();
boolean basalIOB = false;
if (useBasalIOB() == YES) {
basalIOB = true;
} else if (useBasalIOB() == POSITIVE_ONLY && basalIob.iob > 0) {
basalIOB = true;
} else if (useBasalIOB() == NEGATIVE_ONLY && basalIob.iob < 0) {
basalIOB = true;
}
// SuperBolus
boolean superBolus = false;
if (useSuperBolus() == YES && SP.getBoolean(R.string.key_usesuperbolus, false)) {
superBolus = true;
}
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuperBolus())
superBolus = false;
// Trend
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
boolean trend = false;
if (useTrend() == YES) {
trend = true;
} else if (useTrend() == POSITIVE_ONLY && glucoseStatus != null && glucoseStatus.short_avgdelta > 0) {
trend = true;
} else if (useTrend() == NEGATIVE_ONLY && glucoseStatus != null && glucoseStatus.short_avgdelta < 0) {
trend = true;
}
wizard.doCalc(profile, tempTarget, carbs(), cob, bg, 0d, bolusIOB, basalIOB, superBolus, trend);
return wizard;
}
public String buttonText() {
try {
return storage.getString("buttonText");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return "";
}
public Integer carbs() {
try {
return storage.getInt("carbs");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return 0;
}
public Date validFromDate() {
return DateUtil.toDate(validFrom());
}
public Date validToDate() {
return DateUtil.toDate(validTo());
}
public Integer validFrom() {
try {
return storage.getInt("validFrom");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return 0;
}
public Integer validTo() {
try {
return storage.getInt("validTo");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return 0;
}
public int useBG() {
try {
return storage.getInt("useBG");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return YES;
}
public int useCOB() {
try {
return storage.getInt("useCOB");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return NO;
}
public int useBolusIOB() {
try {
return storage.getInt("useBolusIOB");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return YES;
}
public int useBasalIOB() {
try {
return storage.getInt("useBasalIOB");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return YES;
}
public int useTrend() {
try {
return storage.getInt("useTrend");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return NO;
}
public int useSuperBolus() {
try {
return storage.getInt("useSuperBolus");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return NO;
}
public int useTempTarget() {
try {
return storage.getInt("useTempTarget");
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return NO;
}
}

View file

@ -9,7 +9,6 @@ import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
@ -17,13 +16,13 @@ import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.QuickWizard;
import info.nightscout.androidaps.data.QuickWizardEntry;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Overview.QuickWizard;
import info.nightscout.androidaps.plugins.Overview.events.EventQuickWizardChange;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SafeParse;
@ -31,19 +30,25 @@ import info.nightscout.utils.SafeParse;
public class EditQuickWizardDialog extends DialogFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class);
QuickWizard.QuickWizardEntry entry = new QuickWizard().newEmptyItem();
QuickWizardEntry entry = new QuickWizard().newEmptyItem();
QuickWizard quickWizard = MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard;
EditText buttonEdit;
EditText carbsEdit;
Spinner fromSpinner;
Spinner toSpinner;
Button okButton;
Spinner useBGSpinner;
Spinner useCOBSpinner;
Spinner useBolusIOBSpinner;
Spinner useBasalIOBSpinner;
Spinner useTrendSpinner;
Spinner useSuperBolusSpinner;
Spinner useTempTargetSpinner;
public EditQuickWizardDialog() {
}
public void setData(QuickWizard.QuickWizardEntry data) {
public void setData(QuickWizardEntry data) {
entry = data;
}
@ -58,8 +63,16 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic
carbsEdit = (EditText) view.findViewById(R.id.overview_editquickwizard_carbs_edit);
fromSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_from_spinner);
toSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_to_spinner);
okButton = (Button) view.findViewById(R.id.overview_editquickwizard_ok_button);
okButton.setOnClickListener(this);
useBGSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usebg_spinner);
useCOBSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usecob_spinner);
useBolusIOBSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usebolusiob_spinner);
useBasalIOBSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usebasaliob_spinner);
useTrendSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usetrend_spinner);
useSuperBolusSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usesuperbolus_spinner);
useTempTargetSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usetemptarget_spinner);
view.findViewById(R.id.ok).setOnClickListener(this);
view.findViewById(R.id.cancel).setOnClickListener(this);
int posFrom = 0;
int posTo = 95;
@ -83,6 +96,14 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic
fromSpinner.setSelection(posFrom);
toSpinner.setSelection(posTo);
setSelection(useBGSpinner, entry.useBG());
setSelection(useCOBSpinner, entry.useCOB());
setSelection(useBolusIOBSpinner, entry.useBolusIOB());
setSelection(useBasalIOBSpinner, entry.useBasalIOB());
setSelection(useTrendSpinner, entry.useTrend());
setSelection(useSuperBolusSpinner, entry.useSuperBolus());
setSelection(useTempTargetSpinner, entry.useTempTarget());
return view;
}
@ -96,7 +117,7 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.overview_editquickwizard_ok_button:
case R.id.ok:
if (fromSpinner.getSelectedItem() == null) return;
if (toSpinner.getSelectedItem() == null) return;
try {
@ -106,6 +127,13 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic
entry.storage.put("validFrom", validFromInt);
int validToInt = DateUtil.toSeconds(toSpinner.getSelectedItem().toString());
entry.storage.put("validTo", validToInt);
entry.storage.put("useBG", getSelection(useBGSpinner));
entry.storage.put("useCOB", getSelection(useCOBSpinner));
entry.storage.put("useBolusIOB", getSelection(useBolusIOBSpinner));
entry.storage.put("useBasalIOB", getSelection(useBasalIOBSpinner));
entry.storage.put("useTrend", getSelection(useTrendSpinner));
entry.storage.put("useSuperBolus", getSelection(useSuperBolusSpinner));
entry.storage.put("useTempTarget", getSelection(useTempTargetSpinner));
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
@ -113,6 +141,50 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic
dismiss();
MainApp.bus().post(new EventQuickWizardChange());
break;
case R.id.cancel:
dismiss();
break;
}
}
int getSelection(Spinner spinner) {
String value = spinner.getSelectedItem().toString();
if (value.equals(MainApp.sResources.getString(R.string.yes)))
return QuickWizardEntry.YES;
if (value.equals(MainApp.sResources.getString(R.string.no)))
return QuickWizardEntry.NO;
if (value.equals(MainApp.sResources.getString(R.string.positiveonly)))
return QuickWizardEntry.POSITIVE_ONLY;
if (value.equals(MainApp.sResources.getString(R.string.negativeonly)))
return QuickWizardEntry.NEGATIVE_ONLY;
return QuickWizardEntry.NO;
}
void setSelection(Spinner spinner, int value) {
String selection;
switch (value) {
case QuickWizardEntry.YES:
selection = MainApp.sResources.getString(R.string.yes);
break;
case QuickWizardEntry.NO:
selection = MainApp.sResources.getString(R.string.no);
break;
case QuickWizardEntry.POSITIVE_ONLY:
selection = MainApp.sResources.getString(R.string.positiveonly);
break;
case QuickWizardEntry.NEGATIVE_ONLY:
selection = MainApp.sResources.getString(R.string.negativeonly);
break;
default:
selection = MainApp.sResources.getString(R.string.no);
break;
}
for (int i = 0; i < spinner.getCount(); i++) {
if (spinner.getItemAtPosition(i).toString().equalsIgnoreCase(selection)) {
spinner.setSelection(i);
break;
}
}
}
}

View file

@ -53,6 +53,8 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
@ -102,7 +104,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
Integer calculatedCarbs = 0;
Double calculatedTotalInsulin = 0d;
JSONObject boluscalcJSON;
boolean cobAvailable = false;
Context context;
@ -138,25 +139,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
MainApp.bus().unregister(this);
}
@Subscribe
public void onStatusEvent(final EventOpenAPSUpdateGui e) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (ConfigBuilderPlugin.getActiveAPS() instanceof OpenAPSAMAPlugin && ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSRun().after(new Date(System.currentTimeMillis() - 11 * 60 * 1000L))) {
cobLayout.setVisibility(View.VISIBLE);
cobAvailable = true;
} else {
cobLayout.setVisibility(View.GONE);
cobAvailable = false;
}
calculateInsulin();
}
});
}
@Subscribe
public void onStatusEvent(final EventNewBG e) {
Activity activity = getActivity();
@ -439,14 +421,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U");
basalIobInsulin.setText(DecimalFormatter.to2Decimal(-basalIob.basaliob) + "U");
// COB only if AMA is selected
if (ConfigBuilderPlugin.getActiveAPS() instanceof OpenAPSAMAPlugin && ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSRun().after(new Date(System.currentTimeMillis() - 11 * 60 * 1000L))) {
cobLayout.setVisibility(View.VISIBLE);
cobAvailable = true;
} else {
cobLayout.setVisibility(View.GONE);
cobAvailable = false;
}
calculateInsulin();
}
@ -483,13 +457,11 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
// COB
Double c_cob = 0d;
if (cobAvailable && cobCheckbox.isChecked()) {
if (ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSRun().after(new Date(System.currentTimeMillis() - 11 * 60 * 1000L))) {
try {
c_cob = SafeParse.stringToDouble(ConfigBuilderPlugin.getActiveAPS().getLastAPSResult().json().getString("COB"));
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
if (cobCheckbox.isChecked()) {
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis());
if(autosensData != null && autosensData.time > System.currentTimeMillis() - 11 * 60 * 1000L) {
c_cob = autosensData.cob;
}
}
@ -531,7 +503,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
bgTrendInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromTrend) + "U");
// COB
if (cobAvailable && cobCheckbox.isChecked()) {
if (cobCheckbox.isChecked()) {
cob.setText(DecimalFormatter.to2Decimal(c_cob) + "g IC: " + DecimalFormatter.to1Decimal(wizard.ic));
cobInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromCOB) + "U");
} else {

View file

@ -60,6 +60,7 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.QuickWizardEntry;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.DatabaseHelper;
@ -96,6 +97,7 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
import info.nightscout.androidaps.plugins.Overview.activities.QuickWizardListActivity;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
@ -114,7 +116,7 @@ import info.nightscout.utils.SP;
import info.nightscout.utils.SingleClickButton;
import info.nightscout.utils.ToastUtils;
public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, View.OnLongClickListener {
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
TextView timeView;
@ -252,6 +254,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
acceptTempButton.setOnClickListener(this);
quickWizardButton = (SingleClickButton) view.findViewById(R.id.overview_quickwizardbutton);
quickWizardButton.setOnClickListener(this);
quickWizardButton.setOnLongClickListener(this);
calibrationButton = (SingleClickButton) view.findViewById(R.id.overview_calibrationbutton);
if (calibrationButton != null)
calibrationButton.setOnClickListener(this);
@ -576,6 +579,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
@Override
public boolean onLongClick(View v) {
switch (v.getId()) {
case R.id.overview_quickwizardbutton:
Intent i = new Intent(v.getContext(), QuickWizardListActivity.class);
startActivity(i);
return true;
}
return false;
}
private void onClickAcceptTemp() {
if (ConfigBuilderPlugin.getActiveLoop() != null) {
ConfigBuilderPlugin.getActiveLoop().invoke("Accept temp button", false);
@ -619,11 +633,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final Profile profile = MainApp.getConfigBuilder().getProfile();
final TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory();
QuickWizard.QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
if (quickWizardEntry != null && actualBg != null) {
quickWizardButton.setVisibility(View.VISIBLE);
BolusWizard wizard = new BolusWizard();
wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, actualBg.valueToUnits(profile.getUnits()), 0d, true, true, false, false);
final BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, actualBg);
final JSONObject boluscalcJSON = new JSONObject();
try {
@ -682,6 +695,26 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
accepted = true;
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
if (wizard.superBolus) {
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop != null) {
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
}
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, 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.tempbasaldeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
}
});
}
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
@ -1086,12 +1119,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
tempTargetView.setLongClickable(true);
// QuickWizard button
QuickWizard.QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) {
quickWizardButton.setVisibility(View.VISIBLE);
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
BolusWizard wizard = new BolusWizard();
wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false);
BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, lastBG);
text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U";
quickWizardButton.setText(text);
if (wizard.calculatedTotalInsulin <= 0)

View file

@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.QuickWizard;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;

View file

@ -1,9 +1,9 @@
package info.nightscout.androidaps.plugins.Overview.activities;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -15,13 +15,11 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe;
import java.text.SimpleDateFormat;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.QuickWizard;
import info.nightscout.androidaps.plugins.Overview.Dialogs.EditQuickWizardDialog;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Overview.QuickWizard;
import info.nightscout.androidaps.plugins.Overview.events.EventQuickWizardChange;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@ -153,6 +151,7 @@ public class QuickWizardListActivity extends AppCompatActivity implements View.O
break;
}
}
@Subscribe
public void onStatusEvent(final EventQuickWizardChange ev) {
updateGUI();

View file

@ -215,6 +215,8 @@ public class WearPlugin implements PluginBase {
@Subscribe
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
if(ev.result == null) return;
String status;
if(ev.result.success){
status = MainApp.sResources.getString(R.string.success);

View file

@ -60,7 +60,7 @@ public class QueueThread extends Thread {
}
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {
MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult()));
MainApp.bus().post(new EventDismissBolusprogressIfRunning(null));
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout)));
log.debug("QUEUE: timed out");
pump.stopConnecting();

View file

@ -14,15 +14,15 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
public class BolusWizard {
// Inputs
Profile specificProfile = null;
TempTarget tempTarget;
private Profile specificProfile = null;
private TempTarget tempTarget;
public Integer carbs = 0;
Double bg = 0d;
Double correction;
Boolean includeBolusIOB = true;
Boolean includeBasalIOB = true;
Boolean superBolus = false;
Boolean trend = false;
private Double bg = 0d;
private Double correction;
private Boolean includeBolusIOB = true;
private Boolean includeBasalIOB = true;
public Boolean superBolus = false;
private Boolean trend = false;
// Intermediate
public Double sens = 0d;

View file

@ -5,68 +5,149 @@
tools:context="info.nightscout.androidaps.plugins.Overview.Dialogs.EditQuickWizardDialog">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp">
android:layout_margin="15dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/overview_editquickwizard_buttontext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<EditText
android:id="@+id/overview_editquickwizard_button_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:id="@+id/overview_editquickwizard_button_edit" />
android:inputType="text" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/overview_editquickwizard_carbs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<EditText
android:id="@+id/overview_editquickwizard_carbs_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="@+id/overview_editquickwizard_carbs_edit" />
android:inputType="numberDecimal" />
<TextView
android:text="@string/overview_editquickwizard_valid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/overview_editquickwizard_valid"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Spinner
android:id="@+id/overview_editquickwizard_from_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="@+id/overview_editquickwizard_to_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/overview_editquickwizard_to_spinner"
android:layout_weight="1" />
</LinearLayout>
<Button
android:text="@string/ok"
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/overview_editquickwizard_ok_button"
android:layout_weight="1" />
android:text="@string/overview_editquickwizard_usebg"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<Spinner
android:id="@+id/overview_editquickwizard_usebg_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/quickWizardUseBGArray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/overview_editquickwizard_usebolusiob"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<Spinner
android:id="@+id/overview_editquickwizard_usebolusiob_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/quickWizardUseBolusIOBArray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/overview_editquickwizard_usebasaliob"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<Spinner
android:id="@+id/overview_editquickwizard_usebasaliob_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/quickWizardUseBasalOBArray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/overview_editquickwizard_usecob"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<Spinner
android:id="@+id/overview_editquickwizard_usecob_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/quickWizardUseCOBArray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/overview_editquickwizard_usetrend"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<Spinner
android:id="@+id/overview_editquickwizard_usetrend_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/quickWizardUseTrendArray" />
<TextView
android:id="@+id/overview_editquickwizard_usesuperbolus_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/overview_editquickwizard_usesuperbolus"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<Spinner
android:id="@+id/overview_editquickwizard_usesuperbolus_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/quickWizardUseSuperBolusArray" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/overview_editquickwizard_usetemptarget"
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
<Spinner
android:id="@+id/overview_editquickwizard_usetemptarget_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/quickWizardUseTempTargetArray" />
<include layout="@layout/mdtp_done_button" />
</LinearLayout>

View file

@ -59,4 +59,43 @@
<item>2</item>
</string-array>
<string-array name="quickWizardUseBGArray">
<item>@string/yes</item>
<item>@string/no</item>
</string-array>
<string-array name="quickWizardUseCOBArray">
<item>@string/yes</item>
<item>@string/no</item>
</string-array>
<string-array name="quickWizardUseBolusIOBArray">
<item>@string/yes</item>
<item>@string/no</item>
</string-array>
<string-array name="quickWizardUseBasalOBArray">
<item>@string/yes</item>
<item>@string/no</item>
<item>@string/positiveonly</item>
<item>@string/negativeonly</item>
</string-array>
<string-array name="quickWizardUseTrendArray">
<item>@string/no</item>
<item>@string/yes</item>
<item>@string/positiveonly</item>
<item>@string/negativeonly</item>
</string-array>
<string-array name="quickWizardUseSuperBolusArray">
<item>@string/no</item>
<item>@string/yes</item>
</string-array>
<string-array name="quickWizardUseTempTargetArray">
<item>@string/no</item>
<item>@string/yes</item>
</string-array>
</resources>

View file

@ -800,5 +800,16 @@
<string name="dexcomg5_xdripupload_summary">In xDrip+ select 640g/Eversense data source</string>
<string name="nsclientbg">NSClient BG</string>
<string name="minimalbasalvaluereplaced">Basal value replaced by minimal supported value</string>
<string name="overview_editquickwizard_usebg">BG calculation</string>
<string name="overview_editquickwizard_usebolusiob">Bolus IOB calculation</string>
<string name="overview_editquickwizard_usebasaliob">Basal IOB calculation</string>
<string name="overview_editquickwizard_usetrend">Trend calculation</string>
<string name="overview_editquickwizard_usesuperbolus">Superbolus calculation</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="positiveonly">Positive only</string>
<string name="negativeonly">Negative only</string>
<string name="overview_editquickwizard_usecob">COB calculation</string>
<string name="overview_editquickwizard_usetemptarget">Temporary target calculation</string>
</resources>