temptarget sort and allow for zero-duration to cancel predated ones
This commit is contained in:
parent
d36a515d45
commit
b79743588d
|
@ -370,6 +370,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
String enteredBy = SP.getString("careportal_enteredby", "");
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
boolean allowZeroDuration = false;
|
||||
data.put("created_at", DateUtil.toISOString(eventTime));
|
||||
switch (options.eventType) {
|
||||
case R.id.careportal_bgcheck:
|
||||
|
@ -431,6 +432,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
break;
|
||||
case R.id.careportal_temptarget:
|
||||
data.put("eventType", "Temporary Target");
|
||||
allowZeroDuration = true;
|
||||
break;
|
||||
}
|
||||
if (SafeParse.stringToDouble(bgInputEdit.getText().toString()) != 0d) {
|
||||
|
@ -443,7 +445,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
data.put("carbs", SafeParse.stringToDouble(carbsEdit.getText().toString()));
|
||||
if (SafeParse.stringToDouble(insulinEdit.getText().toString()) != 0d)
|
||||
data.put("insulin", SafeParse.stringToDouble(insulinEdit.getText().toString()));
|
||||
if (SafeParse.stringToDouble(durationeEdit.getText().toString()) != 0d)
|
||||
if (allowZeroDuration || SafeParse.stringToDouble(durationeEdit.getText().toString()) != 0d)
|
||||
data.put("duration", SafeParse.stringToDouble(durationeEdit.getText().toString()));
|
||||
if (layoutPercent.getVisibility() != View.GONE)
|
||||
data.put("percent", SafeParse.stringToDouble(percentEdit.getText().toString()));
|
||||
|
@ -607,7 +609,10 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||
}
|
||||
if (options.executeTempTarget) {
|
||||
if (data.has("targetBottom") && data.has("targetTop")) {
|
||||
|
||||
|
||||
try {
|
||||
if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration")&& data.getInt("duration") == 0)) {
|
||||
sHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -616,8 +621,10 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
tempTarget.timeStart = eventTime;
|
||||
tempTarget.duration = data.getInt("duration");
|
||||
tempTarget.reason = data.getString("reason");
|
||||
if(tempTarget.duration != 0) {
|
||||
tempTarget.low = NSProfile.toMgdl(data.getDouble("targetBottom"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits());
|
||||
tempTarget.high = NSProfile.toMgdl(data.getDouble("targetTop"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits());
|
||||
}
|
||||
tempTarget.setTimeIndex(tempTarget.getTimeIndex());
|
||||
Dao<TempTarget, Long> dao = MainApp.getDbHelper().getDaoTempTargets();
|
||||
log.debug("Creating new TempTarget db record: " + tempTarget.log());
|
||||
|
@ -632,6 +639,9 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
}
|
||||
});
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||
}
|
||||
|
|
|
@ -83,6 +83,9 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
|
|||
holder.reason.setText(tempTarget.reason);
|
||||
if (tempTarget.isInProgress())
|
||||
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorInProgress));
|
||||
else if (tempTarget.duration == 0){
|
||||
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.notificationUrgent));
|
||||
}
|
||||
else
|
||||
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.cardColorBackground));
|
||||
holder.remove.setTag(tempTarget);
|
||||
|
|
|
@ -91,7 +91,11 @@ public class TempTargetRangePlugin implements PluginBase {
|
|||
|
||||
@Nullable
|
||||
public TempTarget getTempTargetInProgress(long time) {
|
||||
for (int i = tempTargets.size() - 1; i >= 0; i--) {
|
||||
// for (int i = tempTargets.size() - 1; i >= 0; i--) {
|
||||
for (int i = 0; i < tempTargets.size(); i++) {
|
||||
// a zero-duration temp target will cancel all prior targets
|
||||
if (tempTargets.get(i).duration == 0) return null;
|
||||
|
||||
if (tempTargets.get(i).timeStart.getTime() > time) continue;
|
||||
if (tempTargets.get(i).getPlannedTimeEnd().getTime() >= time) return tempTargets.get(i);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue