Merge pull request #11 from jotomo/combo-scripter-v2

20.12.2017
This commit is contained in:
Simon Pauwels 2017-12-20 22:37:43 +01:00 committed by GitHub
commit 5bda1235c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 537 additions and 180 deletions

View file

@ -39,6 +39,9 @@ Limitations:
pump solely through AAPS. pump solely through AAPS.
Checking history, reservoir level etc on the pump causes no issues but should be avoided Checking history, reservoir level etc on the pump causes no issues but should be avoided
when the Bluetooth icon is displayed on the display, indicating that AAPS is communicating with the pump. when the Bluetooth icon is displayed on the display, indicating that AAPS is communicating with the pump.
- Currently only basal rates in the range of 0.05 to 10 U/h are supported (this also applies when modifying
a profile, e.g. when increasing to 200%, the highest basal rate must not exceed 5 U/h since it will be
doubled. Similarly, when reducing to 50%, the lowest basal rate must be at least 0.10 U/h).
Setup: Setup:
- Configure pump using 360 config software. - Configure pump using 360 config software.

View file

@ -117,10 +117,8 @@ public class DataService extends IntentService {
handleNewDataFromDexcomG5(intent); handleNewDataFromDexcomG5(intent);
} }
} else if (Intents.ACTION_NEW_SGV.equals(action)) { } else if (Intents.ACTION_NEW_SGV.equals(action)) {
// always handle SGV if NS-Client is the source // always backfill SGV from NS
if (nsClientEnabled) { handleNewDataFromNSClient(intent);
handleNewDataFromNSClient(intent);
}
// Objectives 0 // Objectives 0
ObjectivesPlugin.bgIsAvailableInNS = true; ObjectivesPlugin.bgIsAvailableInNS = true;
ObjectivesPlugin.saveProgress(); ObjectivesPlugin.saveProgress();
@ -301,7 +299,7 @@ public class DataService extends IntentService {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
if (ConfigBuilderPlugin.nightscoutVersionCode < Config.SUPPORTEDNSVERSION) { if (ConfigBuilderPlugin.nightscoutVersionCode < Config.SUPPORTEDNSVERSION) {
Notification notification = new Notification(Notification.OLD_NS, MainApp.sResources.getString(R.string.unsupportednsversion), Notification.URGENT); Notification notification = new Notification(Notification.OLD_NS, MainApp.sResources.getString(R.string.unsupportednsversion), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
} else { } else {
MainApp.bus().post(new EventDismissNotification(Notification.OLD_NS)); MainApp.bus().post(new EventDismissNotification(Notification.OLD_NS));

View file

@ -53,6 +53,7 @@ public class BgReading implements DataPointWithLabelInterface {
value = sgv.getMgdl(); value = sgv.getMgdl();
raw = sgv.getFiltered() != null ? sgv.getFiltered() : value; raw = sgv.getFiltered() != null ? sgv.getFiltered() : value;
direction = sgv.getDirection(); direction = sgv.getDirection();
_id = sgv.getId();
} }
public Double valueToUnits(String units) { public Double valueToUnits(String units) {

View file

@ -367,6 +367,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return false; return false;
} }
public void update(BgReading bgReading) {
bgReading.date = roundDateToSec(bgReading.date);
try {
getDaoBgReadings().update(bgReading);
} catch (SQLException e) {
e.printStackTrace();
}
}
private static void scheduleBgChange() { private static void scheduleBgChange() {
class PostRunnable implements Runnable { class PostRunnable implements Runnable {
public void run() { public void run() {
@ -397,7 +406,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder(); QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
queryBuilder.orderBy("date", false); queryBuilder.orderBy("date", false);
queryBuilder.limit(1L); queryBuilder.limit(1L);
queryBuilder.where().gt("value", 38); queryBuilder.where().gt("value", 38).and().eq("isValid", true);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare(); PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgList = daoBgReadings.query(preparedQuery); bgList = daoBgReadings.query(preparedQuery);
@ -435,7 +444,24 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
QueryBuilder<BgReading, Long> queryBuilder = daoBgreadings.queryBuilder(); QueryBuilder<BgReading, Long> queryBuilder = daoBgreadings.queryBuilder();
queryBuilder.orderBy("date", ascending); queryBuilder.orderBy("date", ascending);
Where where = queryBuilder.where(); Where where = queryBuilder.where();
where.ge("date", mills).and().gt("value", 38); where.ge("date", mills).and().gt("value", 38).and().eq("isValid", true);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgReadings = daoBgreadings.query(preparedQuery);
return bgReadings;
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return new ArrayList<BgReading>();
}
public List<BgReading> getAllBgreadingsDataFromTime(long mills, boolean ascending) {
try {
Dao<BgReading, Long> daoBgreadings = getDaoBgReadings();
List<BgReading> bgReadings;
QueryBuilder<BgReading, Long> queryBuilder = daoBgreadings.queryBuilder();
queryBuilder.orderBy("date", ascending);
Where where = queryBuilder.where();
where.ge("date", mills);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare(); PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgReadings = daoBgreadings.query(preparedQuery); bgReadings = daoBgreadings.query(preparedQuery);
return bgReadings; return bgReadings;

View file

@ -127,8 +127,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
return; return;
} }
final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
boolean allowProfileSwitch = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getProfileList().size() > 1; if (!pump.getPumpDescription().isSetBasalProfileCapable || !pump.isInitialized() || pump.isSuspended())
if (!pump.getPumpDescription().isSetBasalProfileCapable || !pump.isInitialized() || pump.isSuspended() || !allowProfileSwitch)
profileSwitch.setVisibility(View.GONE); profileSwitch.setVisibility(View.GONE);
else else
profileSwitch.setVisibility(View.VISIBLE); profileSwitch.setVisibility(View.VISIBLE);

View file

@ -96,6 +96,8 @@ public class UploadQueue {
} }
public static void removeID(final String action, final String _id) { public static void removeID(final String action, final String _id) {
if (_id == null || _id.equals(""))
return;
startService(); startService();
if (NSClientService.handler != null) { if (NSClientService.handler != null) {
NSClientService.handler.post(new Runnable() { NSClientService.handler.post(new Runnable() {

View file

@ -1,10 +1,7 @@
package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts; package info.nightscout.androidaps.plugins.NSClientInternal.broadcasts;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.TransactionTooLargeException;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONArray; import org.json.JSONArray;
@ -19,9 +16,7 @@ import java.util.List;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils;
/** /**
* Created by mike on 20.02.2016. * Created by mike on 20.02.2016.
@ -29,31 +24,31 @@ import info.nightscout.utils.ToastUtils;
public class BroadcastTreatment { public class BroadcastTreatment {
private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class); private static Logger log = LoggerFactory.getLogger(BroadcastTreatment.class);
public static void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) { public static void handleNewTreatment(JSONObject treatment, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.getData().toString()); bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle(); bundle = new Bundle();
bundle.putString("treatment", treatment.getData().toString()); bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_TREATMENT); intent = new Intent(Intents.ACTION_NEW_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); MainApp.instance().getApplicationContext().sendBroadcast(intent);
} }
} }
public static void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) { public static void handleNewTreatment(JSONArray treatments, boolean isDelta) {
List<JSONArray> splitted = splitArray(treatments); List<JSONArray> splitted = splitArray(treatments);
for (JSONArray part: splitted) { for (JSONArray part : splitted) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatments", part.toString()); bundle.putString("treatments", part.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
@ -63,21 +58,21 @@ public class BroadcastTreatment {
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
} }
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)){ if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
splitted = splitArray(treatments); splitted = splitArray(treatments);
for (JSONArray part: splitted) { for (JSONArray part : splitted) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatments", part.toString()); bundle.putString("treatments", part.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); MainApp.instance().getApplicationContext().sendBroadcast(intent);
} }
} }
} }
public void handleChangedTreatment(JSONObject treatment, Context context, boolean isDelta) { public void handleChangedTreatment(JSONObject treatment, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString()); bundle.putString("treatment", treatment.toString());
@ -88,18 +83,18 @@ public class BroadcastTreatment {
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle(); bundle = new Bundle();
bundle.putString("treatment", treatment.toString()); bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); MainApp.instance().getApplicationContext().sendBroadcast(intent);
} }
} }
public static void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) { public static void handleChangedTreatment(JSONArray treatments, boolean isDelta) {
List<JSONArray> splitted = splitArray(treatments); List<JSONArray> splitted = splitArray(treatments);
for (JSONArray part : splitted) { for (JSONArray part : splitted) {
@ -112,7 +107,7 @@ public class BroadcastTreatment {
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
} }
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
splitted = splitArray(treatments); splitted = splitArray(treatments);
for (JSONArray part : splitted) { for (JSONArray part : splitted) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -121,12 +116,12 @@ public class BroadcastTreatment {
Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); MainApp.instance().getApplicationContext().sendBroadcast(intent);
} }
} }
} }
public static void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) { public static void handleRemovedTreatment(JSONObject treatment, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString()); bundle.putString("treatment", treatment.toString());
@ -137,18 +132,18 @@ public class BroadcastTreatment {
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle(); bundle = new Bundle();
bundle.putString("treatment", treatment.toString()); bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); MainApp.instance().getApplicationContext().sendBroadcast(intent);
} }
} }
public static void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) { public static void handleRemovedTreatment(JSONArray treatments, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatments", treatments.toString()); bundle.putString("treatments", treatments.toString());
@ -159,14 +154,14 @@ public class BroadcastTreatment {
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) { if (SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle(); bundle = new Bundle();
bundle.putString("treatments", treatments.toString()); bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); MainApp.instance().getApplicationContext().sendBroadcast(intent);
} }
} }

View file

@ -63,5 +63,6 @@ public class NSSgv {
public Long getMills () { return getLongOrNull("mills"); } public Long getMills () { return getLongOrNull("mills"); }
public String getDevice () { return getStringOrNull("device"); } public String getDevice () { return getStringOrNull("device"); }
public String getDirection () { return getStringOrNull("direction"); } public String getDirection () { return getStringOrNull("direction"); }
public String getId () { return getStringOrNull("_id"); }
} }

View file

@ -11,16 +11,14 @@ import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.DbRequest;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck; import info.nightscout.utils.DateUtil;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
public class DBAccessReceiver extends BroadcastReceiver { public class DBAccessReceiver extends BroadcastReceiver {
@ -89,7 +87,12 @@ public class DBAccessReceiver extends BroadcastReceiver {
UploadQueue.add(dbr); UploadQueue.add(dbr);
} else { } else {
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), data); DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), data);
// this is not used as mongo _id but only for searching in UploadQueue database
// if record has to be removed from queue before upload
dbr._id = nsclientid.toString();
UploadQueue.add(dbr); UploadQueue.add(dbr);
if (collection.equals("treatments"))
genereateTreatmentOfflineBroadcast(dbr);
} }
} finally { } finally {
@ -98,6 +101,19 @@ public class DBAccessReceiver extends BroadcastReceiver {
} }
public void genereateTreatmentOfflineBroadcast(DbRequest request) {
if (request.action.equals("dbAdd")) {
try {
JSONObject data = new JSONObject(request.data);
data.put("mills", DateUtil.fromISODateString(data.getString("created_at")).getTime());
data.put("_id", data.get("NSCLIENT_ID")); // this is only fake id
BroadcastTreatment.handleNewTreatment(data, false);
} catch (Exception e) {
log.error("Unhadled exception", e);
}
}
}
private boolean isAllowedCollection(String collection) { private boolean isAllowedCollection(String collection) {
// "treatments" || "entries" || "devicestatus" || "profile" || "food" // "treatments" || "entries" || "devicestatus" || "profile" || "food"
if (collection.equals("treatments")) return true; if (collection.equals("treatments")) return true;

View file

@ -52,15 +52,15 @@ import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastS
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment; import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastUrgentAlarm; import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastUrgentAlarm;
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck; import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientRestart;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import io.socket.client.IO; import io.socket.client.IO;
@ -310,17 +310,17 @@ public class NSClientService extends Service {
}; };
private Emitter.Listener onAnnouncement = new Emitter.Listener() { private Emitter.Listener onAnnouncement = new Emitter.Listener() {
/* /*
{ {
"level":0, "level":0,
"title":"Announcement", "title":"Announcement",
"message":"test", "message":"test",
"plugin":{"name":"treatmentnotify","label":"Treatment Notifications","pluginType":"notification","enabled":true}, "plugin":{"name":"treatmentnotify","label":"Treatment Notifications","pluginType":"notification","enabled":true},
"group":"Announcement", "group":"Announcement",
"isAnnouncement":true, "isAnnouncement":true,
"key":"9ac46ad9a1dcda79dd87dae418fce0e7955c68da" "key":"9ac46ad9a1dcda79dd87dae418fce0e7955c68da"
} }
*/ */
@Override @Override
public void call(final Object... args) { public void call(final Object... args) {
JSONObject data; JSONObject data;
@ -342,19 +342,19 @@ public class NSClientService extends Service {
}; };
private Emitter.Listener onAlarm = new Emitter.Listener() { private Emitter.Listener onAlarm = new Emitter.Listener() {
/* /*
{ {
"level":1, "level":1,
"title":"Warning HIGH", "title":"Warning HIGH",
"message":"BG Now: 5 -0.2 → mmol\/L\nRaw BG: 4.8 mmol\/L Čistý\nBG 15m: 4.8 mmol\/L\nIOB: -0.02U\nCOB: 0g", "message":"BG Now: 5 -0.2 → mmol\/L\nRaw BG: 4.8 mmol\/L Čistý\nBG 15m: 4.8 mmol\/L\nIOB: -0.02U\nCOB: 0g",
"eventName":"high", "eventName":"high",
"plugin":{"name":"simplealarms","label":"Simple Alarms","pluginType":"notification","enabled":true}, "plugin":{"name":"simplealarms","label":"Simple Alarms","pluginType":"notification","enabled":true},
"pushoverSound":"climb", "pushoverSound":"climb",
"debug":{"lastSGV":5,"thresholds":{"bgHigh":180,"bgTargetTop":75,"bgTargetBottom":72,"bgLow":70}}, "debug":{"lastSGV":5,"thresholds":{"bgHigh":180,"bgTargetTop":75,"bgTargetBottom":72,"bgLow":70}},
"group":"default", "group":"default",
"key":"simplealarms_1" "key":"simplealarms_1"
} }
*/ */
@Override @Override
public void call(final Object... args) { public void call(final Object... args) {
if (Config.detailedLog) if (Config.detailedLog)
@ -372,19 +372,19 @@ public class NSClientService extends Service {
}; };
private Emitter.Listener onUrgentAlarm = new Emitter.Listener() { private Emitter.Listener onUrgentAlarm = new Emitter.Listener() {
/* /*
{ {
"level":2, "level":2,
"title":"Urgent HIGH", "title":"Urgent HIGH",
"message":"BG Now: 5.2 -0.1 → mmol\/L\nRaw BG: 5 mmol\/L Čistý\nBG 15m: 5 mmol\/L\nIOB: 0.00U\nCOB: 0g", "message":"BG Now: 5.2 -0.1 → mmol\/L\nRaw BG: 5 mmol\/L Čistý\nBG 15m: 5 mmol\/L\nIOB: 0.00U\nCOB: 0g",
"eventName":"high", "eventName":"high",
"plugin":{"name":"simplealarms","label":"Simple Alarms","pluginType":"notification","enabled":true}, "plugin":{"name":"simplealarms","label":"Simple Alarms","pluginType":"notification","enabled":true},
"pushoverSound":"persistent", "pushoverSound":"persistent",
"debug":{"lastSGV":5.2,"thresholds":{"bgHigh":80,"bgTargetTop":75,"bgTargetBottom":72,"bgLow":70}}, "debug":{"lastSGV":5.2,"thresholds":{"bgHigh":80,"bgTargetTop":75,"bgTargetBottom":72,"bgLow":70}},
"group":"default", "group":"default",
"key":"simplealarms_2" "key":"simplealarms_2"
} }
*/ */
@Override @Override
public void call(final Object... args) { public void call(final Object... args) {
JSONObject data; JSONObject data;
@ -402,14 +402,14 @@ public class NSClientService extends Service {
}; };
private Emitter.Listener onClearAlarm = new Emitter.Listener() { private Emitter.Listener onClearAlarm = new Emitter.Listener() {
/* /*
{ {
"clear":true, "clear":true,
"title":"All Clear", "title":"All Clear",
"message":"default - Urgent was ack'd", "message":"default - Urgent was ack'd",
"group":"default" "group":"default"
} }
*/ */
@Override @Override
public void call(final Object... args) { public void call(final Object... args) {
JSONObject data; JSONObject data;
@ -520,17 +520,17 @@ public class NSClientService extends Service {
updatedTreatments.put(jsonTreatment); updatedTreatments.put(jsonTreatment);
} else if (treatment.getAction().equals("remove")) { } else if (treatment.getAction().equals("remove")) {
if (treatment.getMills() != null && treatment.getMills() > System.currentTimeMillis() - 24 * 60 * 60 * 1000L) // handle 1 day old deletions only if (treatment.getMills() != null && treatment.getMills() > System.currentTimeMillis() - 24 * 60 * 60 * 1000L) // handle 1 day old deletions only
removedTreatments.put(jsonTreatment); removedTreatments.put(jsonTreatment);
} }
} }
if (removedTreatments.length() > 0) { if (removedTreatments.length() > 0) {
BroadcastTreatment.handleRemovedTreatment(removedTreatments, MainApp.instance().getApplicationContext(), isDelta); BroadcastTreatment.handleRemovedTreatment(removedTreatments, isDelta);
} }
if (updatedTreatments.length() > 0) { if (updatedTreatments.length() > 0) {
BroadcastTreatment.handleChangedTreatment(updatedTreatments, MainApp.instance().getApplicationContext(), isDelta); BroadcastTreatment.handleChangedTreatment(updatedTreatments, isDelta);
} }
if (addedTreatments.length() > 0) { if (addedTreatments.length() > 0) {
BroadcastTreatment.handleNewTreatment(addedTreatments, MainApp.instance().getApplicationContext(), isDelta); BroadcastTreatment.handleNewTreatment(addedTreatments, isDelta);
} }
} }
if (data.has("devicestatus")) { if (data.has("devicestatus")) {
@ -634,12 +634,12 @@ public class NSClientService extends Service {
} }
// Was that sgv more less 15 mins ago ? // Was that sgv more less 15 mins ago ?
boolean lessThan15MinAgo = false; boolean lessThan15MinAgo = false;
if((System.currentTimeMillis()-latestDateInReceivedData)/(60 * 1000L) < 15L ) if ((System.currentTimeMillis() - latestDateInReceivedData) / (60 * 1000L) < 15L)
lessThan15MinAgo = true; lessThan15MinAgo = true;
if(Notification.isAlarmForStaleData() && lessThan15MinAgo){ if (Notification.isAlarmForStaleData() && lessThan15MinAgo) {
MainApp.bus().post(new EventDismissNotification(Notification.NSALARM)); MainApp.bus().post(new EventDismissNotification(Notification.NSALARM));
} }
BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta); BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
} }
MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData))); MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData)));
} catch (JSONException e) { } catch (JSONException e) {
@ -757,7 +757,7 @@ public class NSClientService extends Service {
public void run() { public void run() {
if (mSocket == null || !mSocket.connected()) return; if (mSocket == null || !mSocket.connected()) return;
if (lastResendTime > System.currentTimeMillis() - 10 * 1000L) { if (lastResendTime > System.currentTimeMillis() - 10 * 1000L) {
log.debug("Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec"); log.debug("Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec");
return; return;
} }

View file

@ -120,19 +120,17 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
profile = new ProfileStore(newProfile.getData()); profile = new ProfileStore(newProfile.getData());
storeNSProfile(); storeNSProfile();
MainApp.bus().post(new EventNSProfileUpdateGUI()); MainApp.bus().post(new EventNSProfileUpdateGUI());
if (SP.getBoolean(R.string.key_sync_profile_to_pump, false)) { ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() {
ConfigBuilderPlugin.getCommandQueue().setProfile(MainApp.getConfigBuilder().getProfile(), new Callback() { @Override
@Override public void run() {
public void run() { if (result.enacted) {
if (result.enacted) { SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class); if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) {
if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) { smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
}
} }
} }
}); }
} });
} }
private static void storeNSProfile() { private static void storeNSProfile() {

View file

@ -242,6 +242,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public synchronized PumpEnactResult setNewBasalProfile(Profile profile) { public synchronized PumpEnactResult setNewBasalProfile(Profile profile) {
if (!isInitialized()) { if (!isInitialized()) {
// note that this should not happen anymore since the queue is present, which
// issues a READSTATE when starting to issue commands which initializes the pump
log.error("setNewBasalProfile not initialized"); log.error("setNewBasalProfile not initialized");
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT); Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
@ -283,9 +285,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public boolean isThisProfileSet(Profile profile) { public boolean isThisProfileSet(Profile profile) {
if (!isInitialized()) { if (!isInitialized()) {
// This is called too soon (for the Combo) on startup, so ignore this. /* This might be called too soon during boot. Return true to prevent a request
// The Combo init (refreshDataFromPump) will read the profile and update the pump's to update the profile. KeepAlive is called every Constants.keepalivems
// profile if the pref is set; and will detect the need for a profile update and apply it.
*/
return true; return true;
} }
return pump.basalProfile.equals(convertProfileToComboProfile(profile)); return pump.basalProfile.equals(convertProfileToComboProfile(profile));
@ -353,11 +356,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return; return;
} }
pump.basalProfile = readBasalResult.basalProfile; pump.basalProfile = readBasalResult.basalProfile;
Profile profile = MainApp.getConfigBuilder().getProfile();
if (!pump.basalProfile.equals(convertProfileToComboProfile(profile))) {
setNewBasalProfile(profile);
}
} }
if (!pump.initialized) { if (!pump.initialized) {
@ -801,6 +799,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
private void checkForUnsafeUsage(CommandResult commandResult) { private void checkForUnsafeUsage(CommandResult commandResult) {
if (commandResult == null) return;
long lastViolation = 0; long lastViolation = 0;
if (commandResult.state.unsafeUsageDetected) { if (commandResult.state.unsafeUsageDetected) {
lastViolation = System.currentTimeMillis(); lastViolation = System.currentTimeMillis();

View file

@ -7,8 +7,10 @@ import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback; import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanResult;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -31,7 +33,6 @@ import info.nightscout.utils.SP;
public class BLEScanActivity extends AppCompatActivity { public class BLEScanActivity extends AppCompatActivity {
private static Logger log = LoggerFactory.getLogger(BLEScanActivity.class); private static Logger log = LoggerFactory.getLogger(BLEScanActivity.class);
private Context mContext = null;
private ListView listView = null; private ListView listView = null;
private ListAdapter mListAdapter = null; private ListAdapter mListAdapter = null;
@ -53,26 +54,20 @@ public class BLEScanActivity extends AppCompatActivity {
listView.setEmptyView(findViewById(R.id.danars_blescanner_nodevice)); listView.setEmptyView(findViewById(R.id.danars_blescanner_nodevice));
listView.setAdapter(mListAdapter); listView.setAdapter(mListAdapter);
initView();
}
private void initView() {
mContext = getApplicationContext();
BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
// MIKE: test mBluetoothLeScanner for null (bt disabled)
mListAdapter.notifyDataSetChanged(); mListAdapter.notifyDataSetChanged();
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
if (mBluetoothLeScanner == null) {
mBluetoothAdapter.enable();
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
}
startScan(); startScan();
} }
@ -138,7 +133,7 @@ public class BLEScanActivity extends AppCompatActivity {
ViewHolder holder; ViewHolder holder;
if (v == null) { if (v == null) {
v = View.inflate(mContext, R.layout.danars_blescanner_item, null); v = View.inflate(getApplicationContext(), R.layout.danars_blescanner_item, null);
holder = new ViewHolder(v); holder = new ViewHolder(v);
v.setTag(holder); v.setTag(holder);
} else { } else {

View file

@ -0,0 +1,172 @@
package info.nightscout.androidaps.plugins.SourceDexcomG5;
import android.app.Activity;
import android.content.DialogInterface;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.NSUpload;
/**
* Created by mike on 16.10.2017.
*/
public class BGSourceFragment extends SubscriberFragment {
private static Logger log = LoggerFactory.getLogger(BGSourceFragment.class);
RecyclerView recyclerView;
Profile profile;
final long MILLS_TO_THE_PAST = 12 * 60 * 60 * 1000L;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.bgsource_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.bgsource_recyclerview);
recyclerView.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm);
long now = System.currentTimeMillis();
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false));
recyclerView.setAdapter(adapter);
profile = ConfigBuilderPlugin.getActiveProfileInterface().getProfile().getDefaultProfile();
return view;
} catch (Exception e) {
Crashlytics.logException(e);
}
return null;
}
@Subscribe
@SuppressWarnings("unused")
public void onStatusEvent(final EventNewBG ev) {
updateGUI();
}
@Override
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
long now = System.currentTimeMillis();
recyclerView.swapAdapter(new BGSourceFragment.RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false)), true);
}
});
}
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.BgReadingsViewHolder> {
List<BgReading> bgReadings;
RecyclerViewAdapter(List<BgReading> bgReadings) {
this.bgReadings = bgReadings;
}
@Override
public BgReadingsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.bgsource_item, viewGroup, false);
return new BgReadingsViewHolder(v);
}
@Override
public void onBindViewHolder(BgReadingsViewHolder holder, int position) {
BgReading bgReading = bgReadings.get(position);
holder.ns.setVisibility(NSUpload.isIdValid(bgReading._id) ? View.VISIBLE : View.GONE);
holder.invalid.setVisibility(!bgReading.isValid ? View.VISIBLE : View.GONE);
holder.date.setText(DateUtil.dateAndTimeString(bgReading.date));
holder.value.setText(bgReading.valueToUnitsToString(profile.getUnits()));
holder.direction.setText(bgReading.directionToSymbol());
holder.remove.setTag(bgReading);
}
@Override
public int getItemCount() {
return bgReadings.size();
}
class BgReadingsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView date;
TextView value;
TextView direction;
TextView invalid;
TextView ns;
TextView remove;
BgReadingsViewHolder(View itemView) {
super(itemView);
date = (TextView) itemView.findViewById(R.id.bgsource_date);
value = (TextView) itemView.findViewById(R.id.bgsource_value);
direction = (TextView) itemView.findViewById(R.id.bgsource_direction);
invalid = (TextView) itemView.findViewById(R.id.invalid_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
remove = (TextView) itemView.findViewById(R.id.bgsource_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
@Override
public void onClick(View v) {
final BgReading bgReading = (BgReading) v.getTag();
switch (v.getId()) {
case R.id.bgsource_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(profile.getUnits()));
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
final String _id = bgReading._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeFoodFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
bgReading.isValid = false;
MainApp.getDbHelper().update(bgReading);
updateGUI();
}
});
builder.setNegativeButton(MainApp.sResources.getString(R.string.cancel), null);
builder.show();
break;
}
}
}
}
}

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
public class SourceDexcomG5Plugin implements PluginBase, BgSourceInterface { public class SourceDexcomG5Plugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = false; private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static SourceDexcomG5Plugin plugin = null; private static SourceDexcomG5Plugin plugin = null;
@ -23,7 +24,7 @@ public class SourceDexcomG5Plugin implements PluginBase, BgSourceInterface {
@Override @Override
public String getFragmentClass() { public String getFragmentClass() {
return null; return BGSourceFragment.class.getName();
} }
@Override @Override
@ -49,7 +50,7 @@ public class SourceDexcomG5Plugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean isVisibleInTabs(int type) { public boolean isVisibleInTabs(int type) {
return false; return Config.G5UPLOADER || type == BGSOURCE && fragmentVisible;
} }
@Override @Override
@ -59,7 +60,7 @@ public class SourceDexcomG5Plugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean hasFragment() { public boolean hasFragment() {
return false; return true;
} }
@Override @Override
@ -74,7 +75,7 @@ public class SourceDexcomG5Plugin implements PluginBase, BgSourceInterface {
@Override @Override
public void setFragmentVisible(int type, boolean fragmentVisible) { public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
} }
@Override @Override

View file

@ -4,12 +4,14 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class SourceGlimpPlugin implements PluginBase, BgSourceInterface { public class SourceGlimpPlugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = false; private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static SourceGlimpPlugin plugin = null; private static SourceGlimpPlugin plugin = null;
@ -21,7 +23,7 @@ public class SourceGlimpPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public String getFragmentClass() { public String getFragmentClass() {
return null; return BGSourceFragment.class.getName();
} }
@Override @Override
@ -47,7 +49,7 @@ public class SourceGlimpPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean isVisibleInTabs(int type) { public boolean isVisibleInTabs(int type) {
return false; return type == BGSOURCE && fragmentVisible;
} }
@Override @Override
@ -57,7 +59,7 @@ public class SourceGlimpPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean hasFragment() { public boolean hasFragment() {
return false; return true;
} }
@Override @Override
@ -72,7 +74,7 @@ public class SourceGlimpPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public void setFragmentVisible(int type, boolean fragmentVisible) { public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
} }
@Override @Override

View file

@ -4,12 +4,14 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class SourceMM640gPlugin implements PluginBase, BgSourceInterface { public class SourceMM640gPlugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = false; private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static SourceMM640gPlugin plugin = null; private static SourceMM640gPlugin plugin = null;
@ -21,7 +23,7 @@ public class SourceMM640gPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public String getFragmentClass() { public String getFragmentClass() {
return null; return BGSourceFragment.class.getName();
} }
@Override @Override
@ -47,7 +49,7 @@ public class SourceMM640gPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean isVisibleInTabs(int type) { public boolean isVisibleInTabs(int type) {
return false; return type == BGSOURCE && fragmentVisible;
} }
@Override @Override
@ -57,7 +59,7 @@ public class SourceMM640gPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean hasFragment() { public boolean hasFragment() {
return false; return true;
} }
@Override @Override
@ -72,7 +74,7 @@ public class SourceMM640gPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public void setFragmentVisible(int type, boolean fragmentVisible) { public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
} }
@Override @Override

View file

@ -5,12 +5,14 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class SourceNSClientPlugin implements PluginBase, BgSourceInterface { public class SourceNSClientPlugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = true; private boolean fragmentEnabled = true;
private boolean fragmentVisible = false;
private static SourceNSClientPlugin plugin = null; private static SourceNSClientPlugin plugin = null;
@ -22,7 +24,7 @@ public class SourceNSClientPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public String getFragmentClass() { public String getFragmentClass() {
return null; return BGSourceFragment.class.getName();
} }
@Override @Override
@ -32,7 +34,7 @@ public class SourceNSClientPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public String getName() { public String getName() {
return MainApp.instance().getString(R.string.nsclient); return MainApp.instance().getString(R.string.nsclientbg);
} }
@Override @Override
@ -49,7 +51,7 @@ public class SourceNSClientPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean isVisibleInTabs(int type) { public boolean isVisibleInTabs(int type) {
return false; return type == BGSOURCE && fragmentVisible;
} }
@Override @Override
@ -59,7 +61,7 @@ public class SourceNSClientPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean hasFragment() { public boolean hasFragment() {
return false; return true;
} }
@Override @Override
@ -74,7 +76,7 @@ public class SourceNSClientPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public void setFragmentVisible(int type, boolean fragmentVisible) { public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
} }
@Override @Override

View file

@ -4,12 +4,16 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class SourceXdripPlugin implements PluginBase, BgSourceInterface { public class SourceXdripPlugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static SourceXdripPlugin plugin = null; private static SourceXdripPlugin plugin = null;
public static SourceXdripPlugin getPlugin() { public static SourceXdripPlugin getPlugin() {
@ -20,11 +24,9 @@ public class SourceXdripPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public String getFragmentClass() { public String getFragmentClass() {
return null; return BGSourceFragment.class.getName();
} }
private boolean fragmentEnabled = false;
@Override @Override
public int getType() { public int getType() {
return PluginBase.BGSOURCE; return PluginBase.BGSOURCE;
@ -48,7 +50,7 @@ public class SourceXdripPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean isVisibleInTabs(int type) { public boolean isVisibleInTabs(int type) {
return false; return type == BGSOURCE && fragmentVisible;
} }
@Override @Override
@ -58,7 +60,7 @@ public class SourceXdripPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public boolean hasFragment() { public boolean hasFragment() {
return false; return true;
} }
@Override @Override
@ -73,6 +75,7 @@ public class SourceXdripPlugin implements PluginBase, BgSourceInterface {
@Override @Override
public void setFragmentVisible(int type, boolean fragmentVisible) { public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
} }
@Override @Override

View file

@ -36,6 +36,7 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
@ -82,7 +83,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U"); holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U");
holder.mealOrCorrection.setText(t.mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous)); holder.mealOrCorrection.setText(t.mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous));
holder.ph.setVisibility(t.source == Source.PUMP ? View.VISIBLE : View.GONE); holder.ph.setVisibility(t.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(t._id != null ? View.VISIBLE : View.GONE); holder.ns.setVisibility(NSUpload.isIdValid(t._id) ? View.VISIBLE : View.GONE);
holder.invalid.setVisibility(t.isValid ? View.GONE : View.VISIBLE); holder.invalid.setVisibility(t.isValid ? View.GONE : View.VISIBLE);
if (iob.iobContrib != 0) if (iob.iobContrib != 0)
holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)); holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
@ -146,8 +147,10 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
treatment.isValid = false; treatment.isValid = false;
MainApp.getDbHelper().update(treatment); MainApp.getDbHelper().update(treatment);
} else { } else {
if (_id != null && !_id.equals("")) { if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id); NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
} }
MainApp.getDbHelper().delete(treatment); MainApp.getDbHelper().delete(treatment);
} }

View file

@ -31,6 +31,7 @@ import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
@ -63,7 +64,7 @@ public class TreatmentsExtendedBolusesFragment extends SubscriberFragment {
public void onBindViewHolder(ExtendedBolusesViewHolder holder, int position) { public void onBindViewHolder(ExtendedBolusesViewHolder holder, int position) {
ExtendedBolus extendedBolus = extendedBolusList.getReversed(position); ExtendedBolus extendedBolus = extendedBolusList.getReversed(position);
holder.ph.setVisibility(extendedBolus.source == Source.PUMP ? View.VISIBLE : View.GONE); holder.ph.setVisibility(extendedBolus.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(extendedBolus._id != null ? View.VISIBLE : View.GONE); holder.ns.setVisibility(NSUpload.isIdValid(extendedBolus._id) ? View.VISIBLE : View.GONE);
if (extendedBolus.isEndingEvent()) { if (extendedBolus.isEndingEvent()) {
holder.date.setText(DateUtil.dateAndTimeString(extendedBolus.date)); holder.date.setText(DateUtil.dateAndTimeString(extendedBolus.date));
holder.duration.setText(MainApp.sResources.getString(R.string.cancel)); holder.duration.setText(MainApp.sResources.getString(R.string.cancel));
@ -148,8 +149,10 @@ public class TreatmentsExtendedBolusesFragment extends SubscriberFragment {
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
final String _id = extendedBolus._id; final String _id = extendedBolus._id;
if (_id != null && !_id.equals("")) { if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id); NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
} }
MainApp.getDbHelper().delete(extendedBolus); MainApp.getDbHelper().delete(extendedBolus);
Answers.getInstance().logCustom(new CustomEvent("RemoveExtendedBolus")); Answers.getInstance().logCustom(new CustomEvent("RemoveExtendedBolus"));

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.events.EventProfileSwitchChange;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
@ -66,7 +67,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
if (profile == null) return; if (profile == null) return;
ProfileSwitch profileSwitch = profileSwitchList.getReversed(position); ProfileSwitch profileSwitch = profileSwitchList.getReversed(position);
holder.ph.setVisibility(profileSwitch.source == Source.PUMP ? View.VISIBLE : View.GONE); holder.ph.setVisibility(profileSwitch.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(profileSwitch._id != null ? View.VISIBLE : View.GONE); holder.ns.setVisibility(NSUpload.isIdValid(profileSwitch._id) ? View.VISIBLE : View.GONE);
holder.date.setText(DateUtil.dateAndTimeString(profileSwitch.date)); holder.date.setText(DateUtil.dateAndTimeString(profileSwitch.date));
if (!profileSwitch.isEndingEvent()) { if (!profileSwitch.isEndingEvent()) {
@ -131,8 +132,10 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
final String _id = profileSwitch._id; final String _id = profileSwitch._id;
if (_id != null && !_id.equals("")) { if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id); NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
} }
MainApp.getDbHelper().delete(profileSwitch); MainApp.getDbHelper().delete(profileSwitch);
} }

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.events.EventTempTargetChange;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
@ -67,7 +68,7 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements
String units = MainApp.getConfigBuilder().getProfileUnits(); String units = MainApp.getConfigBuilder().getProfileUnits();
TempTarget tempTarget = tempTargetList.getReversed(position); TempTarget tempTarget = tempTargetList.getReversed(position);
holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE); holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(tempTarget._id != null ? View.VISIBLE : View.GONE); holder.ns.setVisibility(NSUpload.isIdValid(tempTarget._id) ? View.VISIBLE : View.GONE);
if (!tempTarget.isEndingEvent()) { if (!tempTarget.isEndingEvent()) {
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date) + " - " + DateUtil.timeString(tempTarget.originalEnd())); holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date) + " - " + DateUtil.timeString(tempTarget.originalEnd()));
holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.durationInMinutes) + " min"); holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.durationInMinutes) + " min");
@ -149,8 +150,10 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
final String _id = tempTarget._id; final String _id = tempTarget._id;
if (_id != null && !_id.equals("")) { if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id); NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
} }
MainApp.getDbHelper().delete(tempTarget); MainApp.getDbHelper().delete(tempTarget);
} }

View file

@ -31,6 +31,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
@ -65,7 +66,7 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment {
public void onBindViewHolder(TempBasalsViewHolder holder, int position) { public void onBindViewHolder(TempBasalsViewHolder holder, int position) {
TemporaryBasal tempBasal = tempBasalList.getReversed(position); TemporaryBasal tempBasal = tempBasalList.getReversed(position);
holder.ph.setVisibility(tempBasal.source == Source.PUMP ? View.VISIBLE : View.GONE); holder.ph.setVisibility(tempBasal.source == Source.PUMP ? View.VISIBLE : View.GONE);
holder.ns.setVisibility(tempBasal._id != null ? View.VISIBLE : View.GONE); holder.ns.setVisibility(NSUpload.isIdValid(tempBasal._id) ? View.VISIBLE : View.GONE);
if (tempBasal.isEndingEvent()) { if (tempBasal.isEndingEvent()) {
holder.date.setText(DateUtil.dateAndTimeString(tempBasal.date)); holder.date.setText(DateUtil.dateAndTimeString(tempBasal.date));
holder.duration.setText(MainApp.sResources.getString(R.string.cancel)); holder.duration.setText(MainApp.sResources.getString(R.string.cancel));
@ -165,8 +166,10 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment {
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
final String _id = tempBasal._id; final String _id = tempBasal._id;
if (_id != null && !_id.equals("")) { if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id); NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
} }
MainApp.getDbHelper().delete(tempBasal); MainApp.getDbHelper().delete(tempBasal);
Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal")); Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal"));

View file

@ -28,6 +28,7 @@ public class QueueThread extends Thread {
private CommandQueue queue; private CommandQueue queue;
private long lastCommandTime = 0;
private boolean connectLogged = false; private boolean connectLogged = false;
private PowerManager.WakeLock mWakeLock; private PowerManager.WakeLock mWakeLock;
@ -44,7 +45,7 @@ public class QueueThread extends Thread {
public final void run() { public final void run() {
mWakeLock.acquire(); mWakeLock.acquire();
MainApp.bus().post(new EventQueueChanged()); MainApp.bus().post(new EventQueueChanged());
long connectionStartTime = System.currentTimeMillis(); long connectionStartTime = lastCommandTime = System.currentTimeMillis();
try { try {
while (true) { while (true) {
@ -106,17 +107,24 @@ public class QueueThread extends Thread {
queue.performing().execute(); queue.performing().execute();
queue.resetPerforming(); queue.resetPerforming();
MainApp.bus().post(new EventQueueChanged()); MainApp.bus().post(new EventQueueChanged());
lastCommandTime = System.currentTimeMillis();
SystemClock.sleep(100); SystemClock.sleep(100);
continue; continue;
} }
} }
if (queue.size() == 0 && queue.performing() == null) { if (queue.size() == 0 && queue.performing() == null) {
log.debug("QUEUE: queue empty. disconnect"); long secondsFromLastCommand = (System.currentTimeMillis() - lastCommandTime) / 1000;
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING)); if (secondsFromLastCommand >= 5) {
pump.disconnect("Queue empty"); log.debug("QUEUE: queue empty. disconnect");
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED)); MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTING));
return; pump.disconnect("Queue empty");
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED));
return;
} else {
log.debug("QUEUE: waiting for disconnect");
SystemClock.sleep(1000);
}
} }
} }
} finally { } finally {

View file

@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.utils.LocalAlertUtils; import info.nightscout.utils.LocalAlertUtils;
import info.nightscout.utils.SP;
public class KeepAliveReceiver extends BroadcastReceiver { public class KeepAliveReceiver extends BroadcastReceiver {
private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class); private static Logger log = LoggerFactory.getLogger(KeepAliveReceiver.class);

View file

@ -493,4 +493,11 @@ public class NSUpload {
} }
public static boolean isIdValid(String _id) {
if (_id == null)
return false;
if (_id.length() == 24)
return true;
return false;
}
} }

