OpenAPSPlugins -> kotlin

This commit is contained in:
Milos Kozak 2019-08-06 21:50:08 +02:00
parent d2c01501a8
commit 73e8d21ca0
14 changed files with 364 additions and 469 deletions

View file

@ -1,135 +0,0 @@
package info.nightscout.androidaps.plugins.aps.openAPSAMA;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.json.JSONArray;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.JSONFormatter;
public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(L.APS);
Button run;
TextView lastRunView;
TextView glucoseStatusView;
TextView currentTempView;
TextView iobDataView;
TextView profileView;
TextView mealDataView;
TextView autosensDataView;
TextView resultView;
TextView scriptdebugView;
TextView requestView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.openapsama_fragment, container, false);
run = (Button) view.findViewById(R.id.openapsma_run);
run.setOnClickListener(this);
lastRunView = (TextView) view.findViewById(R.id.openapsma_lastrun);
glucoseStatusView = (TextView) view.findViewById(R.id.openapsma_glucosestatus);
currentTempView = (TextView) view.findViewById(R.id.openapsma_currenttemp);
iobDataView = (TextView) view.findViewById(R.id.openapsma_iobdata);
profileView = (TextView) view.findViewById(R.id.openapsma_profile);
mealDataView = (TextView) view.findViewById(R.id.openapsma_mealdata);
autosensDataView = (TextView) view.findViewById(R.id.openapsma_autosensdata);
scriptdebugView = (TextView) view.findViewById(R.id.openapsma_scriptdebugdata);
resultView = (TextView) view.findViewById(R.id.openapsma_result);
requestView = (TextView) view.findViewById(R.id.openapsma_request);
updateGUI();
return view;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.openapsma_run:
OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button", false);
break;
}
}
@Subscribe
public void onStatusEvent(final EventOpenAPSUpdateGui ev) {
updateGUI();
}
@Subscribe
public void onStatusEvent(final EventOpenAPSUpdateResultGui ev) {
updateResultGUI(ev.text);
}
@Override
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
DetermineBasalResultAMA lastAPSResult = OpenAPSAMAPlugin.getPlugin().lastAPSResult;
if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned());
}
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS = OpenAPSAMAPlugin.getPlugin().lastDetermineBasalAdapterAMAJS;
if (determineBasalAdapterAMAJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getGlucoseStatusParam()));
currentTempView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getCurrentTempParam()));
try {
JSONArray iobArray = new JSONArray(determineBasalAdapterAMAJS.getIobDataParam());
iobDataView.setText(TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))));
} catch (JSONException e) {
log.error("Unhandled exception", e);
iobDataView.setText("JSONException");
}
profileView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getProfileParam()));
mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam()));
scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug());
}
if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != 0) {
lastRunView.setText(DateUtil.dateAndTimeFullString(OpenAPSAMAPlugin.getPlugin().lastAPSRun));
}
if (OpenAPSAMAPlugin.getPlugin().lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(OpenAPSAMAPlugin.getPlugin().lastAutosensResult.json()));
}
});
}
void updateResultGUI(final String text) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
resultView.setText(text);
glucoseStatusView.setText("");
currentTempView.setText("");
iobDataView.setText("");
profileView.setText("");
mealDataView.setText("");
autosensDataView.setText("");
scriptdebugView.setText("");
requestView.setText("");
lastRunView.setText("");
});
}
}

View file

