Singleton OpenAPSSMBPlugin.

This commit is contained in:
Johannes Mockenhaupt 2017-10-07 21:15:34 +02:00
parent fa1c282699
commit c6c5624b85
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 21 additions and 20 deletions

View file

@ -131,6 +131,7 @@ public class MainApp extends Application {
if (Config.LOOPENABLED) pluginsList.add(LoopPlugin.getPlugin()); if (Config.LOOPENABLED) pluginsList.add(LoopPlugin.getPlugin());
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAPlugin.getPlugin()); if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSMAPlugin.getPlugin());
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
if (Config.OPENAPSENABLED) pluginsList.add(OpenAPSSMBPlugin.getPlugin());
pluginsList.add(NSProfilePlugin.getPlugin()); pluginsList.add(NSProfilePlugin.getPlugin());
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin()); if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin());
if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin()); if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin());

View file

@ -27,15 +27,6 @@ import info.nightscout.utils.JSONFormatter;
public class OpenAPSSMBFragment extends SubscriberFragment implements View.OnClickListener { public class OpenAPSSMBFragment extends SubscriberFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(OpenAPSSMBFragment.class); 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; Button run;
TextView lastRunView; TextView lastRunView;
TextView glucoseStatusView; TextView glucoseStatusView;
@ -74,7 +65,7 @@ public class OpenAPSSMBFragment extends SubscriberFragment implements View.OnCli
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.openapsma_run: case R.id.openapsma_run:
getPlugin().invoke("OpenAPSAMA button"); OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSAMA button");
Answers.getInstance().logCustom(new CustomEvent("OpenAPS_AMA_Run")); Answers.getInstance().logCustom(new CustomEvent("OpenAPS_AMA_Run"));
break; break;
} }
@ -98,12 +89,13 @@ public class OpenAPSSMBFragment extends SubscriberFragment implements View.OnCli
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
DetermineBasalResultSMB lastAPSResult = getPlugin().lastAPSResult; OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult;
if (lastAPSResult != null) { if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json)); resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned()); requestView.setText(lastAPSResult.toSpanned());
} }
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = getPlugin().lastDetermineBasalAdapterSMBJS; DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
if (determineBasalAdapterSMBJS != null) { if (determineBasalAdapterSMBJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam())); glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()));
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam())); currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()));
@ -118,11 +110,11 @@ public class OpenAPSSMBFragment extends SubscriberFragment implements View.OnCli
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam())); mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()));
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug()); scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug());
} }
if (getPlugin().lastAPSRun != null) { if (plugin.lastAPSRun != null) {
lastRunView.setText(getPlugin().lastAPSRun.toLocaleString()); lastRunView.setText(plugin.lastAPSRun.toLocaleString());
} }
if (getPlugin().lastAutosensResult != null) { if (plugin.lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(getPlugin().lastAutosensResult.json())); autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()));
} }
} }
}); });

View file

@ -23,9 +23,6 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.ScriptReader; 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.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
@ -33,7 +30,6 @@ import info.nightscout.utils.NSUpload;
import info.nightscout.utils.Profiler; import info.nightscout.utils.Profiler;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
/** /**
@ -51,6 +47,18 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
boolean fragmentEnabled = false; boolean fragmentEnabled = false;
boolean fragmentVisible = true; boolean fragmentVisible = true;
private static OpenAPSSMBPlugin openAPSSMBPlugin;
private OpenAPSSMBPlugin() {
}
public static OpenAPSSMBPlugin getPlugin() {
if (openAPSSMBPlugin == null) {
openAPSSMBPlugin = new OpenAPSSMBPlugin();
}
return openAPSSMBPlugin;
}
@Override @Override
public String getName() { public String getName() {
return MainApp.instance().getString(R.string.openapssmb); return MainApp.instance().getString(R.string.openapssmb);