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", "");
|
String enteredBy = SP.getString("careportal_enteredby", "");
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
try {
|
try {
|
||||||
|
boolean allowZeroDuration = false;
|
||||||
data.put("created_at", DateUtil.toISOString(eventTime));
|
data.put("created_at", DateUtil.toISOString(eventTime));
|
||||||
switch (options.eventType) {
|
switch (options.eventType) {
|
||||||
case R.id.careportal_bgcheck:
|
case R.id.careportal_bgcheck:
|
||||||
|
@ -431,6 +432,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_temptarget:
|
case R.id.careportal_temptarget:
|
||||||
data.put("eventType", "Temporary Target");
|
data.put("eventType", "Temporary Target");
|
||||||
|
allowZeroDuration = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (SafeParse.stringToDouble(bgInputEdit.getText().toString()) != 0d) {
|
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()));
|
data.put("carbs", SafeParse.stringToDouble(carbsEdit.getText().toString()));
|
||||||
if (SafeParse.stringToDouble(insulinEdit.getText().toString()) != 0d)
|
if (SafeParse.stringToDouble(insulinEdit.getText().toString()) != 0d)
|
||||||
data.put("insulin", SafeParse.stringToDouble(insulinEdit.getText().toString()));
|
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()));
|
data.put("duration", SafeParse.stringToDouble(durationeEdit.getText().toString()));
|
||||||
if (layoutPercent.getVisibility() != View.GONE)
|
if (layoutPercent.getVisibility() != View.GONE)
|
||||||
data.put("percent", SafeParse.stringToDouble(percentEdit.getText().toString()));
|
data.put("percent", SafeParse.stringToDouble(percentEdit.getText().toString()));
|
||||||
|
@ -607,7 +609,10 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||||
}
|
}
|
||||||
if (options.executeTempTarget) {
|
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() {
|
sHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -616,8 +621,10 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
tempTarget.timeStart = eventTime;
|
tempTarget.timeStart = eventTime;
|
||||||
tempTarget.duration = data.getInt("duration");
|
tempTarget.duration = data.getInt("duration");
|
||||||
tempTarget.reason = data.getString("reason");
|
tempTarget.reason = data.getString("reason");
|
||||||
|
if(tempTarget.duration != 0) {
|
||||||
tempTarget.low = NSProfile.toMgdl(data.getDouble("targetBottom"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits());
|
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.high = NSProfile.toMgdl(data.getDouble("targetTop"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits());
|
||||||
|
}
|
||||||
tempTarget.setTimeIndex(tempTarget.getTimeIndex());
|
tempTarget.setTimeIndex(tempTarget.getTimeIndex());
|
||||||
Dao<TempTarget, Long> dao = MainApp.getDbHelper().getDaoTempTargets();
|
Dao<TempTarget, Long> dao = MainApp.getDbHelper().getDaoTempTargets();
|
||||||
log.debug("Creating new TempTarget db record: " + tempTarget.log());
|
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 {
|
} else {
|
||||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,9 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
|
||||||
holder.reason.setText(tempTarget.reason);
|
holder.reason.setText(tempTarget.reason);
|
||||||
if (tempTarget.isInProgress())
|
if (tempTarget.isInProgress())
|
||||||
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorInProgress));
|
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
|
else
|
||||||
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.cardColorBackground));
|
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.cardColorBackground));
|
||||||
holder.remove.setTag(tempTarget);
|
holder.remove.setTag(tempTarget);
|
||||||
|
|
|
@ -91,7 +91,11 @@ public class TempTargetRangePlugin implements PluginBase {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public TempTarget getTempTargetInProgress(long time) {
|
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).timeStart.getTime() > time) continue;
|
||||||
if (tempTargets.get(i).getPlannedTimeEnd().getTime() >= time) return tempTargets.get(i);
|
if (tempTargets.get(i).getPlannedTimeEnd().getTime() >= time) return tempTargets.get(i);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue