From 357c84e2e2ee76787ebe1c2e4bc3eed124007b1c Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Tue, 17 Oct 2017 12:20:12 +0200 Subject: [PATCH] ComboPlugin singletion. --- .../info/nightscout/androidaps/MainApp.java | 5 ++--- .../plugins/PumpCombo/ComboFragment.java | 21 +++++++------------ .../plugins/PumpCombo/ComboPlugin.java | 8 ++++++- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 804b7bca87..0de381f2e8 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -48,8 +48,7 @@ import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPe import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment; import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin; -import info.nightscout.androidaps.plugins.PumpCombo.ComboFragment; -import info.nightscout.androidaps.plugins.PumpDanaR.DanaRFragment; +import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; @@ -129,7 +128,7 @@ public class MainApp extends Application { if (Config.DANAR) pluginsList.add(DanaRKoreanPlugin.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRv2Plugin.getPlugin()); if (Config.DANAR) pluginsList.add(DanaRSPlugin.getPlugin()); - if (Config.COMBO) pluginsList.add(ComboFragment.getPlugin()); + if (Config.COMBO) pluginsList.add(ComboPlugin.getPlugin()); pluginsList.add(CareportalFragment.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getInstance()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index ef974b8046..945f385bf4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -27,12 +27,6 @@ import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateG public class ComboFragment extends Fragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(ComboFragment.class); - private static ComboPlugin comboPlugin = new ComboPlugin(); - - public static ComboPlugin getPlugin() { - return comboPlugin; - } - private Button refresh; private TextView statusText; @@ -103,7 +97,7 @@ public class ComboFragment extends Fragment implements View.OnClickListener { Thread thread = new Thread(new Runnable() { @Override public void run() { - getPlugin().refreshDataFromPump("User request"); + ComboPlugin.getPlugin().refreshDataFromPump("User request"); } }); thread.start(); @@ -117,9 +111,10 @@ public class ComboFragment extends Fragment implements View.OnClickListener { activity.runOnUiThread(new Runnable() { @Override public void run() { - statusText.setText(getPlugin().getPump().stateSummary); - if (getPlugin().isInitialized()) { - PumpState ps = getPlugin().getPump().state; + ComboPlugin plugin = ComboPlugin.getPlugin(); + statusText.setText(plugin.getPump().stateSummary); + if (plugin.isInitialized()) { + PumpState ps = plugin.getPump().state; if (ps != null) { boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100; if (tbrActive) { @@ -152,16 +147,16 @@ public class ComboFragment extends Fragment implements View.OnClickListener { } } - Command lastCmd = getPlugin().getPump().lastCmd; + Command lastCmd = plugin.getPump().lastCmd; if (lastCmd != null) { lastCmdText.setText(lastCmd.toString()); - lastCmdTimeText.setText(getPlugin().getPump().lastCmdTime.toLocaleString()); + lastCmdTimeText.setText(plugin.getPump().lastCmdTime.toLocaleString()); } else { lastCmdText.setText(""); lastCmdTimeText.setText(""); } - CommandResult lastCmdResult = getPlugin().getPump().lastCmdResult; + CommandResult lastCmdResult = plugin.getPump().lastCmdResult; if (lastCmdResult != null && lastCmdResult.message != null) { lastCmdResultText.setText(lastCmdResult.message); lastCmdDurationText.setText(lastCmdResult.duration); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index d79310fbdf..4991213e95 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -62,7 +62,13 @@ public class ComboPlugin implements PluginBase, PumpInterface { private ComboPump pump = new ComboPump(); - private boolean ignoreLastSetTbrOrReadStateFailure = false; + private static ComboPlugin plugin = null; + + public static ComboPlugin getPlugin() { + if (plugin == null) + plugin = new ComboPlugin(); + return plugin; + } @Nullable private volatile BolusCommand runningBolusCommand;