Insight: preemptive connection preference option

This commit is contained in:
Jamorham 2018-02-21 12:23:19 +00:00
parent 2f1efc7d06
commit 67b397b417
No known key found for this signature in database
GPG key ID: 0BC5C3E0AAD64DF9
3 changed files with 22 additions and 10 deletions

View file

@ -19,6 +19,7 @@ import info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver;
import info.nightscout.androidaps.plugins.PumpInsight.history.LiveHistory; import info.nightscout.androidaps.plugins.PumpInsight.history.LiveHistory;
import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers; import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers;
import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem; import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem;
import info.nightscout.utils.SP;
import sugar.free.sightparser.handling.ServiceConnectionCallback; import sugar.free.sightparser.handling.ServiceConnectionCallback;
import sugar.free.sightparser.handling.SightServiceConnector; import sugar.free.sightparser.handling.SightServiceConnector;
import sugar.free.sightparser.handling.StatusCallback; import sugar.free.sightparser.handling.StatusCallback;
@ -493,15 +494,17 @@ public class Connector {
@Subscribe @Subscribe
public void onStatusEvent(final EventFeatureRunning ev) { public void onStatusEvent(final EventFeatureRunning ev) {
switch (ev.getFeature()) { if (SP.getBoolean("insight_preemptive_connect", true)) {
case WIZARD: switch (ev.getFeature()) {
log("Wizard feature detected, preconnecting to pump"); case WIZARD:
connectToPump(120 * 1000); log("Wizard feature detected, preconnecting to pump");
break; connectToPump(120 * 1000);
case MAIN: break;
log("Main feature detected, preconnecting to pump"); case MAIN:
connectToPump(30 * 1000); log("Main feature detected, preconnecting to pump");
break; connectToPump(30 * 1000);
break;
}
} }
} }
} }

View file

@ -904,5 +904,8 @@
<string name="insight_keepalive_format_string">%ds expires %s</string> <string name="insight_keepalive_format_string">%ds expires %s</string>
<string name="insight_keep_alive_status">Keep-alive status</string> <string name="insight_keep_alive_status">Keep-alive status</string>
<string name="statistics">Statistics</string> <string name="statistics">Statistics</string>
<string name="connect_preemptively">Connect preemptively</string>
<string name="automatically_connect_when">Automatically connect when AndroidAPS screens are opened, before any pump command is requested, to reduce connection delay</string>
<string name="not_recommended_due_to_battery_drain">Not recommended due to battery drain</string>
</resources> </resources>

View file

@ -7,7 +7,13 @@
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="insight_always_connected" android:key="insight_always_connected"
android:title="@string/insight_stay_always_connected" /> android:title="@string/insight_stay_always_connected"
android:summary="@string/not_recommended_due_to_battery_drain"/>
<SwitchPreference
android:defaultValue="true"
android:key="insight_preemptive_connect"
android:title="@string/connect_preemptively"
android:summary="@string/automatically_connect_when"/>
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="insight_real_tbr_cancel" android:key="insight_real_tbr_cancel"