View file

@ -0,0 +1,22 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/bgsource_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</FrameLayout>

View file

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/bgsource_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardBackgroundColor="@color/cardColorBackground"
card_view:cardCornerRadius="6dp"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/bgsource_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="16:55"
android:textStyle="bold" />
<TextView
android:id="@+id/bgsource_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:text="Name"
android:textStyle="bold" />
<TextView
android:id="@+id/bgsource_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingStart="10dp"
android:text="-" />
<TextView
android:id="@+id/ns_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:text="NS"
android:textAlignment="viewEnd"
android:textColor="@color/colorSetTempButton" />
<TextView
android:id="@+id/invalid_sign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:text="@string/invalid"
android:textColor="@android:color/holo_red_light" />
<TextView
android:id="@+id/bgsource_remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="5dp"
android:paddingStart="10dp"
android:text="@string/overview_quickwizard_item_remove_button"
android:textAlignment="viewEnd"
android:textColor="@android:color/holo_orange_light" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View file

@ -790,6 +790,7 @@
<string name="dexcomg5_xdripupload_title">Send BG data to xDrip+</string> <string name="dexcomg5_xdripupload_title">Send BG data to xDrip+</string>
<string name="key_dexcomg5_xdripupload" translatable="false">dexcomg5_xdripupload</string> <string name="key_dexcomg5_xdripupload" translatable="false">dexcomg5_xdripupload</string>
<string name="dexcomg5_xdripupload_summary">In xDrip+ select 640g/Eversense data source</string> <string name="dexcomg5_xdripupload_summary">In xDrip+ select 640g/Eversense data source</string>
<string name="nsclientbg">NSClient BG</string>
<string name="bolusstopping">Stopping bolus delivery</string> <string name="bolusstopping">Stopping bolus delivery</string>
<string name="bolusstopped">Bolus delivery stopped</string> <string name="bolusstopped">Bolus delivery stopped</string>
<string name="combo_programming_bolus">Programming pump for bolusing</string> <string name="combo_programming_bolus">Programming pump for bolusing</string>