@ -0,0 +1,106 @@
package info.nightscout.androidaps.plugins.aps.openAPSAMA
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.JSONFormatter
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.openapsama_fragment.*
import org.json.JSONArray
import org.json.JSONException
import org.slf4j.LoggerFactory
class OpenAPSAMAFragment : Fragment() {
private val log = LoggerFactory.getLogger(L.APS)
private var disposable: CompositeDisposable = CompositeDisposable()
operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
add(disposable)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.openapsama_fragment, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
openapsma_run.setOnClickListener {
OpenAPSAMAPlugin.getPlugin().invoke("OpenAPSAMA button", false)
}
updateGUI()
disposable += RxBus
.toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
updateGUI()
}, {
FabricPrivacy.logException(it)
})
disposable += RxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
updateResultGUI(it.text)
}, {
FabricPrivacy.logException(it)
})
}
private fun updateGUI() {
OpenAPSAMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult ->
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
openapsma_request.text = lastAPSResult.toSpanned()
}
OpenAPSAMAPlugin.getPlugin().lastDetermineBasalAdapterAMAJS?.let { determineBasalAdapterAMAJS ->
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterAMAJS.glucoseStatusParam)
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterAMAJS.currentTempParam)
try {
val iobArray = JSONArray(determineBasalAdapterAMAJS.iobDataParam)
openapsma_iobdata.text = TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0)))
} catch (e: JSONException) {
log.error("Unhandled exception", e)
openapsma_iobdata.text = "JSONException see log for details"
}
openapsma_profile.text = JSONFormatter.format(determineBasalAdapterAMAJS.profileParam)
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterAMAJS.mealDataParam)
openapsma_scriptdebugdata.text = determineBasalAdapterAMAJS.scriptDebug
}
if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != 0L) {
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(OpenAPSAMAPlugin.getPlugin().lastAPSRun)
}
OpenAPSAMAPlugin.getPlugin().lastAutosensResult?.let {
openapsma_autosensdata.text = JSONFormatter.format(it.json())
}
}
private fun updateResultGUI(text: String) {
openapsma_result.text = text
openapsma_glucosestatus.text = ""
openapsma_currenttemp.text = ""
openapsma_iobdata.text = ""
openapsma_profile.text = ""
openapsma_mealdata.text = ""
openapsma_autosensdata.text = ""
openapsma_scriptdebugdata.text = ""
openapsma_request.text = ""
openapsma_lastrun.text = ""
}
}

View file

@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
@ -17,15 +16,17 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.HardLimits; import info.nightscout.androidaps.utils.HardLimits;
@ -99,21 +100,21 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (profile == null) { if (profile == null) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug(MainApp.gs(R.string.noprofileselected)); log.debug(MainApp.gs(R.string.noprofileselected));
return; return;
} }
if (!isEnabled(PluginType.APS)) { if (!isEnabled(PluginType.APS)) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug(MainApp.gs(R.string.openapsma_disabled)); log.debug(MainApp.gs(R.string.openapsma_disabled));
return; return;
} }
if (glucoseStatus == null) { if (glucoseStatus == null) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug(MainApp.gs(R.string.openapsma_noglucosedata)); log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
return; return;
@ -171,7 +172,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin"); AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
if (autosensData == null) { if (autosensData == null) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata)));
return; return;
} }
lastAutosensResult = autosensData.autosensResult; lastAutosensResult = autosensData.autosensResult;
@ -216,7 +217,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
lastDetermineBasalAdapterAMAJS = determineBasalAdapterAMAJS; lastDetermineBasalAdapterAMAJS = determineBasalAdapterAMAJS;
lastAPSResult = determineBasalResultAMA; lastAPSResult = determineBasalResultAMA;
lastAPSRun = now; lastAPSRun = now;
MainApp.bus().post(new EventOpenAPSUpdateGui()); RxBus.INSTANCE.send(new EventOpenAPSUpdateGui());
//deviceStatus.suggested = determineBasalResultAMA.json; //deviceStatus.suggested = determineBasalResultAMA.json;
} }

View file

@ -1,116 +0,0 @@
package info.nightscout.androidaps.plugins.aps.openAPSMA;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.JSONFormatter;
public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClickListener {
Button run;
TextView lastRunView;
TextView glucoseStatusView;
TextView currentTempView;
TextView iobDataView;
TextView profileView;
TextView mealDataView;
TextView resultView;
TextView requestView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View view = inflater.inflate(R.layout.openapsma_fragment, container, false);
run = (Button) view.findViewById(R.id.openapsma_run);
run.setOnClickListener(this);
lastRunView = (TextView) view.findViewById(R.id.openapsma_lastrun);
glucoseStatusView = (TextView) view.findViewById(R.id.openapsma_glucosestatus);
currentTempView = (TextView) view.findViewById(R.id.openapsma_currenttemp);
iobDataView = (TextView) view.findViewById(R.id.openapsma_iobdata);
profileView = (TextView) view.findViewById(R.id.openapsma_profile);
mealDataView = (TextView) view.findViewById(R.id.openapsma_mealdata);
resultView = (TextView) view.findViewById(R.id.openapsma_result);
requestView = (TextView) view.findViewById(R.id.openapsma_request);
updateGUI();
return view;
} catch (Exception e) {
FabricPrivacy.logException(e);
}
return null;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.openapsma_run:
OpenAPSMAPlugin.getPlugin().invoke("OpenAPSMA button", false);
break;
}
}
@Subscribe
public void onStatusEvent(final EventOpenAPSUpdateGui ev) {
updateGUI();
}
@Subscribe
public void onStatusEvent(final EventOpenAPSUpdateResultGui ev) {
updateResultGUI(ev.text);
}
@Override
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
DetermineBasalResultMA lastAPSResult = OpenAPSMAPlugin.getPlugin().lastAPSResult;
if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned());
}
DetermineBasalAdapterMAJS determineBasalAdapterMAJS = OpenAPSMAPlugin.getPlugin().lastDetermineBasalAdapterMAJS;
if (determineBasalAdapterMAJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getGlucoseStatusParam()));
currentTempView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getCurrentTempParam()));
iobDataView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getIobDataParam()));
profileView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getProfileParam()));
mealDataView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getMealDataParam()));
}
if (OpenAPSMAPlugin.getPlugin().lastAPSRun != 0) {
lastRunView.setText(DateUtil.dateAndTimeFullString(OpenAPSMAPlugin.getPlugin().lastAPSRun));
}
});
}
private void updateResultGUI(final String text) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
resultView.setText(text);
glucoseStatusView.setText("");
currentTempView.setText("");
iobDataView.setText("");
profileView.setText("");
mealDataView.setText("");
requestView.setText("");
lastRunView.setText("");
});
}
}

View file

@ -0,0 +1,89 @@
package info.nightscout.androidaps.plugins.aps.openAPSMA
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.JSONFormatter
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.openapsama_fragment.*
import org.slf4j.LoggerFactory
class OpenAPSMAFragment : Fragment() {
private val log = LoggerFactory.getLogger(L.APS)
private var disposable: CompositeDisposable = CompositeDisposable()
operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
add(disposable)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.openapsma_fragment, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
openapsma_run.setOnClickListener {
OpenAPSMAPlugin.getPlugin().invoke("OpenAPSMA button", false)
}
updateGUI()
disposable += RxBus
.toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
updateGUI()
}, {
FabricPrivacy.logException(it)
})
disposable += RxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
updateResultGUI(it.text)
}, {
FabricPrivacy.logException(it)
})
}
fun updateGUI() {
OpenAPSMAPlugin.getPlugin().lastAPSResult?.let { lastAPSResult ->
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
openapsma_request.text = lastAPSResult.toSpanned()
}
OpenAPSMAPlugin.getPlugin().lastDetermineBasalAdapterMAJS?.let { determineBasalAdapterMAJS ->
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterMAJS.glucoseStatusParam)
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterMAJS.currentTempParam)
openapsma_iobdata.text = JSONFormatter.format(determineBasalAdapterMAJS.iobDataParam)
openapsma_profile.text = JSONFormatter.format(determineBasalAdapterMAJS.profileParam)
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterMAJS.mealDataParam)
}
if (OpenAPSMAPlugin.getPlugin().lastAPSRun != 0L) {
openapsma_lastrun.text = DateUtil.dateAndTimeString(OpenAPSMAPlugin.getPlugin().lastAPSRun)
}
}
private fun updateResultGUI(text: String) {
openapsma_result.text = text
openapsma_glucosestatus.text = ""
openapsma_currenttemp.text = ""
openapsma_iobdata.text = ""
openapsma_profile.text = ""
openapsma_mealdata.text = ""
openapsma_request.text = ""
openapsma_lastrun.text = ""
}
}

View file

@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
@ -17,12 +16,14 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.HardLimits; import info.nightscout.androidaps.utils.HardLimits;
@ -98,21 +99,21 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (profile == null) { if (profile == null) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug(MainApp.gs(R.string.noprofileselected)); log.debug(MainApp.gs(R.string.noprofileselected));
return; return;
} }
if (!isEnabled(PluginType.APS)) { if (!isEnabled(PluginType.APS)) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug(MainApp.gs(R.string.openapsma_disabled)); log.debug(MainApp.gs(R.string.openapsma_disabled));
return; return;
} }
if (glucoseStatus == null) { if (glucoseStatus == null) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug(MainApp.gs(R.string.openapsma_noglucosedata)); log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
return; return;
@ -193,7 +194,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS; lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS;
lastAPSResult = determineBasalResultMA; lastAPSResult = determineBasalResultMA;
lastAPSRun = now; lastAPSRun = now;
MainApp.bus().post(new EventOpenAPSUpdateGui()); RxBus.INSTANCE.send(new EventOpenAPSUpdateGui());
} }

View file

@ -1,9 +0,0 @@
package info.nightscout.androidaps.plugins.aps.openAPSMA.events;
import info.nightscout.androidaps.events.EventUpdateGui;
/**
* Created by mike on 05.08.2016.
*/
public class EventOpenAPSUpdateGui extends EventUpdateGui {
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.aps.openAPSMA.events
import info.nightscout.androidaps.events.EventUpdateGui
class EventOpenAPSUpdateGui : EventUpdateGui()

View file

@ -1,14 +0,0 @@
package info.nightscout.androidaps.plugins.aps.openAPSMA.events;
import info.nightscout.androidaps.events.EventUpdateGui;
/**
* Created by mike on 05.08.2016.
*/
public class EventOpenAPSUpdateResultGui extends EventUpdateGui {
public String text;
public EventOpenAPSUpdateResultGui(String text) {
this.text = text;
}
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.aps.openAPSMA.events
import info.nightscout.androidaps.events.EventUpdateGui
class EventOpenAPSUpdateResultGui(val text: String) : EventUpdateGui()

View file

@ -1,159 +0,0 @@
package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.json.JSONArray;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.JSONFormatter;
public class OpenAPSSMBFragment extends SubscriberFragment {
private static Logger log = LoggerFactory.getLogger(L.APS);
@BindView(R.id.openapsma_run)
Button run;
@BindView(R.id.openapsma_lastrun)
TextView lastRunView;
@BindView(R.id.openapsma_constraints)
TextView constraintsView;
@BindView(R.id.openapsma_glucosestatus)
TextView glucoseStatusView;
@BindView(R.id.openapsma_currenttemp)
TextView currentTempView;
@BindView(R.id.openapsma_iobdata)
TextView iobDataView;
@BindView(R.id.openapsma_profile)
TextView profileView;
@BindView(R.id.openapsma_mealdata)
TextView mealDataView;
@BindView(R.id.openapsma_autosensdata)
TextView autosensDataView;
@BindView(R.id.openapsma_result)
TextView resultView;
@BindView(R.id.openapsma_scriptdebugdata)
TextView scriptdebugView;
@BindView(R.id.openapsma_request)
TextView requestView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.openapsama_fragment, container, false);
unbinder = ButterKnife.bind(this, view);
return view;
}
@OnClick(R.id.openapsma_run)
public void onRunClick() {
OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSSMB button", false);
}
@Subscribe
public void onStatusEvent(final EventOpenAPSUpdateGui ev) {
updateGUI();
}
@Subscribe
public void onStatusEvent(final EventOpenAPSUpdateResultGui ev) {
updateResultGUI(ev.text);
}
@Override
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
synchronized (OpenAPSSMBFragment.this) {
if (!isBound()) return;
OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult;
if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned());
}
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
if (determineBasalAdapterSMBJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()));
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()));
try {
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
iobDataView.setText(TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))));
} catch (JSONException e) {
log.error("Unhandled exception", e);
iobDataView.setText("JSONException see log for details");
}
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()));
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()));
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug());
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
constraintsView.setText(lastAPSResult.inputConstraints.getReasons());
}
if (plugin.lastAPSRun != 0) {
lastRunView.setText(DateUtil.dateAndTimeFullString(plugin.lastAPSRun));
}
if (plugin.lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()));
}
}
});
}
void updateResultGUI(final String text) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
synchronized (OpenAPSSMBFragment.this) {
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;
}
}

