QuickWizard detailed settings
This commit is contained in:
parent
e2f6e6a450
commit
8fdd16c305
|
@ -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;
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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,13 +127,64 @@ 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);
|
||||
}
|
||||
quickWizard.addOrUpdate(entry);
|
||||
dismiss();
|
||||
MainApp.bus().post(new EventQuickWizardChange());
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
|||
Integer calculatedCarbs = 0;
|
||||
Double calculatedTotalInsulin = 0d;
|
||||
JSONObject boluscalcJSON;
|
||||
boolean cobAvailable = false;
|
||||
|
||||
Context context;
|
||||
|
||||
|
@ -140,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();
|
||||
|
@ -441,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) {
|
||||
cobLayout.setVisibility(View.VISIBLE);
|
||||
cobAvailable = true;
|
||||
} else {
|
||||
cobLayout.setVisibility(View.GONE);
|
||||
cobAvailable = false;
|
||||
}
|
||||
calculateInsulin();
|
||||
}
|
||||
|
||||
|
@ -485,7 +457,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
|||
|
||||
// COB
|
||||
Double c_cob = 0d;
|
||||
if (cobAvailable && cobCheckbox.isChecked()) {
|
||||
if (cobCheckbox.isChecked()) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis());
|
||||
|
||||
if(autosensData != null && autosensData.time > System.currentTimeMillis() - 11 * 60 * 1000L) {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
@ -97,6 +98,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;
|
||||
|
@ -115,7 +117,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;
|
||||
|
@ -253,6 +255,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);
|
||||
|
@ -577,6 +580,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);
|
||||
|
@ -620,11 +634,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 {
|
||||
|
@ -683,6 +696,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;
|
||||
|
@ -1087,12 +1120,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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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">
|
||||
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:id="@+id/overview_editquickwizard_from_spinner"
|
||||
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>
|
||||
|
||||
|
|
|
@ -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>
|
|
@ -789,5 +789,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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue