Improve connection routine

This commit is contained in:
TebbeUbben 2019-01-25 22:32:22 +01:00
parent ffc1db3c95
commit 8116a24fc6
3 changed files with 13 additions and 7 deletions

View file

@ -261,17 +261,12 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
@Override
public boolean isConnected() {
if (connectionService == null || alertService == null) return false;
return connectionService.getState() == InsightState.CONNECTED;
return connectionService != null && alertService != null && connectionService.getState() == InsightState.CONNECTED;
}
@Override
public boolean isConnecting() {
if (connectionService == null || alertService == null) return false;
InsightState state = connectionService.getState();
return state == InsightState.CONNECTING
|| state == InsightState.APP_CONNECT_MESSAGE
|| state == InsightState.RECOVERING;
return connectionService != null && alertService != null && connectionService.hasRequestedConnection(this);
}
@Override

View file

@ -249,6 +249,10 @@ public class InsightConnectionService extends Service implements ConnectionEstab
log.info("Insight state changed: " + state.name());
}
public synchronized boolean hasRequestedConnection(Object lock) {
return connectionRequests.contains(lock);
}
public synchronized void requestConnection(Object lock) {
if (connectionRequests.contains(lock)) return;
connectionRequests.add(lock);

View file

@ -1266,6 +1266,13 @@
<string name="refresh">Refresh</string>
<string name="description_pump_insight_local">Pump integration for Accu-Chek Insight pumps</string>
<string name="not_inserted">Not inserted</string>
<string name="short_status_last_connected">Last conn: %1$d min ago</string>
<string name="short_status_tbr">TBR: %1$d%% for %2$d / %3$d min</string>
<string name="short_status_extended">Extended: %1$.2f / %2$.2f U for %3$d min</string>
<string name="short_status_multiwave">Extended: %1$.2f / %2$.2f U for %3$d min</string>
<string name="short_status_tdd">TDD: %1$.2f</string>
<string name="short_status_reservoir">Reser.: %1$.2fU</string>
<string name="short_status_battery">Batt.: %1$d%%</string>
<plurals name="objective_days">
<item quantity="one">%1$d day</item>