Events to RxBus
This commit is contained in:
parent
06f8af82d8
commit
6044335b1d
34 changed files with 406 additions and 438 deletions
|
@ -16,7 +16,6 @@ import androidx.appcompat.widget.PopupMenu;
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
|
||||||
import com.jjoe64.graphview.GraphView;
|
import com.jjoe64.graphview.GraphView;
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
|
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -169,7 +168,6 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
MainApp.bus().unregister(this);
|
|
||||||
disposable.clear();
|
disposable.clear();
|
||||||
iobCobCalculatorPlugin.stopCalculation("onPause");
|
iobCobCalculatorPlugin.stopCalculation("onPause");
|
||||||
}
|
}
|
||||||
|
@ -177,7 +175,6 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
MainApp.bus().register(this);
|
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
.toObservable(EventAutosensCalculationFinished.class)
|
.toObservable(EventAutosensCalculationFinished.class)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
@ -190,6 +187,14 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
||||||
}
|
}
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventIobCalculationProgress.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> {
|
||||||
|
if (iobCalculationProgressView != null)
|
||||||
|
iobCalculationProgressView.setText(event.getProgress());
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
// set start of current day
|
// set start of current day
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||||
|
@ -210,14 +215,6 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
||||||
iobCobCalculatorPlugin.runCalculation(from, end, true, false, eventCustomCalculationFinished);
|
iobCobCalculatorPlugin.runCalculation(from, end, true, false, eventCustomCalculationFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventIobCalculationProgress e) {
|
|
||||||
runOnUiThread(() -> {
|
|
||||||
if (iobCalculationProgressView != null)
|
|
||||||
iobCalculationProgressView.setText(e.progress);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateGUI(String from) {
|
void updateGUI(String from) {
|
||||||
log.debug("updateGUI from: " + from);
|
log.debug("updateGUI from: " + from);
|
||||||
|
|
||||||
|
|
|
@ -1037,7 +1037,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
RxBus.INSTANCE.send(new EventReloadTempBasalData());
|
RxBus.INSTANCE.send(new EventReloadTempBasalData());
|
||||||
RxBus.INSTANCE.send(new EventTempBasalChange());
|
RxBus.INSTANCE.send(new EventTempBasalChange());
|
||||||
if (earliestDataChange != null)
|
if (earliestDataChange != null)
|
||||||
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
RxBus.INSTANCE.send(new EventNewHistoryData(earliestDataChange));
|
||||||
earliestDataChange = null;
|
earliestDataChange = null;
|
||||||
scheduledTemBasalsPost = null;
|
scheduledTemBasalsPost = null;
|
||||||
}
|
}
|
||||||
|
@ -1372,7 +1372,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
log.debug("Firing EventExtendedBolusChange");
|
log.debug("Firing EventExtendedBolusChange");
|
||||||
RxBus.INSTANCE.send(new EventReloadTreatmentData(new EventExtendedBolusChange()));
|
RxBus.INSTANCE.send(new EventReloadTreatmentData(new EventExtendedBolusChange()));
|
||||||
if (earliestDataChange != null)
|
if (earliestDataChange != null)
|
||||||
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
RxBus.INSTANCE.send(new EventNewHistoryData(earliestDataChange));
|
||||||
earliestDataChange = null;
|
earliestDataChange = null;
|
||||||
scheduledExtendedBolusPost = null;
|
scheduledExtendedBolusPost = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.general.nsclient;
|
package info.nightscout.androidaps.plugins.general.nsclient;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -17,18 +16,22 @@ import android.widget.CompoundButton;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
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.common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
|
public class NSClientFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
public class NSClientFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
|
||||||
private TextView logTextView;
|
private TextView logTextView;
|
||||||
private TextView queueTextView;
|
private TextView queueTextView;
|
||||||
private TextView urlTextView;
|
private TextView urlTextView;
|
||||||
|
@ -45,7 +48,6 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
try {
|
|
||||||
View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);
|
View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);
|
||||||
|
|
||||||
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
|
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
|
||||||
|
@ -76,20 +78,31 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
showqueue.setOnClickListener(this);
|
showqueue.setOnClickListener(this);
|
||||||
showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||||
|
|
||||||
updateGUI();
|
|
||||||
return view;
|
return view;
|
||||||
} catch (Exception e) {
|
|
||||||
FabricPrivacy.logException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
@Override
|
||||||
|
public synchronized void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventNSClientUpdateGUI.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
updateGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
disposable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.nsclientinternal_restart:
|
case R.id.nsclientinternal_restart:
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
FabricPrivacy.getInstance().logCustom("NSClientRestart");
|
FabricPrivacy.getInstance().logCustom("NSClientRestart");
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_delivernow:
|
case R.id.nsclientinternal_delivernow:
|
||||||
|
@ -108,7 +121,7 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
UploadQueue.clearQueue();
|
UploadQueue.clearQueue();
|
||||||
updateGUI();
|
updateGui();
|
||||||
FabricPrivacy.getInstance().logCustom("NSClientClearQueue");
|
FabricPrivacy.getInstance().logCustom("NSClientClearQueue");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -116,7 +129,7 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
builder.show();
|
builder.show();
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_showqueue:
|
case R.id.nsclientinternal_showqueue:
|
||||||
MainApp.bus().post(new EventNSClientNewLog("QUEUE", NSClientPlugin.getPlugin().queue().textList()));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("QUEUE", NSClientPlugin.getPlugin().queue().textList()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,27 +139,18 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
switch (buttonView.getId()) {
|
switch (buttonView.getId()) {
|
||||||
case R.id.nsclientinternal_paused:
|
case R.id.nsclientinternal_paused:
|
||||||
NSClientPlugin.getPlugin().pause(isChecked);
|
NSClientPlugin.getPlugin().pause(isChecked);
|
||||||
updateGUI();
|
updateGui();
|
||||||
FabricPrivacy.getInstance().logCustom("NSClientPause");
|
FabricPrivacy.getInstance().logCustom("NSClientPause");
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_autoscroll:
|
case R.id.nsclientinternal_autoscroll:
|
||||||
SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
|
SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
|
||||||
NSClientPlugin.getPlugin().autoscroll = isChecked;
|
NSClientPlugin.getPlugin().autoscroll = isChecked;
|
||||||
updateGUI();
|
updateGui();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
protected void updateGui() {
|
||||||
public void onStatusEvent(final EventNSClientUpdateGUI ev) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateGUI() {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(() -> {
|
|
||||||
NSClientPlugin.getPlugin().updateLog();
|
NSClientPlugin.getPlugin().updateLog();
|
||||||
pausedCheckbox.setChecked(SP.getBoolean(R.string.key_nsclientinternal_paused, false));
|
pausedCheckbox.setChecked(SP.getBoolean(R.string.key_nsclientinternal_paused, false));
|
||||||
logTextView.setText(NSClientPlugin.getPlugin().textLog);
|
logTextView.setText(NSClientPlugin.getPlugin().textLog);
|
||||||
|
@ -157,7 +161,6 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
Spanned queuetext = Html.fromHtml(MainApp.gs(R.string.queue) + " <b>" + UploadQueue.size() + "</b>");
|
Spanned queuetext = Html.fromHtml(MainApp.gs(R.string.queue) + " <b>" + UploadQueue.size() + "</b>");
|
||||||
queueTextView.setText(queuetext);
|
queueTextView.setText(queuetext);
|
||||||
statusTextView.setText(NSClientPlugin.getPlugin().status);
|
statusTextView.setText(NSClientPlugin.getPlugin().status);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(event -> {
|
.subscribe(event -> {
|
||||||
status = event.getStatus();
|
status = event.getStatus();
|
||||||
MainApp.bus().post(new EventNSClientUpdateGUI());
|
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
|
@ -136,6 +136,15 @@ public class NSClientPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventNSClientNewLog.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> {
|
||||||
|
addToLog(event);
|
||||||
|
if (L.isEnabled(L.NSCLIENT))
|
||||||
|
log.debug(event.getAction() + " " + event.getLogText());
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -171,19 +180,12 @@ public class NSClientPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventNSClientNewLog ev) {
|
|
||||||
addToLog(ev);
|
|
||||||
if (L.isEnabled(L.NSCLIENT))
|
|
||||||
log.debug(ev.action + " " + ev.logText);
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized void clearLog() {
|
synchronized void clearLog() {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
synchronized (listLog) {
|
synchronized (listLog) {
|
||||||
listLog.clear();
|
listLog.clear();
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientUpdateGUI());
|
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +198,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
listLog.remove(0);
|
listLog.remove(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientUpdateGUI());
|
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.events.Event;
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
||||||
import io.socket.client.Ack;
|
import io.socket.client.Ack;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ public class NSAddAck extends Event implements Ack {
|
||||||
if (response.has("result")) {
|
if (response.has("result")) {
|
||||||
_id = null;
|
_id = null;
|
||||||
if (response.getString("result").contains("Not")) {
|
if (response.getString("result").contains("Not")) {
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (L.isEnabled(L.NSCLIENT))
|
if (L.isEnabled(L.NSCLIENT))
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.nsclient.events;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 15.02.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventNSClientNewLog extends Event {
|
|
||||||
public Date date = new Date();
|
|
||||||
public String action;
|
|
||||||
public String logText;
|
|
||||||
public EventNSClientNewLog(String action, String logText) {
|
|
||||||
this.action = action;
|
|
||||||
this.logText = logText;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
|
|
||||||
|
|
||||||
public StringBuilder toPreparedHtml() {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
stringBuilder.append(timeFormat.format(date));
|
|
||||||
stringBuilder.append(" <b>");
|
|
||||||
stringBuilder.append(action);
|
|
||||||
stringBuilder.append("</b> ");
|
|
||||||
stringBuilder.append(logText);
|
|
||||||
stringBuilder.append("<br>");
|
|
||||||
return stringBuilder;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.nsclient.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class EventNSClientNewLog(var action: String, var logText: String) : Event() {
|
||||||
|
var date = Date()
|
||||||
|
|
||||||
|
private var timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||||
|
|
||||||
|
fun toPreparedHtml(): StringBuilder {
|
||||||
|
val stringBuilder = StringBuilder()
|
||||||
|
stringBuilder.append(timeFormat.format(date))
|
||||||
|
stringBuilder.append(" <b>")
|
||||||
|
stringBuilder.append(action)
|
||||||
|
stringBuilder.append("</b> ")
|
||||||
|
stringBuilder.append(logText)
|
||||||
|
stringBuilder.append("<br>")
|
||||||
|
return stringBuilder
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.nsclient.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 15.02.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventNSClientRestart extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.nsclient.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventNSClientRestart : Event()
|
|
@ -1,10 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.nsclient.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.EventUpdateGui;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 17.02.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventNSClientUpdateGUI extends EventUpdateGui {
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.nsclient.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.EventUpdateGui
|
||||||
|
|
||||||
|
class EventNSClientUpdateGUI : EventUpdateGui()
|
|
@ -167,6 +167,14 @@ public class NSClientService extends Service {
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventNSClientRestart.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> {
|
||||||
|
latestDateInReceivedData = 0;
|
||||||
|
restart();
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -202,12 +210,6 @@ public class NSClientService extends Service {
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventNSClientRestart ev) {
|
|
||||||
latestDateInReceivedData = 0;
|
|
||||||
restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
dataCounter = 0;
|
dataCounter = 0;
|
||||||
|
|
||||||
|
@ -218,13 +220,13 @@ public class NSClientService extends Service {
|
||||||
|
|
||||||
RxBus.INSTANCE.send(new EventNSClientStatus("Initializing"));
|
RxBus.INSTANCE.send(new EventNSClientStatus("Initializing"));
|
||||||
if (!MainApp.getSpecificPlugin(NSClientPlugin.class).isAllowed()) {
|
if (!MainApp.getSpecificPlugin(NSClientPlugin.class).isAllowed()) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "not allowed"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "not allowed"));
|
||||||
RxBus.INSTANCE.send(new EventNSClientStatus("Not allowed"));
|
RxBus.INSTANCE.send(new EventNSClientStatus("Not allowed"));
|
||||||
} else if (MainApp.getSpecificPlugin(NSClientPlugin.class).paused) {
|
} else if (MainApp.getSpecificPlugin(NSClientPlugin.class).paused) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "paused"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "paused"));
|
||||||
RxBus.INSTANCE.send(new EventNSClientStatus("Paused"));
|
RxBus.INSTANCE.send(new EventNSClientStatus("Paused"));
|
||||||
} else if (!nsEnabled) {
|
} else if (!nsEnabled) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disabled"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "disabled"));
|
||||||
RxBus.INSTANCE.send(new EventNSClientStatus("Disabled"));
|
RxBus.INSTANCE.send(new EventNSClientStatus("Disabled"));
|
||||||
} else if (!nsURL.equals("")) {
|
} else if (!nsURL.equals("")) {
|
||||||
try {
|
try {
|
||||||
|
@ -236,7 +238,7 @@ public class NSClientService extends Service {
|
||||||
mSocket.on(Socket.EVENT_CONNECT, onConnect);
|
mSocket.on(Socket.EVENT_CONNECT, onConnect);
|
||||||
mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
|
mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
|
||||||
mSocket.on(Socket.EVENT_PING, onPing);
|
mSocket.on(Socket.EVENT_PING, onPing);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "do connect"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "do connect"));
|
||||||
mSocket.connect();
|
mSocket.connect();
|
||||||
mSocket.on("dataUpdate", onDataUpdate);
|
mSocket.on("dataUpdate", onDataUpdate);
|
||||||
mSocket.on("announcement", onAnnouncement);
|
mSocket.on("announcement", onAnnouncement);
|
||||||
|
@ -244,11 +246,11 @@ public class NSClientService extends Service {
|
||||||
mSocket.on("urgent_alarm", onUrgentAlarm);
|
mSocket.on("urgent_alarm", onUrgentAlarm);
|
||||||
mSocket.on("clear_alarm", onClearAlarm);
|
mSocket.on("clear_alarm", onClearAlarm);
|
||||||
} catch (URISyntaxException | RuntimeException e) {
|
} catch (URISyntaxException | RuntimeException e) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "Wrong URL syntax"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "Wrong URL syntax"));
|
||||||
RxBus.INSTANCE.send(new EventNSClientStatus("Wrong URL syntax"));
|
RxBus.INSTANCE.send(new EventNSClientStatus("Wrong URL syntax"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "No NS URL specified"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "No NS URL specified"));
|
||||||
RxBus.INSTANCE.send(new EventNSClientStatus("Not configured"));
|
RxBus.INSTANCE.send(new EventNSClientStatus("Not configured"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,7 +260,7 @@ public class NSClientService extends Service {
|
||||||
public void call(Object... args) {
|
public void call(Object... args) {
|
||||||
connectCounter++;
|
connectCounter++;
|
||||||
String socketId = mSocket != null ? mSocket.id() : "NULL";
|
String socketId = mSocket != null ? mSocket.id() : "NULL";
|
||||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "connect #" + connectCounter + " event. ID: " + socketId));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "connect #" + connectCounter + " event. ID: " + socketId));
|
||||||
if (mSocket != null)
|
if (mSocket != null)
|
||||||
sendAuthMessage(new NSAuthAck());
|
sendAuthMessage(new NSAuthAck());
|
||||||
watchdog();
|
watchdog();
|
||||||
|
@ -275,16 +277,16 @@ public class NSClientService extends Service {
|
||||||
reconnections.remove(r);
|
reconnections.remove(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientNewLog("WATCHDOG", "connections in last " + WATCHDOG_INTERVAL_MINUTES + " mins: " + reconnections.size() + "/" + WATCHDOG_MAXCONNECTIONS));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("WATCHDOG", "connections in last " + WATCHDOG_INTERVAL_MINUTES + " mins: " + reconnections.size() + "/" + WATCHDOG_MAXCONNECTIONS));
|
||||||
if (reconnections.size() >= WATCHDOG_MAXCONNECTIONS) {
|
if (reconnections.size() >= WATCHDOG_MAXCONNECTIONS) {
|
||||||
Notification n = new Notification(Notification.NSMALFUNCTION, MainApp.gs(R.string.nsmalfunction), Notification.URGENT);
|
Notification n = new Notification(Notification.NSMALFUNCTION, MainApp.gs(R.string.nsmalfunction), Notification.URGENT);
|
||||||
RxBus.INSTANCE.send(new EventNewNotification(n));
|
RxBus.INSTANCE.send(new EventNewNotification(n));
|
||||||
MainApp.bus().post(new EventNSClientNewLog("WATCHDOG", "pausing for " + WATCHDOG_RECONNECT_IN + " mins"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("WATCHDOG", "pausing for " + WATCHDOG_RECONNECT_IN + " mins"));
|
||||||
NSClientPlugin.getPlugin().pause(true);
|
NSClientPlugin.getPlugin().pause(true);
|
||||||
MainApp.bus().post(new EventNSClientUpdateGUI());
|
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
SystemClock.sleep(T.mins(WATCHDOG_RECONNECT_IN).msecs());
|
SystemClock.sleep(T.mins(WATCHDOG_RECONNECT_IN).msecs());
|
||||||
MainApp.bus().post(new EventNSClientNewLog("WATCHDOG", "reenabling NSClient"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("WATCHDOG", "reenabling NSClient"));
|
||||||
NSClientPlugin.getPlugin().pause(false);
|
NSClientPlugin.getPlugin().pause(false);
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
@ -296,7 +298,7 @@ public class NSClientService extends Service {
|
||||||
public void call(Object... args) {
|
public void call(Object... args) {
|
||||||
if (L.isEnabled(L.NSCLIENT))
|
if (L.isEnabled(L.NSCLIENT))
|
||||||
log.debug("disconnect reason: {}", args);
|
log.debug("disconnect reason: {}", args);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disconnect event"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "disconnect event"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -311,7 +313,7 @@ public class NSClientService extends Service {
|
||||||
mSocket.off("urgent_alarm");
|
mSocket.off("urgent_alarm");
|
||||||
mSocket.off("clear_alarm");
|
mSocket.off("clear_alarm");
|
||||||
|
|
||||||
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "destroy"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "destroy"));
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
hasWriteAuth = false;
|
hasWriteAuth = false;
|
||||||
mSocket.disconnect();
|
mSocket.disconnect();
|
||||||
|
@ -332,7 +334,7 @@ public class NSClientService extends Service {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientNewLog("AUTH", "requesting auth"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("AUTH", "requesting auth"));
|
||||||
if (mSocket != null)
|
if (mSocket != null)
|
||||||
mSocket.emit("authorize", authMessage, ack);
|
mSocket.emit("authorize", authMessage, ack);
|
||||||
}
|
}
|
||||||
|
@ -347,12 +349,12 @@ public class NSClientService extends Service {
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
hasWriteAuth = ack.write && ack.write_treatment;
|
hasWriteAuth = ack.write && ack.write_treatment;
|
||||||
RxBus.INSTANCE.send(new EventNSClientStatus(connectionStatus));
|
RxBus.INSTANCE.send(new EventNSClientStatus(connectionStatus));
|
||||||
MainApp.bus().post(new EventNSClientNewLog("AUTH", connectionStatus));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("AUTH", connectionStatus));
|
||||||
if (!ack.write) {
|
if (!ack.write) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Write permission not granted !!!!"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("ERROR", "Write permission not granted !!!!"));
|
||||||
}
|
}
|
||||||
if (!ack.write_treatment) {
|
if (!ack.write_treatment) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Write treatment permission not granted !!!!"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("ERROR", "Write treatment permission not granted !!!!"));
|
||||||
}
|
}
|
||||||
if (!hasWriteAuth) {
|
if (!hasWriteAuth) {
|
||||||
Notification noperm = new Notification(Notification.NSCLIENT_NO_WRITE_PERMISSION, MainApp.gs(R.string.nowritepermission), Notification.URGENT);
|
Notification noperm = new Notification(Notification.NSCLIENT_NO_WRITE_PERMISSION, MainApp.gs(R.string.nowritepermission), Notification.URGENT);
|
||||||
|
@ -372,7 +374,7 @@ public class NSClientService extends Service {
|
||||||
private Emitter.Listener onPing = new Emitter.Listener() {
|
private Emitter.Listener onPing = new Emitter.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void call(final Object... args) {
|
public void call(final Object... args) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("PING", "received"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("PING", "received"));
|
||||||
// send data if there is something waiting
|
// send data if there is something waiting
|
||||||
resend("Ping received");
|
resend("Ping received");
|
||||||
}
|
}
|
||||||
|
@ -401,7 +403,7 @@ public class NSClientService extends Service {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(data, "message", "received")));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(data, "message", "received")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FabricPrivacy.logException(e);
|
FabricPrivacy.logException(e);
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
@ -428,7 +430,7 @@ public class NSClientService extends Service {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void call(final Object... args) {
|
public void call(final Object... args) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ALARM", "received"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("ALARM", "received"));
|
||||||
JSONObject data;
|
JSONObject data;
|
||||||
try {
|
try {
|
||||||
data = (JSONObject) args[0];
|
data = (JSONObject) args[0];
|
||||||
|
@ -467,7 +469,7 @@ public class NSClientService extends Service {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientNewLog("URGENTALARM", "received"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("URGENTALARM", "received"));
|
||||||
BroadcastUrgentAlarm.handleUrgentAlarm(data, getApplicationContext());
|
BroadcastUrgentAlarm.handleUrgentAlarm(data, getApplicationContext());
|
||||||
if (L.isEnabled(L.NSCLIENT))
|
if (L.isEnabled(L.NSCLIENT))
|
||||||
log.debug(data.toString());
|
log.debug(data.toString());
|
||||||
|
@ -493,7 +495,7 @@ public class NSClientService extends Service {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientNewLog("CLEARALARM", "received"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("CLEARALARM", "received"));
|
||||||
BroadcastClearAlarm.handleClearAlarm(data, getApplicationContext());
|
BroadcastClearAlarm.handleClearAlarm(data, getApplicationContext());
|
||||||
if (L.isEnabled(L.NSCLIENT))
|
if (L.isEnabled(L.NSCLIENT))
|
||||||
log.debug(data.toString());
|
log.debug(data.toString());
|
||||||
|
@ -518,7 +520,7 @@ public class NSClientService extends Service {
|
||||||
// delta means only increment/changes are comming
|
// delta means only increment/changes are comming
|
||||||
boolean isDelta = data.has("delta");
|
boolean isDelta = data.has("delta");
|
||||||
boolean isFull = !isDelta;
|
boolean isFull = !isDelta;
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DATA", "Data packet #" + dataCounter++ + (isDelta ? " delta" : " full")));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DATA", "Data packet #" + dataCounter++ + (isDelta ? " delta" : " full")));
|
||||||
|
|
||||||
if (data.has("profiles")) {
|
if (data.has("profiles")) {
|
||||||
JSONArray profiles = data.getJSONArray("profiles");
|
JSONArray profiles = data.getJSONArray("profiles");
|
||||||
|
@ -526,7 +528,7 @@ public class NSClientService extends Service {
|
||||||
JSONObject profile = (JSONObject) profiles.get(profiles.length() - 1);
|
JSONObject profile = (JSONObject) profiles.get(profiles.length() - 1);
|
||||||
profileStore = new ProfileStore(profile);
|
profileStore = new ProfileStore(profile);
|
||||||
broadcastProfile = true;
|
broadcastProfile = true;
|
||||||
MainApp.bus().post(new EventNSClientNewLog("PROFILE", "profile received"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("PROFILE", "profile received"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +538,7 @@ public class NSClientService extends Service {
|
||||||
|
|
||||||
if (!status.has("versionNum")) {
|
if (!status.has("versionNum")) {
|
||||||
if (status.getInt("versionNum") < Config.SUPPORTEDNSVERSION) {
|
if (status.getInt("versionNum") < Config.SUPPORTEDNSVERSION) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nightscoutVersionName = nsSettingsStatus.getVersion();
|
nightscoutVersionName = nsSettingsStatus.getVersion();
|
||||||
|
@ -561,13 +563,13 @@ public class NSClientService extends Service {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
} else if (!isDelta) {
|
} else if (!isDelta) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If new profile received or change detected broadcast it
|
// If new profile received or change detected broadcast it
|
||||||
if (broadcastProfile && profileStore != null) {
|
if (broadcastProfile && profileStore != null) {
|
||||||
BroadcastProfile.handleNewTreatment(profileStore, MainApp.instance().getApplicationContext(), isDelta);
|
BroadcastProfile.handleNewTreatment(profileStore, MainApp.instance().getApplicationContext(), isDelta);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("PROFILE", "broadcasting"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("PROFILE", "broadcasting"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.has("treatments")) {
|
if (data.has("treatments")) {
|
||||||
|
@ -576,7 +578,7 @@ public class NSClientService extends Service {
|
||||||
JSONArray updatedTreatments = new JSONArray();
|
JSONArray updatedTreatments = new JSONArray();
|
||||||
JSONArray addedTreatments = new JSONArray();
|
JSONArray addedTreatments = new JSONArray();
|
||||||
if (treatments.length() > 0)
|
if (treatments.length() > 0)
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + treatments.length() + " treatments"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DATA", "received " + treatments.length() + " treatments"));
|
||||||
for (Integer index = 0; index < treatments.length(); index++) {
|
for (Integer index = 0; index < treatments.length(); index++) {
|
||||||
JSONObject jsonTreatment = treatments.getJSONObject(index);
|
JSONObject jsonTreatment = treatments.getJSONObject(index);
|
||||||
NSTreatment treatment = new NSTreatment(jsonTreatment);
|
NSTreatment treatment = new NSTreatment(jsonTreatment);
|
||||||
|
@ -610,7 +612,7 @@ public class NSClientService extends Service {
|
||||||
if (data.has("devicestatus")) {
|
if (data.has("devicestatus")) {
|
||||||
JSONArray devicestatuses = data.getJSONArray("devicestatus");
|
JSONArray devicestatuses = data.getJSONArray("devicestatus");
|
||||||
if (devicestatuses.length() > 0) {
|
if (devicestatuses.length() > 0) {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + devicestatuses.length() + " devicestatuses"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DATA", "received " + devicestatuses.length() + " devicestatuses"));
|
||||||
for (Integer index = 0; index < devicestatuses.length(); index++) {
|
for (Integer index = 0; index < devicestatuses.length(); index++) {
|
||||||
JSONObject jsonStatus = devicestatuses.getJSONObject(index);
|
JSONObject jsonStatus = devicestatuses.getJSONObject(index);
|
||||||
// remove from upload queue if Ack is failing
|
// remove from upload queue if Ack is failing
|
||||||
|
@ -625,7 +627,7 @@ public class NSClientService extends Service {
|
||||||
JSONArray updatedFoods = new JSONArray();
|
JSONArray updatedFoods = new JSONArray();
|
||||||
JSONArray addedFoods = new JSONArray();
|
JSONArray addedFoods = new JSONArray();
|
||||||
if (foods.length() > 0)
|
if (foods.length() > 0)
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + foods.length() + " foods"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DATA", "received " + foods.length() + " foods"));
|
||||||
for (Integer index = 0; index < foods.length(); index++) {
|
for (Integer index = 0; index < foods.length(); index++) {
|
||||||
JSONObject jsonFood = foods.getJSONObject(index);
|
JSONObject jsonFood = foods.getJSONObject(index);
|
||||||
|
|
||||||
|
@ -655,7 +657,7 @@ public class NSClientService extends Service {
|
||||||
if (data.has("mbgs")) {
|
if (data.has("mbgs")) {
|
||||||
JSONArray mbgs = data.getJSONArray("mbgs");
|
JSONArray mbgs = data.getJSONArray("mbgs");
|
||||||
if (mbgs.length() > 0)
|
if (mbgs.length() > 0)
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + mbgs.length() + " mbgs"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DATA", "received " + mbgs.length() + " mbgs"));
|
||||||
for (Integer index = 0; index < mbgs.length(); index++) {
|
for (Integer index = 0; index < mbgs.length(); index++) {
|
||||||
JSONObject jsonMbg = mbgs.getJSONObject(index);
|
JSONObject jsonMbg = mbgs.getJSONObject(index);
|
||||||
// remove from upload queue if Ack is failing
|
// remove from upload queue if Ack is failing
|
||||||
|
@ -666,7 +668,7 @@ public class NSClientService extends Service {
|
||||||
if (data.has("cals")) {
|
if (data.has("cals")) {
|
||||||
JSONArray cals = data.getJSONArray("cals");
|
JSONArray cals = data.getJSONArray("cals");
|
||||||
if (cals.length() > 0)
|
if (cals.length() > 0)
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + cals.length() + " cals"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DATA", "received " + cals.length() + " cals"));
|
||||||
// Retreive actual calibration
|
// Retreive actual calibration
|
||||||
for (Integer index = 0; index < cals.length(); index++) {
|
for (Integer index = 0; index < cals.length(); index++) {
|
||||||
// remove from upload queue if Ack is failing
|
// remove from upload queue if Ack is failing
|
||||||
|
@ -677,10 +679,10 @@ public class NSClientService extends Service {
|
||||||
if (data.has("sgvs")) {
|
if (data.has("sgvs")) {
|
||||||
JSONArray sgvs = data.getJSONArray("sgvs");
|
JSONArray sgvs = data.getJSONArray("sgvs");
|
||||||
if (sgvs.length() > 0)
|
if (sgvs.length() > 0)
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DATA", "received " + sgvs.length() + " sgvs"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DATA", "received " + sgvs.length() + " sgvs"));
|
||||||
for (Integer index = 0; index < sgvs.length(); index++) {
|
for (Integer index = 0; index < sgvs.length(); index++) {
|
||||||
JSONObject jsonSgv = sgvs.getJSONObject(index);
|
JSONObject jsonSgv = sgvs.getJSONObject(index);
|
||||||
// MainApp.bus().post(new EventNSClientNewLog("DATA", "svg " + sgvs.getJSONObject(index).toString());
|
// RxBus.INSTANCE.send(new EventNSClientNewLog("DATA", "svg " + sgvs.getJSONObject(index).toString());
|
||||||
NSSgv sgv = new NSSgv(jsonSgv);
|
NSSgv sgv = new NSSgv(jsonSgv);
|
||||||
// Handle new sgv here
|
// Handle new sgv here
|
||||||
// remove from upload queue if Ack is failing
|
// remove from upload queue if Ack is failing
|
||||||
|
@ -699,11 +701,11 @@ public class NSClientService extends Service {
|
||||||
}
|
}
|
||||||
BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
|
BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData)));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData)));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
//MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
|
//RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
|
||||||
} finally {
|
} finally {
|
||||||
if (wakeLock.isHeld()) wakeLock.release();
|
if (wakeLock.isHeld()) wakeLock.release();
|
||||||
}
|
}
|
||||||
|
@ -721,7 +723,7 @@ public class NSClientService extends Service {
|
||||||
message.put("_id", dbr._id);
|
message.put("_id", dbr._id);
|
||||||
message.put("data", new JSONObject(dbr.data));
|
message.put("data", new JSONObject(dbr.data));
|
||||||
mSocket.emit("dbUpdate", message, ack);
|
mSocket.emit("dbUpdate", message, ack);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DBUPDATE " + dbr.collection, "Sent " + dbr._id));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DBUPDATE " + dbr.collection, "Sent " + dbr._id));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -735,7 +737,7 @@ public class NSClientService extends Service {
|
||||||
message.put("_id", dbr._id);
|
message.put("_id", dbr._id);
|
||||||
message.put("data", new JSONObject(dbr.data));
|
message.put("data", new JSONObject(dbr.data));
|
||||||
mSocket.emit("dbUpdateUnset", message, ack);
|
mSocket.emit("dbUpdateUnset", message, ack);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DBUPDATEUNSET " + dbr.collection, "Sent " + dbr._id));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DBUPDATEUNSET " + dbr.collection, "Sent " + dbr._id));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -748,7 +750,7 @@ public class NSClientService extends Service {
|
||||||
message.put("collection", dbr.collection);
|
message.put("collection", dbr.collection);
|
||||||
message.put("_id", dbr._id);
|
message.put("_id", dbr._id);
|
||||||
mSocket.emit("dbRemove", message, ack);
|
mSocket.emit("dbRemove", message, ack);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DBREMOVE " + dbr.collection, "Sent " + dbr._id));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DBREMOVE " + dbr.collection, "Sent " + dbr._id));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -758,9 +760,9 @@ public class NSClientService extends Service {
|
||||||
public void onStatusEvent(NSUpdateAck ack) {
|
public void onStatusEvent(NSUpdateAck ack) {
|
||||||
if (ack.result) {
|
if (ack.result) {
|
||||||
uploadQueue.removeID(ack.action, ack._id);
|
uploadQueue.removeID(ack.action, ack._id);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked " + ack._id));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DBUPDATE/DBREMOVE", "Acked " + ack._id));
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ERROR", "DBUPDATE/DBREMOVE Unknown response"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("ERROR", "DBUPDATE/DBREMOVE Unknown response"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -771,7 +773,7 @@ public class NSClientService extends Service {
|
||||||
message.put("collection", dbr.collection);
|
message.put("collection", dbr.collection);
|
||||||
message.put("data", new JSONObject(dbr.data));
|
message.put("data", new JSONObject(dbr.data));
|
||||||
mSocket.emit("dbAdd", message, ack);
|
mSocket.emit("dbAdd", message, ack);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DBADD " + dbr.collection, "Sent " + dbr.nsClientID));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DBADD " + dbr.collection, "Sent " + dbr.nsClientID));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
@ -780,16 +782,16 @@ public class NSClientService extends Service {
|
||||||
public void sendAlarmAck(AlarmAck alarmAck) {
|
public void sendAlarmAck(AlarmAck alarmAck) {
|
||||||
if (!isConnected || !hasWriteAuth) return;
|
if (!isConnected || !hasWriteAuth) return;
|
||||||
mSocket.emit("ack", alarmAck.level, alarmAck.group, alarmAck.silenceTime);
|
mSocket.emit("ack", alarmAck.level, alarmAck.group, alarmAck.silenceTime);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ALARMACK ", alarmAck.level + " " + alarmAck.group + " " + alarmAck.silenceTime));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("ALARMACK ", alarmAck.level + " " + alarmAck.group + " " + alarmAck.silenceTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(NSAddAck ack) {
|
public void onStatusEvent(NSAddAck ack) {
|
||||||
if (ack.nsClientID != null) {
|
if (ack.nsClientID != null) {
|
||||||
uploadQueue.removeID(ack.json);
|
uploadQueue.removeID(ack.json);
|
||||||
MainApp.bus().post(new EventNSClientNewLog("DBADD", "Acked " + ack.nsClientID));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("DBADD", "Acked " + ack.nsClientID));
|
||||||
} else {
|
} else {
|
||||||
MainApp.bus().post(new EventNSClientNewLog("ERROR", "DBADD Unknown response"));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("ERROR", "DBADD Unknown response"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -811,7 +813,7 @@ public class NSClientService extends Service {
|
||||||
}
|
}
|
||||||
lastResendTime = System.currentTimeMillis();
|
lastResendTime = System.currentTimeMillis();
|
||||||
|
|
||||||
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend started: " + reason));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("QUEUE", "Resend started: " + reason));
|
||||||
|
|
||||||
CloseableIterator<DbRequest> iterator = null;
|
CloseableIterator<DbRequest> iterator = null;
|
||||||
int maxcount = 30;
|
int maxcount = 30;
|
||||||
|
@ -842,7 +844,7 @@ public class NSClientService extends Service {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -942,6 +942,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
.subscribe(event -> updatePumpStatus(event.getStatus()),
|
.subscribe(event -> updatePumpStatus(event.getStatus()),
|
||||||
FabricPrivacy::logException
|
FabricPrivacy::logException
|
||||||
));
|
));
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventIobCalculationProgress.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> {
|
||||||
|
if (iobCalculationProgressView != null)
|
||||||
|
iobCalculationProgressView.setText(event.getProgress());
|
||||||
|
},
|
||||||
|
FabricPrivacy::logException
|
||||||
|
));
|
||||||
sRefreshLoop = () -> {
|
sRefreshLoop = () -> {
|
||||||
scheduleUpdateGUI("refreshLoop");
|
scheduleUpdateGUI("refreshLoop");
|
||||||
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
||||||
|
@ -958,16 +967,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
scheduleUpdateGUI("EventNewOpenLoopNotification");
|
scheduleUpdateGUI("EventNewOpenLoopNotification");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventIobCalculationProgress e) {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(() -> {
|
|
||||||
if (iobCalculationProgressView != null)
|
|
||||||
iobCalculationProgressView.setText(e.progress);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void hideTempRecommendation() {
|
private void hideTempRecommendation() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null)
|
if (activity != null)
|
||||||
|
|
|
@ -411,7 +411,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
private void processTREATMENTS(String[] splitted, Sms receivedSms) {
|
private void processTREATMENTS(String[] splitted, Sms receivedSms) {
|
||||||
if (splitted[1].toUpperCase().equals("REFRESH")) {
|
if (splitted[1].toUpperCase().equals("REFRESH")) {
|
||||||
TreatmentsPlugin.getPlugin().getService().resetTreatments();
|
TreatmentsPlugin.getPlugin().getService().resetTreatments();
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, "TREATMENTS REFRESH SENT"));
|
sendSMS(new Sms(receivedSms.phoneNumber, "TREATMENTS REFRESH SENT"));
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
} else
|
} else
|
||||||
|
@ -420,7 +420,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
|
|
||||||
private void processNSCLIENT(String[] splitted, Sms receivedSms) {
|
private void processNSCLIENT(String[] splitted, Sms receivedSms) {
|
||||||
if (splitted[1].toUpperCase().equals("RESTART")) {
|
if (splitted[1].toUpperCase().equals("RESTART")) {
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, "NSCLIENT RESTART SENT"));
|
sendSMS(new Sms(receivedSms.phoneNumber, "NSCLIENT RESTART SENT"));
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -6,8 +6,6 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.collection.LongSparseArray;
|
import androidx.collection.LongSparseArray;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -90,7 +88,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
MainApp.bus().register(this);
|
|
||||||
// EventConfigBuilderChange
|
// EventConfigBuilderChange
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
.toObservable(EventConfigBuilderChange.class)
|
.toObservable(EventConfigBuilderChange.class)
|
||||||
|
@ -194,12 +191,17 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event);
|
runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event);
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
|
// EventNewHistoryData
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventNewHistoryData.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> newHistoryData(event), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
disposable.clear();
|
disposable.clear();
|
||||||
MainApp.bus().unregister(this);
|
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,8 +765,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated
|
// When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated
|
||||||
@Subscribe
|
public void newHistoryData(EventNewHistoryData ev) {
|
||||||
public void onEventNewHistoryData(EventNewHistoryData ev) {
|
|
||||||
if (this != getPlugin()) {
|
if (this != getPlugin()) {
|
||||||
if (L.isEnabled(L.AUTOSENS))
|
if (L.isEnabled(L.AUTOSENS))
|
||||||
log.debug("Ignoring event for non default instance");
|
log.debug("Ignoring event for non default instance");
|
||||||
|
@ -774,7 +775,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
stopCalculation("onEventNewHistoryData");
|
stopCalculation("onEventNewHistoryData");
|
||||||
synchronized (dataLock) {
|
synchronized (dataLock) {
|
||||||
// clear up 5 min back for proper COB calculation
|
// clear up 5 min back for proper COB calculation
|
||||||
long time = ev.time - 5 * 60 * 1000L;
|
long time = ev.getTime() - 5 * 60 * 1000L;
|
||||||
if (L.isEnabled(L.AUTOSENS))
|
if (L.isEnabled(L.AUTOSENS))
|
||||||
log.debug("Invalidating cached data to: " + DateUtil.dateAndTimeFullString(time));
|
log.debug("Invalidating cached data to: " + DateUtil.dateAndTimeFullString(time));
|
||||||
for (int index = iobTable.size() - 1; index >= 0; index--) {
|
for (int index = iobTable.size() - 1; index >= 0; index--) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class IobCobOref1Thread extends Thread {
|
||||||
// start from oldest to be able sub cob
|
// start from oldest to be able sub cob
|
||||||
for (int i = bucketed_data.size() - 4; i >= 0; i--) {
|
for (int i = bucketed_data.size() - 4; i >= 0; i--) {
|
||||||
String progress = i + (MainApp.isDev() ? " (" + from + ")" : "");
|
String progress = i + (MainApp.isDev() ? " (" + from + ")" : "");
|
||||||
MainApp.bus().post(new EventIobCalculationProgress(progress));
|
RxBus.INSTANCE.send(new EventIobCalculationProgress(progress));
|
||||||
|
|
||||||
if (iobCobCalculatorPlugin.stopCalculationTrigger) {
|
if (iobCobCalculatorPlugin.stopCalculationTrigger) {
|
||||||
iobCobCalculatorPlugin.stopCalculationTrigger = false;
|
iobCobCalculatorPlugin.stopCalculationTrigger = false;
|
||||||
|
@ -392,7 +392,7 @@ public class IobCobOref1Thread extends Thread {
|
||||||
} finally {
|
} finally {
|
||||||
if (mWakeLock != null)
|
if (mWakeLock != null)
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
MainApp.bus().post(new EventIobCalculationProgress(""));
|
RxBus.INSTANCE.send(new EventIobCalculationProgress(""));
|
||||||
if (L.isEnabled(L.AUTOSENS)) {
|
if (L.isEnabled(L.AUTOSENS)) {
|
||||||
log.debug("AUTOSENSDATA thread ended: " + from);
|
log.debug("AUTOSENSDATA thread ended: " + from);
|
||||||
log.debug("Midnights: " + MidnightTime.log());
|
log.debug("Midnights: " + MidnightTime.log());
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import androidx.collection.LongSparseArray;
|
import androidx.collection.LongSparseArray;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -117,7 +118,7 @@ public class IobCobThread extends Thread {
|
||||||
// start from oldest to be able sub cob
|
// start from oldest to be able sub cob
|
||||||
for (int i = bucketed_data.size() - 4; i >= 0; i--) {
|
for (int i = bucketed_data.size() - 4; i >= 0; i--) {
|
||||||
String progress = i + (MainApp.isDev() ? " (" + from + ")" : "");
|
String progress = i + (MainApp.isDev() ? " (" + from + ")" : "");
|
||||||
MainApp.bus().post(new EventIobCalculationProgress(progress));
|
RxBus.INSTANCE.send(new EventIobCalculationProgress(progress));
|
||||||
|
|
||||||
if (iobCobCalculatorPlugin.stopCalculationTrigger) {
|
if (iobCobCalculatorPlugin.stopCalculationTrigger) {
|
||||||
iobCobCalculatorPlugin.stopCalculationTrigger = false;
|
iobCobCalculatorPlugin.stopCalculationTrigger = false;
|
||||||
|
@ -317,7 +318,7 @@ public class IobCobThread extends Thread {
|
||||||
} finally {
|
} finally {
|
||||||
if (mWakeLock != null)
|
if (mWakeLock != null)
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
MainApp.bus().post(new EventIobCalculationProgress(""));
|
RxBus.INSTANCE.send(new EventIobCalculationProgress(""));
|
||||||
if (L.isEnabled(L.AUTOSENS)) {
|
if (L.isEnabled(L.AUTOSENS)) {
|
||||||
log.debug("AUTOSENSDATA thread ended: " + from);
|
log.debug("AUTOSENSDATA thread ended: " + from);
|
||||||
log.debug("Midnights: " + MidnightTime.log());
|
log.debug("Midnights: " + MidnightTime.log());
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
|
|
||||||
public class EventIobCalculationProgress extends Event {
|
|
||||||
public String progress;
|
|
||||||
|
|
||||||
public EventIobCalculationProgress(String progress) {
|
|
||||||
this.progress = progress;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventIobCalculationProgress(var progress: String) : Event()
|
|
@ -1,15 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 26.04.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventNewHistoryData extends Event {
|
|
||||||
public long time = 0;
|
|
||||||
|
|
||||||
public EventNewHistoryData(long time) {
|
|
||||||
this.time = time;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventNewHistoryData(var time: Long) : Event()
|
|
@ -111,7 +111,7 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface {
|
||||||
if (L.isEnabled(L.PROFILE))
|
if (L.isEnabled(L.PROFILE))
|
||||||
log.debug("Stored profile not found");
|
log.debug("Stored profile not found");
|
||||||
// force restart of nsclient to fetch profile
|
// force restart of nsclient to fetch profile
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,28 +5,33 @@ import android.app.Activity;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus;
|
|
||||||
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.common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.combo.events.EventComboPumpUpdateGUI;
|
import info.nightscout.androidaps.plugins.pump.combo.events.EventComboPumpUpdateGUI;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.PumpState;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.combo.ruffyscripter.history.Bolus;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
|
public class ComboFragment extends Fragment implements View.OnClickListener {
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
public class ComboFragment extends SubscriberFragment implements View.OnClickListener {
|
|
||||||
private TextView stateView;
|
private TextView stateView;
|
||||||
private TextView activityView;
|
private TextView activityView;
|
||||||
private TextView batteryView;
|
private TextView batteryView;
|
||||||
|
@ -58,10 +63,31 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
refreshButton = view.findViewById(R.id.combo_refresh_button);
|
refreshButton = view.findViewById(R.id.combo_refresh_button);
|
||||||
refreshButton.setOnClickListener(this);
|
refreshButton.setOnClickListener(this);
|
||||||
|
|
||||||
updateGUI();
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventComboPumpUpdateGUI.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventQueueChanged.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
updateGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
disposable.clear();
|
||||||
|
}
|
||||||
|
|
||||||
private void runOnUiThread(Runnable action) {
|
private void runOnUiThread(Runnable action) {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
|
@ -84,19 +110,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
public void updateGui() {
|
||||||
public void onStatusEvent(final EventComboPumpUpdateGUI ignored) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventQueueChanged ignored) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void updateGUI() {
|
|
||||||
runOnUiThread(() -> {
|
|
||||||
ComboPlugin plugin = ComboPlugin.getPlugin();
|
ComboPlugin plugin = ComboPlugin.getPlugin();
|
||||||
|
|
||||||
// state
|
// state
|
||||||
|
@ -125,7 +139,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
activityView.setTextColor(Color.WHITE);
|
activityView.setTextColor(Color.WHITE);
|
||||||
activityView.setTextSize(14);
|
activityView.setTextSize(14);
|
||||||
activityView.setText("");
|
activityView.setText("");
|
||||||
} else if (plugin.isInitialized()){
|
} else if (plugin.isInitialized()) {
|
||||||
activityView.setTextColor(Color.WHITE);
|
activityView.setTextColor(Color.WHITE);
|
||||||
activityView.setTextSize(20);
|
activityView.setTextSize(20);
|
||||||
activityView.setText("{fa-bed}");
|
activityView.setText("{fa-bed}");
|
||||||
|
@ -226,6 +240,5 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
bolusCount.setText(String.valueOf(SP.getLong(ComboPlugin.COMBO_BOLUSES_DELIVERED, 0L)));
|
bolusCount.setText(String.valueOf(SP.getLong(ComboPlugin.COMBO_BOLUSES_DELIVERED, 0L)));
|
||||||
tbrCount.setText(String.valueOf(SP.getLong(ComboPlugin.COMBO_TBRS_SET, 0L)));
|
tbrCount.setText(String.valueOf(SP.getLong(ComboPlugin.COMBO_TBRS_SET, 0L)));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -390,7 +390,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
|
|
||||||
// ComboFragment updates state fully only after the pump has initialized,
|
// ComboFragment updates state fully only after the pump has initialized,
|
||||||
// so force an update after initialization completed
|
// so force an update after initialization completed
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -406,7 +406,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
if (result.state.menu != null) {
|
if (result.state.menu != null) {
|
||||||
pump.state = result.state;
|
pump.state = result.state;
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -485,7 +485,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
.comment(MainApp.gs(R.string.virtualpump_resultok));
|
.comment(MainApp.gs(R.string.virtualpump_resultok));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +493,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
private PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
private PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
||||||
try {
|
try {
|
||||||
pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
|
pump.activity = MainApp.gs(R.string.combo_pump_action_bolusing, detailedBolusInfo.insulin);
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
|
||||||
|
|
||||||
// check pump is ready and all pump bolus records are known
|
// check pump is ready and all pump bolus records are known
|
||||||
CommandResult stateResult = runCommand(null, 2, () -> ruffyScripter.readQuickInfo(1));
|
CommandResult stateResult = runCommand(null, 2, () -> ruffyScripter.readQuickInfo(1));
|
||||||
|
@ -628,7 +628,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
.carbsDelivered(detailedBolusInfo.carbs);
|
.carbsDelivered(detailedBolusInfo.carbs);
|
||||||
} finally {
|
} finally {
|
||||||
pump.activity = null;
|
pump.activity = null;
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
|
||||||
RxBus.INSTANCE.send(new EventRefreshOverview("Bolus"));
|
RxBus.INSTANCE.send(new EventRefreshOverview("Bolus"));
|
||||||
cancelBolus = false;
|
cancelBolus = false;
|
||||||
}
|
}
|
||||||
|
@ -760,7 +760,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
.source(Source.USER);
|
.source(Source.USER);
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart);
|
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart);
|
||||||
|
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
|
||||||
}
|
}
|
||||||
|
|
||||||
incrementTbrCount();
|
incrementTbrCount();
|
||||||
|
@ -848,7 +848,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
if (!ruffyScripter.isConnected()) {
|
if (!ruffyScripter.isConnected()) {
|
||||||
String originalActivity = pump.activity;
|
String originalActivity = pump.activity;
|
||||||
pump.activity = MainApp.gs(R.string.combo_activity_checking_pump_state);
|
pump.activity = MainApp.gs(R.string.combo_activity_checking_pump_state);
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
|
||||||
CommandResult preCheckError = runOnConnectChecks();
|
CommandResult preCheckError = runOnConnectChecks();
|
||||||
pump.activity = originalActivity;
|
pump.activity = originalActivity;
|
||||||
if (preCheckError != null) {
|
if (preCheckError != null) {
|
||||||
|
@ -859,7 +859,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
|
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
pump.activity = activity;
|
pump.activity = activity;
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
|
||||||
}
|
}
|
||||||
|
|
||||||
commandResult = commandExecution.execute();
|
commandResult = commandExecution.execute();
|
||||||
|
@ -892,7 +892,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
||||||
} finally {
|
} finally {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
pump.activity = null;
|
pump.activity = null;
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.combo.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 24.05.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventComboPumpUpdateGUI {
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.combo.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.EventUpdateGui
|
||||||
|
|
||||||
|
class EventComboPumpUpdateGUI : EventUpdateGui()
|
|
@ -8,7 +8,6 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.squareup.otto.Subscribe
|
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.TDDStatsActivity
|
import info.nightscout.androidaps.activities.TDDStatsActivity
|
||||||
|
@ -81,7 +80,6 @@ class DanaRFragment : Fragment() {
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
MainApp.bus().register(this)
|
|
||||||
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
|
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
|
||||||
disposable += RxBus
|
disposable += RxBus
|
||||||
.toObservable(EventDanaRNewStatus::class.java)
|
.toObservable(EventDanaRNewStatus::class.java)
|
||||||
|
@ -95,6 +93,10 @@ class DanaRFragment : Fragment() {
|
||||||
.toObservable(EventTempBasalChange::class.java)
|
.toObservable(EventTempBasalChange::class.java)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
|
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
|
||||||
|
disposable += RxBus
|
||||||
|
.toObservable(EventQueueChanged::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
|
||||||
disposable += RxBus
|
disposable += RxBus
|
||||||
.toObservable(EventPumpStatusChanged::class.java)
|
.toObservable(EventPumpStatusChanged::class.java)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
@ -118,14 +120,9 @@ class DanaRFragment : Fragment() {
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
disposable.clear()
|
disposable.clear()
|
||||||
MainApp.bus().unregister(this)
|
|
||||||
loopHandler.removeCallbacks(refreshLoop)
|
loopHandler.removeCallbacks(refreshLoop)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
fun onStatusEvent(s: EventQueueChanged) =
|
|
||||||
activity?.runOnUiThread { updateGUI() }
|
|
||||||
|
|
||||||
// GUI functions
|
// GUI functions
|
||||||
@Synchronized
|
@Synchronized
|
||||||
internal fun updateGUI() {
|
internal fun updateGUI() {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.squareup.otto.Subscribe
|
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange
|
import info.nightscout.androidaps.events.EventExtendedBolusChange
|
||||||
|
@ -104,7 +103,6 @@ class MedtronicFragment : Fragment() {
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
MainApp.bus().register(this)
|
|
||||||
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
|
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
|
||||||
disposable += RxBus
|
disposable += RxBus
|
||||||
.toObservable(EventRefreshButtonState::class.java)
|
.toObservable(EventRefreshButtonState::class.java)
|
||||||
|
@ -143,6 +141,10 @@ class MedtronicFragment : Fragment() {
|
||||||
.toObservable(EventPumpStatusChanged::class.java)
|
.toObservable(EventPumpStatusChanged::class.java)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
|
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
|
||||||
|
disposable += RxBus
|
||||||
|
.toObservable(EventQueueChanged::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
|
||||||
|
|
||||||
updateGUI()
|
updateGUI()
|
||||||
}
|
}
|
||||||
|
@ -151,15 +153,9 @@ class MedtronicFragment : Fragment() {
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
disposable.clear()
|
disposable.clear()
|
||||||
MainApp.bus().unregister(this)
|
|
||||||
loopHandler.removeCallbacks(refreshLoop)
|
loopHandler.removeCallbacks(refreshLoop)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
fun onStatusEvent(s: EventQueueChanged) {
|
|
||||||
activity?.runOnUiThread { updateGUI() }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun setDeviceStatus() {
|
private fun setDeviceStatus() {
|
||||||
val pumpStatus: MedtronicPumpStatus = MedtronicUtil.getPumpStatus()
|
val pumpStatus: MedtronicPumpStatus = MedtronicUtil.getPumpStatus()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.treatments;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
||||||
|
@ -13,7 +14,6 @@ import com.j256.ormlite.stmt.QueryBuilder;
|
||||||
import com.j256.ormlite.stmt.Where;
|
import com.j256.ormlite.stmt.Where;
|
||||||
import com.j256.ormlite.support.ConnectionSource;
|
import com.j256.ormlite.support.ConnectionSource;
|
||||||
import com.j256.ormlite.table.TableUtils;
|
import com.j256.ormlite.table.TableUtils;
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -35,7 +35,6 @@ import info.nightscout.androidaps.db.ICallback;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.events.Event;
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.events.EventNsTreatment;
|
import info.nightscout.androidaps.events.EventNsTreatment;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
|
||||||
import info.nightscout.androidaps.events.EventReloadTreatmentData;
|
import info.nightscout.androidaps.events.EventReloadTreatmentData;
|
||||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
@ -191,7 +190,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
if (DatabaseHelper.earliestDataChange != null) {
|
if (DatabaseHelper.earliestDataChange != null) {
|
||||||
if (L.isEnabled(L.DATATREATMENTS))
|
if (L.isEnabled(L.DATATREATMENTS))
|
||||||
log.debug("Firing EventNewHistoryData");
|
log.debug("Firing EventNewHistoryData");
|
||||||
MainApp.bus().post(new EventNewHistoryData(DatabaseHelper.earliestDataChange));
|
RxBus.INSTANCE.send(new EventNewHistoryData(DatabaseHelper.earliestDataChange));
|
||||||
}
|
}
|
||||||
DatabaseHelper.earliestDataChange = null;
|
DatabaseHelper.earliestDataChange = null;
|
||||||
callback.setPost(null);
|
callback.setPost(null);
|
||||||
|
@ -256,8 +255,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
createOrUpdate(treatment);
|
createOrUpdate(treatment);
|
||||||
else
|
else
|
||||||
createOrUpdateMedtronic(treatment, false);
|
createOrUpdateMedtronic(treatment, false);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
log.error("Date is null: " + treatment.toString());
|
log.error("Date is null: " + treatment.toString());
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
@ -401,7 +399,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
|
|
||||||
Treatment existingTreatment = getRecord(treatment.pumpId, treatment.date);
|
Treatment existingTreatment = getRecord(treatment.pumpId, treatment.date);
|
||||||
|
|
||||||
if (existingTreatment==null) {
|
if (existingTreatment == null) {
|
||||||
getDao().create(treatment);
|
getDao().create(treatment);
|
||||||
if (L.isEnabled(L.DATATREATMENTS))
|
if (L.isEnabled(L.DATATREATMENTS))
|
||||||
log.debug("New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
log.debug("New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||||
|
@ -410,7 +408,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
return new UpdateReturn(true, true);
|
return new UpdateReturn(true, true);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (existingTreatment.date==treatment.date) {
|
if (existingTreatment.date == treatment.date) {
|
||||||
// we will do update only, if entry changed
|
// we will do update only, if entry changed
|
||||||
if (!optionalTreatmentCopy(existingTreatment, treatment, fromNightScout)) {
|
if (!optionalTreatmentCopy(existingTreatment, treatment, fromNightScout)) {
|
||||||
return new UpdateReturn(true, false);
|
return new UpdateReturn(true, false);
|
||||||
|
@ -483,15 +481,15 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
|
|
||||||
int source = Source.NONE;
|
int source = Source.NONE;
|
||||||
|
|
||||||
if (oldTreatment.pumpId==0) {
|
if (oldTreatment.pumpId == 0) {
|
||||||
if (newTreatment.pumpId > 0) {
|
if (newTreatment.pumpId > 0) {
|
||||||
oldTreatment.pumpId=newTreatment.pumpId;
|
oldTreatment.pumpId = newTreatment.pumpId;
|
||||||
source = Source.PUMP;
|
source = Source.PUMP;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source==Source.NONE) {
|
if (source == Source.NONE) {
|
||||||
|
|
||||||
if (oldTreatment.source == newTreatment.source) {
|
if (oldTreatment.source == newTreatment.source) {
|
||||||
source = oldTreatment.source;
|
source = oldTreatment.source;
|
||||||
|
@ -522,7 +520,6 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
log.debug("treatmentCopy [old={}, new={}]", oldTreatment.toString(), newTreatment.toString());
|
log.debug("treatmentCopy [old={}, new={}]", oldTreatment.toString(), newTreatment.toString());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (fromNightScout) {
|
if (fromNightScout) {
|
||||||
long pumpId_old = oldTreatment.pumpId;
|
long pumpId_old = oldTreatment.pumpId;
|
||||||
boolean isSMB = (oldTreatment.isSMB || newTreatment.isSMB);
|
boolean isSMB = (oldTreatment.isSMB || newTreatment.isSMB);
|
||||||
|
@ -552,7 +549,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
|
|
||||||
Treatment record = null;
|
Treatment record = null;
|
||||||
|
|
||||||
if (pumpId>0) {
|
if (pumpId > 0) {
|
||||||
|
|
||||||
record = getPumpRecordById(pumpId);
|
record = getPumpRecordById(pumpId);
|
||||||
|
|
||||||
|
@ -572,7 +569,6 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the record for the given id, null if none, throws RuntimeException
|
* Returns the record for the given id, null if none, throws RuntimeException
|
||||||
* if multiple records with the same pump id exist.
|
* if multiple records with the same pump id exist.
|
||||||
|
|
|
@ -232,7 +232,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
|
||||||
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?");
|
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?");
|
||||||
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
|
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
|
||||||
TreatmentsPlugin.getPlugin().getService().resetTreatments();
|
TreatmentsPlugin.getPlugin().getService().resetTreatments();
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
||||||
builder.show();
|
builder.show();
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class TreatmentsCareportalFragment extends Fragment implements View.OnCli
|
||||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
MainApp.getDbHelper().resetCareportalEvents();
|
MainApp.getDbHelper().resetCareportalEvents();
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
||||||
|
|
|
@ -231,7 +231,7 @@ public class TreatmentsProfileSwitchFragment extends Fragment implements View.On
|
||||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
MainApp.getDbHelper().resetProfileSwitch();
|
MainApp.getDbHelper().resetProfileSwitch();
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
||||||
|
|
|
@ -217,7 +217,7 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
|
||||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
MainApp.getDbHelper().resetTempTargets();
|
MainApp.getDbHelper().resetTempTargets();
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class QueueThread extends Thread {
|
||||||
public final void run() {
|
public final void run() {
|
||||||
if (mWakeLock != null)
|
if (mWakeLock != null)
|
||||||
mWakeLock.acquire(T.mins(10).msecs());
|
mWakeLock.acquire(T.mins(10).msecs());
|
||||||
MainApp.bus().post(new EventQueueChanged());
|
RxBus.INSTANCE.send(new EventQueueChanged());
|
||||||
long lastCommandTime;
|
long lastCommandTime;
|
||||||
long connectionStartTime = lastCommandTime = System.currentTimeMillis();
|
long connectionStartTime = lastCommandTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
@ -145,10 +145,10 @@ public class QueueThread extends Thread {
|
||||||
if (queue.performing() != null) {
|
if (queue.performing() != null) {
|
||||||
if (L.isEnabled(L.PUMPQUEUE))
|
if (L.isEnabled(L.PUMPQUEUE))
|
||||||
log.debug("performing " + queue.performing().status());
|
log.debug("performing " + queue.performing().status());
|
||||||
MainApp.bus().post(new EventQueueChanged());
|
RxBus.INSTANCE.send(new EventQueueChanged());
|
||||||
queue.performing().execute();
|
queue.performing().execute();
|
||||||
queue.resetPerforming();
|
queue.resetPerforming();
|
||||||
MainApp.bus().post(new EventQueueChanged());
|
RxBus.INSTANCE.send(new EventQueueChanged());
|
||||||
lastCommandTime = System.currentTimeMillis();
|
lastCommandTime = System.currentTimeMillis();
|
||||||
SystemClock.sleep(100);
|
SystemClock.sleep(100);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue