From 0d8fd9df5c7af30dbec98adda52fedc9cb49acd8 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 1 Dec 2016 09:15:33 +0100 Subject: [PATCH 1/4] 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; From 68f4a2db5089c93c9baab2e1758f54cd2014e3ea Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 1 Dec 2016 10:47:39 +0100 Subject: [PATCH 2/4] wear profile-fix toast from strings.xml --- .../plugins/Wear/wearintegration/WatchUpdaterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 426c0fe20a..729b507cf9 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 @@ -151,7 +151,7 @@ public class WatchUpdaterService extends WearableListenerService implements final DataMap dataMap = dataMapSingleBG(lastBG, glucoseStatus); if(dataMap==null) { - ToastUtils.showToastInUiThread(this,"No profile set yet"); + ToastUtils.showToastInUiThread(this, getString(R.string.noprofile)); return; } From 7eb8702a9c5f9713b1efd4c1c52858c5e8a19866 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 1 Dec 2016 10:54:19 +0100 Subject: [PATCH 3/4] wear profile-null fix Toasts from strings.xml the second --- .../plugins/Wear/wearintegration/WatchUpdaterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 729b507cf9..b1d47ba9f8 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 @@ -260,7 +260,7 @@ 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?"); + ToastUtils.showToastInUiThread(this, getString(R.string.noprofile)); return; } final ArrayList dataMaps = new ArrayList<>(graph_bgs.size()); From 1af28d007f7f4eaf37be15730f553aa746de0739 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 1 Dec 2016 12:10:58 +0100 Subject: [PATCH 4/4] wear make sendData() private --- .../plugins/Wear/wearintegration/WatchUpdaterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b1d47ba9f8..fe6f4455c0 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 @@ -140,7 +140,7 @@ public class WatchUpdaterService extends WearableListenerService implements } } - public void sendData() { + private void sendData() { BgReading lastBG = MainApp.getDbHelper().lastBg(); if (lastBG != null) {