From 0d8fd9df5c7af30dbec98adda52fedc9cb49acd8 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 1 Dec 2016 09:15:33 +0100 Subject: [PATCH] wear profile may be null --- .idea/misc.xml | 2 +- .../wearintegration/WatchUpdaterService.java | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d19981032..fbb68289f4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index b9d42a72f1..426c0fe20a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -35,6 +35,7 @@ import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SafeParse; +import info.nightscout.utils.ToastUtils; public class WatchUpdaterService extends WearableListenerService implements GoogleApiClient.ConnectionCallbacks, @@ -147,14 +148,21 @@ public class WatchUpdaterService extends WearableListenerService implements if(googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) { googleApiConnect(); } if (wear_integration) { - new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMapSingleBG(lastBG, glucoseStatus)); + + final DataMap dataMap = dataMapSingleBG(lastBG, glucoseStatus); + if(dataMap==null) { + ToastUtils.showToastInUiThread(this,"No profile set yet"); + return; + } + + new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(dataMap); } } } private DataMap dataMapSingleBG(BgReading lastBG, DatabaseHelper.GlucoseStatus glucoseStatus) { NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); - + if(profile == null) return null; Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0")); Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0")); @@ -251,9 +259,16 @@ public class WatchUpdaterService extends WearableListenerService implements if (!graph_bgs.isEmpty()) { DataMap entries = dataMapSingleBG(last_bg, glucoseStatus); + if(entries==null) { + ToastUtils.showToastInUiThread(this,"No profile set yet?"); + return; + } final ArrayList dataMaps = new ArrayList<>(graph_bgs.size()); for (BgReading bg : graph_bgs) { - dataMaps.add(dataMapSingleBG(bg, glucoseStatus)); + DataMap dataMap = dataMapSingleBG(bg, glucoseStatus); + if(dataMap != null) { + dataMaps.add(dataMap); + } } entries.putDataMapArrayList("entries", dataMaps); new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).execute(entries); @@ -276,7 +291,9 @@ public class WatchUpdaterService extends WearableListenerService implements NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); - if( profile == null) return; + if(profile==null) { + return; + } long beginBasalSegmentTime = startTimeWindow; long runningTime = startTimeWindow;