View file

@ -0,0 +1,110 @@
package info.nightscout.androidaps.plugins.aps.openAPSSMB
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.JSONFormatter
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.openapsama_fragment.*
import org.json.JSONArray
import org.json.JSONException
import org.slf4j.LoggerFactory
class OpenAPSSMBFragment : Fragment() {
private val log = LoggerFactory.getLogger(L.APS)
private var disposable: CompositeDisposable = CompositeDisposable()
operator fun CompositeDisposable.plusAssign(disposable: Disposable) {
add(disposable)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.openapsama_fragment, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
openapsma_run.setOnClickListener {
OpenAPSSMBPlugin.getPlugin().invoke("OpenAPSSMB button", false)
}
updateGUI()
disposable += RxBus
.toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
updateGUI()
}, {
FabricPrivacy.logException(it)
})
disposable += RxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
updateResultGUI(it.text)
}, {
FabricPrivacy.logException(it)
})
}
fun updateGUI() {
val plugin = OpenAPSSMBPlugin.getPlugin()
plugin.lastAPSResult?.let { lastAPSResult ->
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
openapsma_request.text = lastAPSResult.toSpanned()
}
plugin.lastDetermineBasalAdapterSMBJS?.let { determineBasalAdapterSMBJS ->
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterSMBJS.glucoseStatusParam)
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterSMBJS.currentTempParam)
try {
val iobArray = JSONArray(determineBasalAdapterSMBJS.iobDataParam)
openapsma_iobdata.text = TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0)))
} catch (e: JSONException) {
log.error("Unhandled exception", e)
openapsma_iobdata.text = "JSONException see log for details"
}
openapsma_profile.text = JSONFormatter.format(determineBasalAdapterSMBJS.profileParam)
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterSMBJS.mealDataParam)
openapsma_scriptdebugdata.text = determineBasalAdapterSMBJS.scriptDebug
plugin.lastAPSResult?.inputConstraints?.let {
openapsma_constraints.text = it.reasons
}
}
if (plugin.lastAPSRun != 0L) {
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(plugin.lastAPSRun)
}
plugin.lastAutosensResult?.let {
openapsma_autosensdata.text = JSONFormatter.format(it.json())
}
}
private fun updateResultGUI(text: String) {
openapsma_result.text = text
openapsma_glucosestatus.text = ""
openapsma_currenttemp.text = ""
openapsma_iobdata.text = ""
openapsma_profile.text = ""
openapsma_mealdata.text = ""
openapsma_autosensdata.text = ""
openapsma_scriptdebugdata.text = ""
openapsma_request.text = ""
openapsma_lastrun.text = ""
}
}

View file

@ -6,7 +6,6 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
@ -19,16 +18,18 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.HardLimits; import info.nightscout.androidaps.utils.HardLimits;
@ -103,21 +104,21 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (profile == null) { if (profile == null) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug(MainApp.gs(R.string.noprofileselected)); log.debug(MainApp.gs(R.string.noprofileselected));
return; return;
} }
if (!isEnabled(PluginType.APS)) { if (!isEnabled(PluginType.APS)) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug(MainApp.gs(R.string.openapsma_disabled)); log.debug(MainApp.gs(R.string.openapsma_disabled));
return; return;
} }
if (glucoseStatus == null) { if (glucoseStatus == null) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug(MainApp.gs(R.string.openapsma_noglucosedata)); log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
return; return;
@ -177,7 +178,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin"); AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
if (autosensData == null) { if (autosensData == null) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata)));
return; return;
} }
lastAutosensResult = autosensData.autosensResult; lastAutosensResult = autosensData.autosensResult;
@ -245,7 +246,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
lastDetermineBasalAdapterSMBJS = determineBasalAdapterSMBJS; lastDetermineBasalAdapterSMBJS = determineBasalAdapterSMBJS;
lastAPSResult = determineBasalResultSMB; lastAPSResult = determineBasalResultSMB;
lastAPSRun = now; lastAPSRun = now;
MainApp.bus().post(new EventOpenAPSUpdateGui()); RxBus.INSTANCE.send(new EventOpenAPSUpdateGui());
//deviceStatus.suggested = determineBasalResultAMA.json; //deviceStatus.suggested = determineBasalResultAMA.json;
} }

View file

@ -20,11 +20,16 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.general.wear.wearintegration.WatchUpdaterService; import info.nightscout.androidaps.plugins.general.wear.wearintegration.WatchUpdaterService;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
/** /**
* Created by adrian on 17/11/16. * Created by adrian on 17/11/16.
@ -38,6 +43,7 @@ public class WearPlugin extends PluginBase {
private static WearPlugin wearPlugin; private static WearPlugin wearPlugin;
private static String TAG = "WearPlugin"; private static String TAG = "WearPlugin";
private CompositeDisposable disposable = new CompositeDisposable();
public static WearPlugin getPlugin() { public static WearPlugin getPlugin() {
return wearPlugin; return wearPlugin;
@ -71,11 +77,20 @@ public class WearPlugin extends PluginBase {
watchUS.setSettings(); watchUS.setSettings();
} }
super.onStart(); super.onStart();
disposable.add(RxBus.INSTANCE
.toObservable(EventOpenAPSUpdateGui.class)
.observeOn(Schedulers.io())
.subscribe(eventOpenAPSUpdateGui -> sendDataToWatch(true, true, false),
error -> FabricPrivacy.logException(error)
));
} }
@Override @Override
protected void onStop() { protected void onStop() {
MainApp.bus().unregister(this); MainApp.bus().unregister(this);
disposable.clear();
} }
private void sendDataToWatch(boolean status, boolean basals, boolean bgValue) { private void sendDataToWatch(boolean status, boolean basals, boolean bgValue) {
@ -112,7 +127,7 @@ public class WearPlugin extends PluginBase {
//Log.d(TAG, "WR: WearPlugin:requestNotificationCancel"); //Log.d(TAG, "WR: WearPlugin:requestNotificationCancel");
Intent intent = new Intent(ctx, WatchUpdaterService.class) Intent intent = new Intent(ctx, WatchUpdaterService.class)
.setAction(WatchUpdaterService.ACTION_CANCEL_NOTIFICATION); .setAction(WatchUpdaterService.ACTION_CANCEL_NOTIFICATION);
intent.putExtra("actionstring", actionstring); intent.putExtra("actionstring", actionstring);
ctx.startService(intent); ctx.startService(intent);
} }
@ -136,11 +151,6 @@ public class WearPlugin extends PluginBase {
sendDataToWatch(true, true, false); sendDataToWatch(true, true, false);
} }
@Subscribe
public void onStatusEvent(final EventOpenAPSUpdateGui ev) {
sendDataToWatch(true, true, false);
}
@Subscribe @Subscribe
public void onStatusEvent(final EventExtendedBolusChange ev) { public void onStatusEvent(final EventExtendedBolusChange ev) {
sendDataToWatch(true, true, false); sendDataToWatch(true, true, false);