Check for unbound variables

This commit is contained in:
Nico Schmitz 2018-06-21 21:58:12 +02:00
parent c3050740a8
commit 4d853c1435
5 changed files with 79 additions and 19 deletions

View file

@ -185,6 +185,10 @@ public class HistoryBrowseActivity extends AppCompatActivity {
} }
void updateGUI(String from) { void updateGUI(String from) {
if (noProfile == null || buttonDate == null || buttonZoom == null || bgGraph == null || iobGraph == null || seekBar == null)
return;
final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
final Profile profile = MainApp.getConfigBuilder().getProfile(); final Profile profile = MainApp.getConfigBuilder().getProfile();

View file

@ -80,7 +80,7 @@ public class LoopFragment extends SubscriberFragment {
clearGUI(); clearGUI();
final Activity activity = getActivity(); final Activity activity = getActivity();
if (activity != null) 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) if (activity != null)
activity.runOnUiThread(() -> { activity.runOnUiThread(() -> {
synchronized (LoopFragment.this) { synchronized (LoopFragment.this) {
if (!isBound()) return;
LoopPlugin.LastRun lastRun = LoopPlugin.lastRun; LoopPlugin.LastRun lastRun = LoopPlugin.lastRun;
if (lastRun != null) { if (lastRun != null) {
requestView.setText(lastRun.request != null ? lastRun.request.toSpanned() : ""); requestView.setText(lastRun.request != null ? lastRun.request.toSpanned() : "");
@ -120,14 +121,28 @@ public class LoopFragment extends SubscriberFragment {
if (activity != null) if (activity != null)
activity.runOnUiThread(() -> { activity.runOnUiThread(() -> {
synchronized (LoopFragment.this) { synchronized (LoopFragment.this) {
requestView.setText(""); if (isBound()) {
constraintsProcessedView.setText(""); requestView.setText("");
sourceView.setText(""); constraintsProcessedView.setText("");
lastRunView.setText(""); sourceView.setText("");
lastEnactView.setText(""); lastRunView.setText("");
tbrSetByPumpView.setText(""); lastEnactView.setText("");
smbSetByPumpView.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;
}
} }

View file

@ -88,6 +88,7 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
@Override @Override
public void run() { public void run() {
synchronized (OpenAPSSMBFragment.this) { synchronized (OpenAPSSMBFragment.this) {
if (!isBound()) return;
OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin(); OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult; DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult;
if (lastAPSResult != null) { if (lastAPSResult != null) {
@ -129,18 +130,35 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
@Override @Override
public void run() { public void run() {
synchronized (OpenAPSSMBFragment.this) { synchronized (OpenAPSSMBFragment.this) {
resultView.setText(text); if (isBound()) {
glucoseStatusView.setText(""); resultView.setText(text);
currentTempView.setText(""); glucoseStatusView.setText("");
iobDataView.setText(""); currentTempView.setText("");
profileView.setText(""); iobDataView.setText("");
mealDataView.setText(""); profileView.setText("");
autosensDataView.setText(""); mealDataView.setText("");
scriptdebugView.setText(""); autosensDataView.setText("");
requestView.setText(""); scriptdebugView.setText("");
lastRunView.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;
}
} }

View file

@ -84,6 +84,9 @@ public class NSProfileFragment extends SubscriberFragment {
@Override @Override
protected void updateGUI() { protected void updateGUI() {
if (noProfile == null || profileSpinner == null)
return;
ProfileStore profileStore = NSProfilePlugin.getPlugin().getProfile(); ProfileStore profileStore = NSProfilePlugin.getPlugin().getProfile();
if (profileStore != null) { if (profileStore != null) {
ArrayList<CharSequence> profileList = profileStore.getProfileList(); ArrayList<CharSequence> profileList = profileStore.getProfileList();

View file

@ -217,6 +217,8 @@ public class DanaRFragment extends SubscriberFragment {
@Override @Override
public void run() { public void run() {
synchronized(DanaRFragment.this) { synchronized(DanaRFragment.this) {
if (!isBound()) return;
DanaRPump pump = DanaRPump.getInstance(); DanaRPump pump = DanaRPump.getInstance();
if (pump.lastConnection != 0) { if (pump.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastConnection; Long agoMsec = System.currentTimeMillis() - pump.lastConnection;
@ -280,7 +282,7 @@ public class DanaRFragment extends SubscriberFragment {
} }
//hide user options button if not an RS pump //hide user options button if not an RS pump
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.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); 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;
}
} }