From c6c5624b85b915298bd8855fa86ee6a531073d41 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 7 Oct 2017 21:15:34 +0200 Subject: [PATCH] Singleton OpenAPSSMBPlugin. --- .../info/nightscout/androidaps/MainApp.java | 1 + .../OpenAPSSMB/OpenAPSSMBFragment.java | 24 +++++++------------ .../plugins/OpenAPSSMB/OpenAPSSMBPlugin.java | 16 +++++++++---- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index ce55d7ef8b..f85c3ea124 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -131,6 +131,7 @@ public class MainApp extends Application { if (Config.LOOPENABLED) pluginsList.add(LoopPlugin.getPlugin()); if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAPlugin.getPlugin()); if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); + if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSSMBPlugin.getPlugin()); pluginsList.add(NSProfilePlugin.getPlugin()); if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin()); if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin()); 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 b08d0dac9d..1c0af1a67d 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 @@ -27,15 +27,6 @@ import info.nightscout.utils.JSONFormatter; public class OpenAPSSMBFragment extends SubscriberFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(OpenAPSSMBFragment.class); - private static OpenAPSSMBPlugin openAPSSMBPlugin; - - public static OpenAPSSMBPlugin getPlugin() { - if (openAPSSMBPlugin == null) { - openAPSSMBPlugin = new OpenAPSSMBPlugin(); - } - return openAPSSMBPlugin; - } - Button run; TextView lastRunView; TextView glucoseStatusView; @@ -74,7 +65,7 @@ public class OpenAPSSMBFragment extends SubscriberFragment implements View.OnCli public void onClick(View view) { switch (view.getId()) { case R.id.openapsma_run: - getPlugin().invoke("OpenAPSAMA button"); + OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSAMA button"); Answers.getInstance().logCustom(new CustomEvent("OpenAPS_AMA_Run")); break; } @@ -98,12 +89,13 @@ public class OpenAPSSMBFragment extends SubscriberFragment implements View.OnCli activity.runOnUiThread(new Runnable() { @Override public void run() { - DetermineBasalResultSMB lastAPSResult = getPlugin().lastAPSResult; + OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin(); + DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult; if (lastAPSResult != null) { resultView.setText(JSONFormatter.format(lastAPSResult.json)); requestView.setText(lastAPSResult.toSpanned()); } - DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = getPlugin().lastDetermineBasalAdapterSMBJS; + DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS; if (determineBasalAdapterSMBJS != null) { glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam())); currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam())); @@ -118,11 +110,11 @@ public class OpenAPSSMBFragment extends SubscriberFragment implements View.OnCli mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam())); scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug()); } - if (getPlugin().lastAPSRun != null) { - lastRunView.setText(getPlugin().lastAPSRun.toLocaleString()); + if (plugin.lastAPSRun != null) { + lastRunView.setText(plugin.lastAPSRun.toLocaleString()); } - if (getPlugin().lastAutosensResult != null) { - autosensDataView.setText(JSONFormatter.format(getPlugin().lastAutosensResult.json())); + if (plugin.lastAutosensResult != null) { + autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json())); } } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java index 9ddbacd355..44490d6151 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java @@ -23,9 +23,6 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.ScriptReader; -import info.nightscout.androidaps.plugins.OpenAPSSMB.DetermineBasalResultSMB; -import info.nightscout.androidaps.plugins.OpenAPSSMB.DetermineBasalAdapterSMBJS; -import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.utils.DateUtil; @@ -33,7 +30,6 @@ import info.nightscout.utils.NSUpload; import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; import info.nightscout.utils.SP; -import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; /** @@ -51,6 +47,18 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { boolean fragmentEnabled = false; boolean fragmentVisible = true; + private static OpenAPSSMBPlugin openAPSSMBPlugin; + + private OpenAPSSMBPlugin() { + } + + public static OpenAPSSMBPlugin getPlugin() { + if (openAPSSMBPlugin == null) { + openAPSSMBPlugin = new OpenAPSSMBPlugin(); + } + return openAPSSMBPlugin; + } + @Override public String getName() { return MainApp.instance().getString(R.string.openapssmb);