From 4d853c14350b7c92e9704961f76be489b1436477 Mon Sep 17 00:00:00 2001 From: Nico Schmitz Date: Thu, 21 Jun 2018 21:58:12 +0200 Subject: [PATCH] Check for unbound variables --- .../androidaps/HistoryBrowseActivity.java | 4 ++ .../androidaps/plugins/Loop/LoopFragment.java | 31 +++++++++++---- .../OpenAPSSMB/OpenAPSSMBFragment.java | 38 ++++++++++++++----- .../plugins/ProfileNS/NSProfileFragment.java | 3 ++ .../plugins/PumpDanaR/DanaRFragment.java | 22 ++++++++++- 5 files changed, 79 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/HistoryBrowseActivity.java b/app/src/main/java/info/nightscout/androidaps/HistoryBrowseActivity.java index 4ee7d7a97f..636db14086 100644 --- a/app/src/main/java/info/nightscout/androidaps/HistoryBrowseActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/HistoryBrowseActivity.java @@ -185,6 +185,10 @@ public class HistoryBrowseActivity extends AppCompatActivity { } void updateGUI(String from) { + + if (noProfile == null || buttonDate == null || buttonZoom == null || bgGraph == null || iobGraph == null || seekBar == null) + return; + final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); final Profile profile = MainApp.getConfigBuilder().getProfile(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java index a992a9113a..7fa810f8c0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java @@ -80,7 +80,7 @@ public class LoopFragment extends SubscriberFragment { clearGUI(); final Activity activity = getActivity(); if (activity != null) - activity.runOnUiThread(() -> { synchronized (LoopFragment.this) { lastRunView.setText(ev.text); } }); + activity.runOnUiThread(() -> { synchronized (LoopFragment.this) { if (lastRunView != null) lastRunView.setText(ev.text); } }); } @@ -90,6 +90,7 @@ public class LoopFragment extends SubscriberFragment { if (activity != null) activity.runOnUiThread(() -> { synchronized (LoopFragment.this) { + if (!isBound()) return; LoopPlugin.LastRun lastRun = LoopPlugin.lastRun; if (lastRun != null) { requestView.setText(lastRun.request != null ? lastRun.request.toSpanned() : ""); @@ -120,14 +121,28 @@ public class LoopFragment extends SubscriberFragment { if (activity != null) activity.runOnUiThread(() -> { synchronized (LoopFragment.this) { - requestView.setText(""); - constraintsProcessedView.setText(""); - sourceView.setText(""); - lastRunView.setText(""); - lastEnactView.setText(""); - tbrSetByPumpView.setText(""); - smbSetByPumpView.setText(""); + if (isBound()) { + requestView.setText(""); + constraintsProcessedView.setText(""); + sourceView.setText(""); + lastRunView.setText(""); + lastEnactView.setText(""); + tbrSetByPumpView.setText(""); + smbSetByPumpView.setText(""); + } } }); } + + boolean isBound() { + return requestView != null + && constraintsProcessedView != null + && sourceView != null + && lastRunView != null + && lastEnactView != null + && tbrSetByPumpView != null + && smbSetByPumpView != null + && constraintsView != null + && runNowButton != null; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java index 9ec11e49e9..20ccd46b40 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBFragment.java @@ -88,6 +88,7 @@ public class OpenAPSSMBFragment extends SubscriberFragment { @Override public void run() { synchronized (OpenAPSSMBFragment.this) { + if (!isBound()) return; OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin(); DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult; if (lastAPSResult != null) { @@ -129,18 +130,35 @@ public class OpenAPSSMBFragment extends SubscriberFragment { @Override public void run() { synchronized (OpenAPSSMBFragment.this) { - resultView.setText(text); - glucoseStatusView.setText(""); - currentTempView.setText(""); - iobDataView.setText(""); - profileView.setText(""); - mealDataView.setText(""); - autosensDataView.setText(""); - scriptdebugView.setText(""); - requestView.setText(""); - lastRunView.setText(""); + if (isBound()) { + resultView.setText(text); + glucoseStatusView.setText(""); + currentTempView.setText(""); + iobDataView.setText(""); + profileView.setText(""); + mealDataView.setText(""); + autosensDataView.setText(""); + scriptdebugView.setText(""); + requestView.setText(""); + lastRunView.setText(""); + } } } }); } + + private boolean isBound() { + return run != null + && lastRunView != null + && constraintsView != null + && glucoseStatusView != null + && currentTempView != null + && iobDataView != null + && profileView != null + && mealDataView != null + && autosensDataView != null + && resultView != null + && scriptdebugView != null + && requestView != null; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java index 2d5863949b..6cc9fdf98e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java @@ -84,6 +84,9 @@ public class NSProfileFragment extends SubscriberFragment { @Override protected void updateGUI() { + if (noProfile == null || profileSpinner == null) + return; + ProfileStore profileStore = NSProfilePlugin.getPlugin().getProfile(); if (profileStore != null) { ArrayList profileList = profileStore.getProfileList(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java index 3f89a579ee..7288602d65 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java @@ -217,6 +217,8 @@ public class DanaRFragment extends SubscriberFragment { @Override public void run() { synchronized(DanaRFragment.this) { + if (!isBound()) return; + DanaRPump pump = DanaRPump.getInstance(); if (pump.lastConnection != 0) { Long agoMsec = System.currentTimeMillis() - pump.lastConnection; @@ -280,7 +282,7 @@ public class DanaRFragment extends SubscriberFragment { } //hide user options button if not an RS pump boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP); - if (isKorean ) { + if (isKorean) { danar_user_options.setVisibility(View.GONE); } } @@ -288,4 +290,22 @@ public class DanaRFragment extends SubscriberFragment { }); } + private boolean isBound() { + return lastConnectionView != null + && lastBolusView != null + && dailyUnitsView != null + && basaBasalRateView != null + && tempBasalView != null + && extendedBolusView != null + && reservoirView != null + && batteryView != null + && iobView != null + && firmwareView != null + && basalStepView != null + && bolusStepView != null + && serialNumberView != null + && danar_user_options != null + && queueView != null; + } + }