View file

@ -187,10 +187,10 @@ public class RuffyScripter implements RuffyCommands {
if (!ruffyService.isConnected()) { if (!ruffyService.isConnected()) {
return false; return false;
} }
if (System.currentTimeMillis() - menuLastUpdated >= 500) { if (System.currentTimeMillis() - menuLastUpdated >= 1500) {
waitForScreenUpdate(); waitForScreenUpdate();
} }
return System.currentTimeMillis() - menuLastUpdated < 500; return System.currentTimeMillis() - menuLastUpdated < 1500;
} catch (RemoteException e) { } catch (RemoteException e) {
return false; return false;
} }
@ -241,7 +241,7 @@ public class RuffyScripter implements RuffyCommands {
List<String> violations = cmd.validateArguments(); List<String> violations = cmd.validateArguments();
if (!violations.isEmpty()) { if (!violations.isEmpty()) {
log.error("Command argument violations: " + Joiner.on(", ").join(violations)); log.error("Command argument violations: " + Joiner.on(", ").join(violations));
return new CommandResult().success(false).state(readPumpStateInternal()); return new CommandResult().success(false).state(new PumpState());
} }
synchronized (RuffyScripter.class) { synchronized (RuffyScripter.class) {
@ -282,7 +282,9 @@ public class RuffyScripter implements RuffyCommands {
// on connection loss try to reconnect, confirm warning alerts caused by // on connection loss try to reconnect, confirm warning alerts caused by
// the disconnected and then return the command as failed (the caller // the disconnected and then return the command as failed (the caller
// can retry if needed). // can retry if needed).
log.debug("Connection unusable, aborting command and attempting reconnect ..."); log.debug("Connection unusable (ruffy connection: " + ruffyService.isConnected() + ", "
+ "time since last menu update: " + (System.currentTimeMillis() - menuLastUpdated) + " ms, "
+ "aborting command and attempting reconnect ...");
cmdThread.interrupt(); cmdThread.interrupt();
activeCmd.getResult().success = false; activeCmd.getResult().success = false;
@ -324,12 +326,12 @@ public class RuffyScripter implements RuffyCommands {
return result; return result;
} catch (CommandException e) { } catch (CommandException e) {
log.error("CommandException while executing command", e); log.error("CommandException while executing command", e);
recoverFromCommandFailure(); PumpState pumpState = recoverFromCommandFailure();
return activeCmd.getResult().success(false).state(readPumpStateInternal()); return activeCmd.getResult().success(false).state(pumpState);
} catch (Exception e) { } catch (Exception e) {
log.error("Unexpected exception communication with ruffy", e); log.error("Unexpected exception communication with ruffy", e);
recoverFromCommandFailure(); PumpState pumpState = recoverFromCommandFailure();
return activeCmd.getResult().success(false).state(readPumpStateInternal()); return activeCmd.getResult().success(false).state(pumpState);
} finally { } finally {
Menu menu = this.currentMenu; Menu menu = this.currentMenu;
if (activeCmd.getResult().success && menu != null && menu.getType() != MenuType.MAIN_MENU) { if (activeCmd.getResult().success && menu != null && menu.getType() != MenuType.MAIN_MENU) {
@ -416,12 +418,12 @@ public class RuffyScripter implements RuffyCommands {
/** /**
* Returns to the main menu (if possible) after a command failure, so that subsequent commands * Returns to the main menu (if possible) after a command failure, so that subsequent commands
* reusing the connection won't fail. * reusing the connection won't fail and returns the current PumpState (empty if unreadable).
*/ */
private void recoverFromCommandFailure() { private PumpState recoverFromCommandFailure() {
Menu menu = this.currentMenu; Menu menu = this.currentMenu;
if (menu == null) { if (menu == null) {
return; return new PumpState();
} }
MenuType type = menu.getType(); MenuType type = menu.getType();
if (type != MenuType.WARNING_OR_ERROR && type != MenuType.MAIN_MENU) { if (type != MenuType.WARNING_OR_ERROR && type != MenuType.MAIN_MENU) {
@ -432,6 +434,12 @@ public class RuffyScripter implements RuffyCommands {
log.warn("Error returning to main menu, when trying to recover from command failure", e); log.warn("Error returning to main menu, when trying to recover from command failure", e);
} }
} }
try {
return readPumpStateInternal();
} catch (Exception e) {
log.debug("Reading pump state during recovery failed", e);
return new PumpState();
}
} }
/** /**
@ -480,6 +488,7 @@ public class RuffyScripter implements RuffyCommands {
state.timestamp = System.currentTimeMillis(); state.timestamp = System.currentTimeMillis();
Menu menu = currentMenu; Menu menu = currentMenu;
if (menu == null) { if (menu == null) {
log.debug("Returning empty PumpState, menu is unavailable");
return state; return state;
} }