diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.java
index 9cd39e9ac2..185a53f171 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputLocationMode.java
@@ -28,6 +28,10 @@ public class InputLocationMode extends Element {
return R.string.location_inside;
case OUTSIDE:
return R.string.location_outside;
+ case GOING_IN:
+ return R.string.location_going_in;
+ case GOING_OUT:
+ return R.string.location_going_out;
default:
return R.string.unknown;
}
@@ -79,7 +83,6 @@ public class InputLocationMode extends Element {
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
-// mode = Mode.values()[position];
setValue(Mode.values()[position]);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java
index 03b27732d1..cbb4058a5d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java
@@ -29,14 +29,16 @@ import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.JsonHelper;
import info.nightscout.androidaps.utils.T;
+import static info.nightscout.androidaps.plugins.general.automation.elements.InputLocationMode.Mode.*;
+
public class TriggerLocation extends Trigger {
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
InputDouble latitude = new InputDouble(0d, -90d, +90d, 0.000001d, new DecimalFormat("0.000000"));
InputDouble longitude = new InputDouble(0d, -180d, +180d, 0.000001d, new DecimalFormat("0.000000"));
InputDouble distance = new InputDouble(200d, 0, 100000, 10d, new DecimalFormat("0"));
- // Default mode selected is 0 - inside area
InputLocationMode modeSelected = new InputLocationMode();
+ InputLocationMode.Mode lastMode = new InputLocationMode().getValue();
InputString name = new InputString();
@@ -76,8 +78,15 @@ public class TriggerLocation extends Trigger {
a.setLatitude(latitude.getValue());
a.setLongitude(longitude.getValue());
double calculatedDistance = location.distanceTo(a);
- if (((modeSelected.getValue().ordinal()) == 1d) && (calculatedDistance < distance.getValue()) ||
- ((modeSelected.getValue().ordinal() == 2d) && (calculatedDistance > distance.getValue()))) {
+ //Update lastmode every 5 mins
+ lastMode = currentMode(calculatedDistance);
+ log.debug("Last mode is: "+lastMode);
+ log.debug("Wanted mode is: "+modeSelected.getValue());
+ if ((modeSelected.getValue() == INSIDE) && (calculatedDistance <= distance.getValue()) ||
+ ((modeSelected.getValue() == OUTSIDE) && (calculatedDistance > distance.getValue())) ||
+ ((modeSelected.getValue() == GOING_IN) && (calculatedDistance <= distance.getValue()) && (lastMode == OUTSIDE)) ||
+ ((modeSelected.getValue() == GOING_OUT) && (calculatedDistance > distance.getValue()) && (lastMode == INSIDE))
+ ) {
if (L.isEnabled(L.AUTOMATION))
log.debug("Ready for execution: " + friendlyDescription());
return true;
@@ -108,12 +117,14 @@ public class TriggerLocation extends Trigger {
@Override
Trigger fromJSON(String data) {
try {
+ log.debug("fromJSON: "+data);
JSONObject d = new JSONObject(data);
latitude.setValue(JsonHelper.safeGetDouble(d, "latitude"));
longitude.setValue(JsonHelper.safeGetDouble(d, "longitude"));
distance.setValue(JsonHelper.safeGetDouble(d, "distance"));
name.setValue(JsonHelper.safeGetString(d, "name"));
modeSelected.setValue(InputLocationMode.Mode.valueOf(JsonHelper.safeGetString(d, "mode")));
+ lastMode = modeSelected.getValue(); // load the asked mode as default
lastRun = JsonHelper.safeGetLong(d, "lastRun");
} catch (Exception e) {
log.error("Unhandled exception", e);
@@ -128,7 +139,7 @@ public class TriggerLocation extends Trigger {
@Override
public String friendlyDescription() {
- return MainApp.gs(R.string.locationis, modeSelected.getValue() + " " + name.getValue());
+ return MainApp.gs(R.string.locationis, MainApp.gs(modeSelected.getValue().getStringRes()) + " " + name.getValue());
}
@Override
@@ -163,7 +174,6 @@ public class TriggerLocation extends Trigger {
}
TriggerLocation setMode(InputLocationMode.Mode value) {
-
modeSelected.setValue(value);
return this;
}
@@ -181,4 +191,12 @@ public class TriggerLocation extends Trigger {
.build(root);
}
+ // Method to return the actual mode based on the current distance
+ InputLocationMode.Mode currentMode(double currentDistance){
+ log.debug("Updating current mode!");
+ if ( currentDistance <= this.distance.getValue() )
+ return INSIDE;
+ else
+ return InputLocationMode.Mode.OUTSIDE;
+ }
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 05d34d0cec..3c48994172 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1414,6 +1414,8 @@
In/Out of defined area
inside
outside
+ when you enter the area named
+ when you leave the area named
Last bolus ago
Last bolus time %1$s %2$s min ago
COB