Events to RxBus

This commit is contained in:
Milos Kozak 2019-10-15 09:52:48 +02:00
parent 06f8af82d8
commit 6044335b1d
34 changed files with 406 additions and 438 deletions

View file

@ -16,7 +16,6 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.core.content.res.ResourcesCompat;
import com.jjoe64.graphview.GraphView;
import com.squareup.otto.Subscribe;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import org.slf4j.Logger;
@ -169,7 +168,6 @@ public class HistoryBrowseActivity extends NoSplashActivity {
@Override
public void onPause() {
super.onPause();
MainApp.bus().unregister(this);
disposable.clear();
iobCobCalculatorPlugin.stopCalculation("onPause");
}
@ -177,7 +175,6 @@ public class HistoryBrowseActivity extends NoSplashActivity {
@Override
public void onResume() {
super.onResume();
MainApp.bus().register(this);
disposable.add(RxBus.INSTANCE
.toObservable(EventAutosensCalculationFinished.class)
.observeOn(AndroidSchedulers.mainThread())
@ -190,6 +187,14 @@ public class HistoryBrowseActivity extends NoSplashActivity {
}
}, 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
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
@ -210,14 +215,6 @@ public class HistoryBrowseActivity extends NoSplashActivity {
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) {
log.debug("updateGUI from: " + from);

View file

@ -1037,7 +1037,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
RxBus.INSTANCE.send(new EventReloadTempBasalData());
RxBus.INSTANCE.send(new EventTempBasalChange());
if (earliestDataChange != null)
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
RxBus.INSTANCE.send(new EventNewHistoryData(earliestDataChange));
earliestDataChange = null;
scheduledTemBasalsPost = null;
}
@ -1372,7 +1372,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
log.debug("Firing EventExtendedBolusChange");
RxBus.INSTANCE.send(new EventReloadTreatmentData(new EventExtendedBolusChange()));
if (earliestDataChange != null)
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
RxBus.INSTANCE.send(new EventNewHistoryData(earliestDataChange));
earliestDataChange = null;
scheduledExtendedBolusPost = null;
}

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.general.nsclient;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
@ -17,18 +16,22 @@ import android.widget.CompoundButton;
import android.widget.ScrollView;
import android.widget.TextView;
import com.squareup.otto.Subscribe;
import androidx.fragment.app.Fragment;
import info.nightscout.androidaps.MainApp;
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.EventNSClientRestart;
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
import info.nightscout.androidaps.utils.FabricPrivacy;
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 queueTextView;
private TextView urlTextView;
@ -45,51 +48,61 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
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);
autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
autoscrollCheckbox.setChecked(NSClientPlugin.getPlugin().autoscroll);
autoscrollCheckbox.setOnCheckedChangeListener(this);
pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
pausedCheckbox.setChecked(NSClientPlugin.getPlugin().paused);
pausedCheckbox.setOnCheckedChangeListener(this);
logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue);
urlTextView = (TextView) view.findViewById(R.id.nsclientinternal_url);
statusTextView = (TextView) view.findViewById(R.id.nsclientinternal_status);
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
autoscrollCheckbox.setChecked(NSClientPlugin.getPlugin().autoscroll);
autoscrollCheckbox.setOnCheckedChangeListener(this);
pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
pausedCheckbox.setChecked(NSClientPlugin.getPlugin().paused);
pausedCheckbox.setOnCheckedChangeListener(this);
logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue);
urlTextView = (TextView) view.findViewById(R.id.nsclientinternal_url);
statusTextView = (TextView) view.findViewById(R.id.nsclientinternal_status);
clearlog = (TextView) view.findViewById(R.id.nsclientinternal_clearlog);
clearlog.setOnClickListener(this);
clearlog.setPaintFlags(clearlog.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
restart = (TextView) view.findViewById(R.id.nsclientinternal_restart);
restart.setOnClickListener(this);
restart.setPaintFlags(restart.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
delivernow = (TextView) view.findViewById(R.id.nsclientinternal_delivernow);
delivernow.setOnClickListener(this);
delivernow.setPaintFlags(delivernow.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
clearqueue = (TextView) view.findViewById(R.id.nsclientinternal_clearqueue);
clearqueue.setOnClickListener(this);
clearqueue.setPaintFlags(clearqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
showqueue = (TextView) view.findViewById(R.id.nsclientinternal_showqueue);
showqueue.setOnClickListener(this);
showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
clearlog = (TextView) view.findViewById(R.id.nsclientinternal_clearlog);
clearlog.setOnClickListener(this);
clearlog.setPaintFlags(clearlog.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
restart = (TextView) view.findViewById(R.id.nsclientinternal_restart);
restart.setOnClickListener(this);
restart.setPaintFlags(restart.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
delivernow = (TextView) view.findViewById(R.id.nsclientinternal_delivernow);
delivernow.setOnClickListener(this);
delivernow.setPaintFlags(delivernow.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
clearqueue = (TextView) view.findViewById(R.id.nsclientinternal_clearqueue);
clearqueue.setOnClickListener(this);
clearqueue.setPaintFlags(clearqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
showqueue = (TextView) view.findViewById(R.id.nsclientinternal_showqueue);
showqueue.setOnClickListener(this);
showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
updateGUI();
return view;
} catch (Exception e) {
FabricPrivacy.logException(e);
}
return view;
}
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
public void onClick(View view) {
switch (view.getId()) {
case R.id.nsclientinternal_restart:
MainApp.bus().post(new EventNSClientRestart());
RxBus.INSTANCE.send(new EventNSClientRestart());
FabricPrivacy.getInstance().logCustom("NSClientRestart");
break;
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() {
public void onClick(DialogInterface dialog, int id) {
UploadQueue.clearQueue();
updateGUI();
updateGui();
FabricPrivacy.getInstance().logCustom("NSClientClearQueue");
}
});
@ -116,7 +129,7 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
builder.show();
break;
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;
}
}
@ -126,38 +139,28 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
switch (buttonView.getId()) {
case R.id.nsclientinternal_paused:
NSClientPlugin.getPlugin().pause(isChecked);
updateGUI();
updateGui();
FabricPrivacy.getInstance().logCustom("NSClientPause");
break;
case R.id.nsclientinternal_autoscroll:
SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
NSClientPlugin.getPlugin().autoscroll = isChecked;
updateGUI();
updateGui();
break;
}
}
@Subscribe
public void onStatusEvent(final EventNSClientUpdateGUI ev) {
updateGUI();
}
@Override
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
NSClientPlugin.getPlugin().updateLog();
pausedCheckbox.setChecked(SP.getBoolean(R.string.key_nsclientinternal_paused, false));
logTextView.setText(NSClientPlugin.getPlugin().textLog);
if (NSClientPlugin.getPlugin().autoscroll) {
logScrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
urlTextView.setText(NSClientPlugin.getPlugin().url());
Spanned queuetext = Html.fromHtml(MainApp.gs(R.string.queue) + " <b>" + UploadQueue.size() + "</b>");
queueTextView.setText(queuetext);
statusTextView.setText(NSClientPlugin.getPlugin().status);
});
protected void updateGui() {
NSClientPlugin.getPlugin().updateLog();
pausedCheckbox.setChecked(SP.getBoolean(R.string.key_nsclientinternal_paused, false));
logTextView.setText(NSClientPlugin.getPlugin().textLog);
if (NSClientPlugin.getPlugin().autoscroll) {
logScrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
urlTextView.setText(NSClientPlugin.getPlugin().url());
Spanned queuetext = Html.fromHtml(MainApp.gs(R.string.queue) + " <b>" + UploadQueue.size() + "</b>");
queueTextView.setText(queuetext);
statusTextView.setText(NSClientPlugin.getPlugin().status);
}
}

View file

@ -113,7 +113,7 @@ public class NSClientPlugin extends PluginBase {
.observeOn(Schedulers.io())
.subscribe(event -> {
status = event.getStatus();
MainApp.bus().post(new EventNSClientUpdateGUI());
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
}, FabricPrivacy::logException)
);
disposable.add(RxBus.INSTANCE
@ -136,6 +136,15 @@ public class NSClientPlugin extends PluginBase {
}
}, 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
@ -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() {
handler.post(() -> {
synchronized (listLog) {
listLog.clear();
}
MainApp.bus().post(new EventNSClientUpdateGUI());
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
});
}
@ -196,7 +198,7 @@ public class NSClientPlugin extends PluginBase {
listLog.remove(0);
}
}
MainApp.bus().post(new EventNSClientUpdateGUI());
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
});
}

View file

@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
import io.socket.client.Ack;
@ -44,7 +45,7 @@ public class NSAddAck extends Event implements Ack {
if (response.has("result")) {
_id = null;
if (response.getString("result").contains("Not")) {
MainApp.bus().post(new EventNSClientRestart());
RxBus.INSTANCE.send(new EventNSClientRestart());
return;
}
if (L.isEnabled(L.NSCLIENT))

View file

@ -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;
}
}

View file

@ -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
}
}

View file

@ -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 {
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.general.nsclient.events
import info.nightscout.androidaps.events.Event
class EventNSClientRestart : Event()

View file

@ -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 {
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.general.nsclient.events
import info.nightscout.androidaps.events.EventUpdateGui
class EventNSClientUpdateGUI : EventUpdateGui()

View file

@ -167,6 +167,14 @@ public class NSClientService extends Service {
stopSelf();
}, FabricPrivacy::logException)
);
disposable.add(RxBus.INSTANCE
.toObservable(EventNSClientRestart.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
latestDateInReceivedData = 0;
restart();
}, FabricPrivacy::logException)
);
}
@Override
@ -202,12 +210,6 @@ public class NSClientService extends Service {
MainApp.bus().register(this);
}
@Subscribe
public void onStatusEvent(final EventNSClientRestart ev) {
latestDateInReceivedData = 0;
restart();
}
public void initialize() {
dataCounter = 0;
@ -218,13 +220,13 @@ public class NSClientService extends Service {
RxBus.INSTANCE.send(new EventNSClientStatus("Initializing"));
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"));
} 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"));
} else if (!nsEnabled) {
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "disabled"));
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "disabled"));
RxBus.INSTANCE.send(new EventNSClientStatus("Disabled"));
} else if (!nsURL.equals("")) {
try {
@ -236,7 +238,7 @@ public class NSClientService extends Service {
mSocket.on(Socket.EVENT_CONNECT, onConnect);
mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
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.on("dataUpdate", onDataUpdate);
mSocket.on("announcement", onAnnouncement);
@ -244,11 +246,11 @@ public class NSClientService extends Service {
mSocket.on("urgent_alarm", onUrgentAlarm);
mSocket.on("clear_alarm", onClearAlarm);
} 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"));
}
} 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"));
}
}
@ -258,7 +260,7 @@ public class NSClientService extends Service {
public void call(Object... args) {
connectCounter++;
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)
sendAuthMessage(new NSAuthAck());
watchdog();
@ -275,16 +277,16 @@ public class NSClientService extends Service {
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) {
Notification n = new Notification(Notification.NSMALFUNCTION, MainApp.gs(R.string.nsmalfunction), Notification.URGENT);
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);
MainApp.bus().post(new EventNSClientUpdateGUI());
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
new Thread(() -> {
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);
}).start();
}
@ -296,7 +298,7 @@ public class NSClientService extends Service {
public void call(Object... args) {
if (L.isEnabled(L.NSCLIENT))
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("clear_alarm");
MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "destroy"));
RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "destroy"));
isConnected = false;
hasWriteAuth = false;
mSocket.disconnect();
@ -332,7 +334,7 @@ public class NSClientService extends Service {
log.error("Unhandled exception", e);
return;
}
MainApp.bus().post(new EventNSClientNewLog("AUTH", "requesting auth"));
RxBus.INSTANCE.send(new EventNSClientNewLog("AUTH", "requesting auth"));
if (mSocket != null)
mSocket.emit("authorize", authMessage, ack);
}
@ -347,12 +349,12 @@ public class NSClientService extends Service {
isConnected = true;
hasWriteAuth = ack.write && ack.write_treatment;
RxBus.INSTANCE.send(new EventNSClientStatus(connectionStatus));
MainApp.bus().post(new EventNSClientNewLog("AUTH", connectionStatus));
RxBus.INSTANCE.send(new EventNSClientNewLog("AUTH", connectionStatus));
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) {
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Write treatment permission not granted !!!!"));
RxBus.INSTANCE.send(new EventNSClientNewLog("ERROR", "Write treatment permission not granted !!!!"));
}
if (!hasWriteAuth) {
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() {
@Override
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
resend("Ping received");
}
@ -401,7 +403,7 @@ public class NSClientService extends Service {
return;
}
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) {
FabricPrivacy.logException(e);
log.error("Unhandled exception", e);
@ -428,7 +430,7 @@ public class NSClientService extends Service {
*/
@Override
public void call(final Object... args) {
MainApp.bus().post(new EventNSClientNewLog("ALARM", "received"));
RxBus.INSTANCE.send(new EventNSClientNewLog("ALARM", "received"));
JSONObject data;
try {
data = (JSONObject) args[0];
@ -467,7 +469,7 @@ public class NSClientService extends Service {
log.error("Unhandled exception", e);
return;
}
MainApp.bus().post(new EventNSClientNewLog("URGENTALARM", "received"));
RxBus.INSTANCE.send(new EventNSClientNewLog("URGENTALARM", "received"));
BroadcastUrgentAlarm.handleUrgentAlarm(data, getApplicationContext());
if (L.isEnabled(L.NSCLIENT))
log.debug(data.toString());
@ -493,7 +495,7 @@ public class NSClientService extends Service {
log.error("Unhandled exception", e);
return;
}
MainApp.bus().post(new EventNSClientNewLog("CLEARALARM", "received"));
RxBus.INSTANCE.send(new EventNSClientNewLog("CLEARALARM", "received"));
BroadcastClearAlarm.handleClearAlarm(data, getApplicationContext());
if (L.isEnabled(L.NSCLIENT))
log.debug(data.toString());
@ -518,7 +520,7 @@ public class NSClientService extends Service {
// delta means only increment/changes are comming
boolean isDelta = data.has("delta");
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")) {
JSONArray profiles = data.getJSONArray("profiles");
@ -526,7 +528,7 @@ public class NSClientService extends Service {
JSONObject profile = (JSONObject) profiles.get(profiles.length() - 1);
profileStore = new ProfileStore(profile);
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.getInt("versionNum") < Config.SUPPORTEDNSVERSION) {
MainApp.bus().post(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
RxBus.INSTANCE.send(new EventNSClientNewLog("ERROR", "Unsupported Nightscout version !!!!"));
}
} else {
nightscoutVersionName = nsSettingsStatus.getVersion();
@ -561,13 +563,13 @@ public class NSClientService extends Service {
}
*/
} 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 (broadcastProfile && profileStore != null) {
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")) {
@ -576,7 +578,7 @@ public class NSClientService extends Service {
JSONArray updatedTreatments = new JSONArray();
JSONArray addedTreatments = new JSONArray();
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++) {
JSONObject jsonTreatment = treatments.getJSONObject(index);
NSTreatment treatment = new NSTreatment(jsonTreatment);
@ -610,7 +612,7 @@ public class NSClientService extends Service {
if (data.has("devicestatus")) {
JSONArray devicestatuses = data.getJSONArray("devicestatus");
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++) {
JSONObject jsonStatus = devicestatuses.getJSONObject(index);
// remove from upload queue if Ack is failing
@ -625,7 +627,7 @@ public class NSClientService extends Service {
JSONArray updatedFoods = new JSONArray();
JSONArray addedFoods = new JSONArray();
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++) {
JSONObject jsonFood = foods.getJSONObject(index);
@ -655,7 +657,7 @@ public class NSClientService extends Service {
if (data.has("mbgs")) {
JSONArray mbgs = data.getJSONArray("mbgs");
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++) {
JSONObject jsonMbg = mbgs.getJSONObject(index);
// remove from upload queue if Ack is failing
@ -666,7 +668,7 @@ public class NSClientService extends Service {
if (data.has("cals")) {
JSONArray cals = data.getJSONArray("cals");
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
for (Integer index = 0; index < cals.length(); index++) {
// remove from upload queue if Ack is failing
@ -677,10 +679,10 @@ public class NSClientService extends Service {
if (data.has("sgvs")) {
JSONArray sgvs = data.getJSONArray("sgvs");
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++) {
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);
// Handle new sgv here
// remove from upload queue if Ack is failing
@ -699,11 +701,11 @@ public class NSClientService extends Service {
}
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) {
log.error("Unhandled exception", e);
}
//MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
//RxBus.INSTANCE.send(new EventNSClientNewLog("NSCLIENT", "onDataUpdate end");
} finally {
if (wakeLock.isHeld()) wakeLock.release();
}
@ -721,7 +723,7 @@ public class NSClientService extends Service {
message.put("_id", dbr._id);
message.put("data", new JSONObject(dbr.data));
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) {
log.error("Unhandled exception", e);
}
@ -735,7 +737,7 @@ public class NSClientService extends Service {
message.put("_id", dbr._id);
message.put("data", new JSONObject(dbr.data));
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) {
log.error("Unhandled exception", e);
}
@ -748,7 +750,7 @@ public class NSClientService extends Service {
message.put("collection", dbr.collection);
message.put("_id", dbr._id);
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) {
log.error("Unhandled exception", e);
}
@ -758,9 +760,9 @@ public class NSClientService extends Service {
public void onStatusEvent(NSUpdateAck ack) {
if (ack.result) {
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 {
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("data", new JSONObject(dbr.data));
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) {
log.error("Unhandled exception", e);
}
@ -780,16 +782,16 @@ public class NSClientService extends Service {
public void sendAlarmAck(AlarmAck alarmAck) {
if (!isConnected || !hasWriteAuth) return;
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
public void onStatusEvent(NSAddAck ack) {
if (ack.nsClientID != null) {
uploadQueue.removeID(ack.json);
MainApp.bus().post(new EventNSClientNewLog("DBADD", "Acked " + ack.nsClientID));
RxBus.INSTANCE.send(new EventNSClientNewLog("DBADD", "Acked " + ack.nsClientID));
} 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();
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend started: " + reason));
RxBus.INSTANCE.send(new EventNSClientNewLog("QUEUE", "Resend started: " + reason));
CloseableIterator<DbRequest> iterator = null;
int maxcount = 30;
@ -842,7 +844,7 @@ public class NSClientService extends Service {
log.error("Unhandled exception", e);
}
MainApp.bus().post(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason));
RxBus.INSTANCE.send(new EventNSClientNewLog("QUEUE", "Resend ended: " + reason));
}
});
}

View file

@ -942,6 +942,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
.subscribe(event -> updatePumpStatus(event.getStatus()),
FabricPrivacy::logException
));
disposable.add(RxBus.INSTANCE
.toObservable(EventIobCalculationProgress.class)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(event -> {
if (iobCalculationProgressView != null)
iobCalculationProgressView.setText(event.getProgress());
},
FabricPrivacy::logException
));
sRefreshLoop = () -> {
scheduleUpdateGUI("refreshLoop");
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
@ -958,16 +967,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
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() {
Activity activity = getActivity();
if (activity != null)

View file

@ -411,7 +411,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
private void processTREATMENTS(String[] splitted, Sms receivedSms) {
if (splitted[1].toUpperCase().equals("REFRESH")) {
TreatmentsPlugin.getPlugin().getService().resetTreatments();
MainApp.bus().post(new EventNSClientRestart());
RxBus.INSTANCE.send(new EventNSClientRestart());
sendSMS(new Sms(receivedSms.phoneNumber, "TREATMENTS REFRESH SENT"));
receivedSms.processed = true;
} else
@ -420,7 +420,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
private void processNSCLIENT(String[] splitted, Sms receivedSms) {
if (splitted[1].toUpperCase().equals("RESTART")) {
MainApp.bus().post(new EventNSClientRestart());
RxBus.INSTANCE.send(new EventNSClientRestart());
sendSMS(new Sms(receivedSms.phoneNumber, "NSCLIENT RESTART SENT"));
receivedSms.processed = true;
} else

View file

@ -6,8 +6,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.LongSparseArray;
import com.squareup.otto.Subscribe;
import org.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -90,7 +88,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
@Override
protected void onStart() {
super.onStart();
MainApp.bus().register(this);
// EventConfigBuilderChange
disposable.add(RxBus.INSTANCE
.toObservable(EventConfigBuilderChange.class)
@ -194,12 +191,17 @@ public class IobCobCalculatorPlugin extends PluginBase {
runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event);
}, FabricPrivacy::logException)
);
// EventNewHistoryData
disposable.add(RxBus.INSTANCE
.toObservable(EventNewHistoryData.class)
.observeOn(Schedulers.io())
.subscribe(event -> newHistoryData(event), FabricPrivacy::logException)
);
}
@Override
protected void onStop() {
disposable.clear();
MainApp.bus().unregister(this);
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
@Subscribe
public void onEventNewHistoryData(EventNewHistoryData ev) {
public void newHistoryData(EventNewHistoryData ev) {
if (this != getPlugin()) {
if (L.isEnabled(L.AUTOSENS))
log.debug("Ignoring event for non default instance");
@ -774,7 +775,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
stopCalculation("onEventNewHistoryData");
synchronized (dataLock) {
// 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))
log.debug("Invalidating cached data to: " + DateUtil.dateAndTimeFullString(time));
for (int index = iobTable.size() - 1; index >= 0; index--) {

View file

@ -119,7 +119,7 @@ public class IobCobOref1Thread extends Thread {
// start from oldest to be able sub cob
for (int i = bucketed_data.size() - 4; i >= 0; i--) {
String progress = i + (MainApp.isDev() ? " (" + from + ")" : "");
MainApp.bus().post(new EventIobCalculationProgress(progress));
RxBus.INSTANCE.send(new EventIobCalculationProgress(progress));
if (iobCobCalculatorPlugin.stopCalculationTrigger) {
iobCobCalculatorPlugin.stopCalculationTrigger = false;
@ -392,7 +392,7 @@ public class IobCobOref1Thread extends Thread {
} finally {
if (mWakeLock != null)
mWakeLock.release();
MainApp.bus().post(new EventIobCalculationProgress(""));
RxBus.INSTANCE.send(new EventIobCalculationProgress(""));
if (L.isEnabled(L.AUTOSENS)) {
log.debug("AUTOSENSDATA thread ended: " + from);
log.debug("Midnights: " + MidnightTime.log());

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
import android.content.Context;
import android.os.PowerManager;
import android.os.SystemClock;
import androidx.collection.LongSparseArray;
import org.slf4j.Logger;
@ -117,7 +118,7 @@ public class IobCobThread extends Thread {
// start from oldest to be able sub cob
for (int i = bucketed_data.size() - 4; i >= 0; i--) {
String progress = i + (MainApp.isDev() ? " (" + from + ")" : "");
MainApp.bus().post(new EventIobCalculationProgress(progress));
RxBus.INSTANCE.send(new EventIobCalculationProgress(progress));
if (iobCobCalculatorPlugin.stopCalculationTrigger) {
iobCobCalculatorPlugin.stopCalculationTrigger = false;
@ -317,7 +318,7 @@ public class IobCobThread extends Thread {
} finally {
if (mWakeLock != null)
mWakeLock.release();
MainApp.bus().post(new EventIobCalculationProgress(""));
RxBus.INSTANCE.send(new EventIobCalculationProgress(""));
if (L.isEnabled(L.AUTOSENS)) {
log.debug("AUTOSENSDATA thread ended: " + from);
log.debug("Midnights: " + MidnightTime.log());

View file

@ -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;
}
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events
import info.nightscout.androidaps.events.Event
class EventIobCalculationProgress(var progress: String) : Event()

View file

@ -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;
}
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.iob.iobCobCalculator.events
import info.nightscout.androidaps.events.Event
class EventNewHistoryData(var time: Long) : Event()

View file

@ -111,7 +111,7 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface {
if (L.isEnabled(L.PROFILE))
log.debug("Stored profile not found");
// force restart of nsclient to fetch profile
MainApp.bus().post(new EventNSClientRestart());
RxBus.INSTANCE.send(new EventNSClientRestart());
}
}

View file

@ -5,28 +5,33 @@ import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import androidx.annotation.NonNull;
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 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.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.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.events.EventQueueChanged;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
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 activityView;
private TextView batteryView;
@ -58,10 +63,31 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
refreshButton = view.findViewById(R.id.combo_refresh_button);
refreshButton.setOnClickListener(this);
updateGUI();
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) {
Activity activity = getActivity();
if (activity != null) {
@ -84,148 +110,135 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
}
}
@Subscribe
public void onStatusEvent(final EventComboPumpUpdateGUI ignored) {
updateGUI();
}
public void updateGui() {
ComboPlugin plugin = ComboPlugin.getPlugin();
@Subscribe
public void onStatusEvent(final EventQueueChanged ignored) {
updateGUI();
}
// state
stateView.setText(plugin.getStateSummary());
PumpState ps = plugin.getPump().state;
if (ps.insulinState == PumpState.EMPTY || ps.batteryState == PumpState.EMPTY
|| ps.activeAlert != null && ps.activeAlert.errorCode != null) {
stateView.setTextColor(Color.RED);
stateView.setTypeface(null, Typeface.BOLD);
} else if (plugin.getPump().state.suspended
|| ps.activeAlert != null && ps.activeAlert.warningCode != null) {
stateView.setTextColor(Color.YELLOW);
stateView.setTypeface(null, Typeface.BOLD);
} else {
stateView.setTextColor(Color.WHITE);
stateView.setTypeface(null, Typeface.NORMAL);
}
// activity
String activity = plugin.getPump().activity;
if (activity != null) {
activityView.setTextColor(Color.WHITE);
activityView.setTextSize(14);
activityView.setText(activity);
} else if (ConfigBuilderPlugin.getPlugin().getCommandQueue().size() > 0) {
activityView.setTextColor(Color.WHITE);
activityView.setTextSize(14);
activityView.setText("");
} else if (plugin.isInitialized()) {
activityView.setTextColor(Color.WHITE);
activityView.setTextSize(20);
activityView.setText("{fa-bed}");
} else {
activityView.setTextColor(Color.RED);
activityView.setTextSize(14);
activityView.setText(MainApp.gs(R.string.pump_unreachable));
}
public void updateGUI() {
runOnUiThread(() -> {
ComboPlugin plugin = ComboPlugin.getPlugin();
// state
stateView.setText(plugin.getStateSummary());
PumpState ps = plugin.getPump().state;
if (ps.insulinState == PumpState.EMPTY || ps.batteryState == PumpState.EMPTY
|| ps.activeAlert != null && ps.activeAlert.errorCode != null) {
stateView.setTextColor(Color.RED);
stateView.setTypeface(null, Typeface.BOLD);
} else if (plugin.getPump().state.suspended
|| ps.activeAlert != null && ps.activeAlert.warningCode != null) {
stateView.setTextColor(Color.YELLOW);
stateView.setTypeface(null, Typeface.BOLD);
if (plugin.isInitialized()) {
// battery
batteryView.setTextSize(20);
if (ps.batteryState == PumpState.EMPTY) {
batteryView.setText("{fa-battery-empty}");
batteryView.setTextColor(Color.RED);
} else if (ps.batteryState == PumpState.LOW) {
batteryView.setText("{fa-battery-quarter}");
batteryView.setTextColor(Color.YELLOW);
} else {
stateView.setTextColor(Color.WHITE);
stateView.setTypeface(null, Typeface.NORMAL);
batteryView.setText("{fa-battery-full}");
batteryView.setTextColor(Color.WHITE);
}
// activity
String activity = plugin.getPump().activity;
if (activity != null) {
activityView.setTextColor(Color.WHITE);
activityView.setTextSize(14);
activityView.setText(activity);
} else if (ConfigBuilderPlugin.getPlugin().getCommandQueue().size() > 0) {
activityView.setTextColor(Color.WHITE);
activityView.setTextSize(14);
activityView.setText("");
} else if (plugin.isInitialized()){
activityView.setTextColor(Color.WHITE);
activityView.setTextSize(20);
activityView.setText("{fa-bed}");
// reservoir
int reservoirLevel = plugin.getPump().reservoirLevel;
if (reservoirLevel != -1) {
reservoirView.setText(reservoirLevel + " " + MainApp.gs(R.string.insulin_unit_shortname));
} else if (ps.insulinState == PumpState.LOW) {
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_low));
} else if (ps.insulinState == PumpState.EMPTY) {
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_empty));
} else {
activityView.setTextColor(Color.RED);
activityView.setTextSize(14);
activityView.setText(MainApp.gs(R.string.pump_unreachable));
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_normal));
}
if (plugin.isInitialized()) {
// battery
batteryView.setTextSize(20);
if (ps.batteryState == PumpState.EMPTY) {
batteryView.setText("{fa-battery-empty}");
batteryView.setTextColor(Color.RED);
} else if (ps.batteryState == PumpState.LOW) {
batteryView.setText("{fa-battery-quarter}");
batteryView.setTextColor(Color.YELLOW);
} else {
batteryView.setText("{fa-battery-full}");
batteryView.setTextColor(Color.WHITE);
}
// reservoir
int reservoirLevel = plugin.getPump().reservoirLevel;
if (reservoirLevel != -1) {
reservoirView.setText(reservoirLevel + " " + MainApp.gs(R.string.insulin_unit_shortname));
} else if (ps.insulinState == PumpState.LOW) {
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_low));
} else if (ps.insulinState == PumpState.EMPTY) {
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_empty));
} else {
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_normal));
}
if (ps.insulinState == PumpState.UNKNOWN) {
reservoirView.setTextColor(Color.WHITE);
reservoirView.setTypeface(null, Typeface.NORMAL);
} else if (ps.insulinState == PumpState.LOW) {
reservoirView.setTextColor(Color.YELLOW);
reservoirView.setTypeface(null, Typeface.BOLD);
} else if (ps.insulinState == PumpState.EMPTY) {
reservoirView.setTextColor(Color.RED);
reservoirView.setTypeface(null, Typeface.BOLD);
} else {
reservoirView.setTextColor(Color.WHITE);
reservoirView.setTypeface(null, Typeface.NORMAL);
}
// last connection
String minAgo = DateUtil.minAgo(plugin.getPump().lastSuccessfulCmdTime);
long min = (System.currentTimeMillis() - plugin.getPump().lastSuccessfulCmdTime) / 1000 / 60;
if (plugin.getPump().lastSuccessfulCmdTime + 60 * 1000 > System.currentTimeMillis()) {
lastConnectionView.setText(R.string.combo_pump_connected_now);
lastConnectionView.setTextColor(Color.WHITE);
} else if (plugin.getPump().lastSuccessfulCmdTime + 30 * 60 * 1000 < System.currentTimeMillis()) {
lastConnectionView.setText(MainApp.gs(R.string.combo_no_pump_connection, min));
lastConnectionView.setTextColor(Color.RED);
} else {
lastConnectionView.setText(minAgo);
lastConnectionView.setTextColor(Color.WHITE);
}
// last bolus
Bolus bolus = plugin.getPump().lastBolus;
if (bolus != null) {
long agoMsc = System.currentTimeMillis() - bolus.timestamp;
double bolusMinAgo = agoMsc / 60d / 1000d;
String unit = MainApp.gs(R.string.insulin_unit_shortname);
String ago;
if ((agoMsc < 60 * 1000)) {
ago = MainApp.gs(R.string.combo_pump_connected_now);
} else if (bolusMinAgo < 60) {
ago = DateUtil.minAgo(bolus.timestamp);
} else {
ago = DateUtil.hourAgo(bolus.timestamp);
}
lastBolusView.setText(MainApp.gs(R.string.combo_last_bolus, bolus.amount, unit, ago));
} else {
lastBolusView.setText("");
}
// base basal rate
baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));
// TBR
String tbrStr = "";
if (ps.tbrPercent != -1 && ps.tbrPercent != 100) {
long minSinceRead = (System.currentTimeMillis() - plugin.getPump().state.timestamp) / 1000 / 60;
long remaining = ps.tbrRemainingDuration - minSinceRead;
if (remaining >= 0) {
tbrStr = MainApp.gs(R.string.combo_tbr_remaining, ps.tbrPercent, remaining);
}
}
tempBasalText.setText(tbrStr);
// stats
bolusCount.setText(String.valueOf(SP.getLong(ComboPlugin.COMBO_BOLUSES_DELIVERED, 0L)));
tbrCount.setText(String.valueOf(SP.getLong(ComboPlugin.COMBO_TBRS_SET, 0L)));
if (ps.insulinState == PumpState.UNKNOWN) {
reservoirView.setTextColor(Color.WHITE);
reservoirView.setTypeface(null, Typeface.NORMAL);
} else if (ps.insulinState == PumpState.LOW) {
reservoirView.setTextColor(Color.YELLOW);
reservoirView.setTypeface(null, Typeface.BOLD);
} else if (ps.insulinState == PumpState.EMPTY) {
reservoirView.setTextColor(Color.RED);
reservoirView.setTypeface(null, Typeface.BOLD);
} else {
reservoirView.setTextColor(Color.WHITE);
reservoirView.setTypeface(null, Typeface.NORMAL);
}
});
// last connection
String minAgo = DateUtil.minAgo(plugin.getPump().lastSuccessfulCmdTime);
long min = (System.currentTimeMillis() - plugin.getPump().lastSuccessfulCmdTime) / 1000 / 60;
if (plugin.getPump().lastSuccessfulCmdTime + 60 * 1000 > System.currentTimeMillis()) {
lastConnectionView.setText(R.string.combo_pump_connected_now);
lastConnectionView.setTextColor(Color.WHITE);
} else if (plugin.getPump().lastSuccessfulCmdTime + 30 * 60 * 1000 < System.currentTimeMillis()) {
lastConnectionView.setText(MainApp.gs(R.string.combo_no_pump_connection, min));
lastConnectionView.setTextColor(Color.RED);
} else {
lastConnectionView.setText(minAgo);
lastConnectionView.setTextColor(Color.WHITE);
}
// last bolus
Bolus bolus = plugin.getPump().lastBolus;
if (bolus != null) {
long agoMsc = System.currentTimeMillis() - bolus.timestamp;
double bolusMinAgo = agoMsc / 60d / 1000d;
String unit = MainApp.gs(R.string.insulin_unit_shortname);
String ago;
if ((agoMsc < 60 * 1000)) {
ago = MainApp.gs(R.string.combo_pump_connected_now);
} else if (bolusMinAgo < 60) {
ago = DateUtil.minAgo(bolus.timestamp);
} else {
ago = DateUtil.hourAgo(bolus.timestamp);
}
lastBolusView.setText(MainApp.gs(R.string.combo_last_bolus, bolus.amount, unit, ago));
} else {
lastBolusView.setText("");
}
// base basal rate
baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));
// TBR
String tbrStr = "";
if (ps.tbrPercent != -1 && ps.tbrPercent != 100) {
long minSinceRead = (System.currentTimeMillis() - plugin.getPump().state.timestamp) / 1000 / 60;
long remaining = ps.tbrRemainingDuration - minSinceRead;
if (remaining >= 0) {
tbrStr = MainApp.gs(R.string.combo_tbr_remaining, ps.tbrPercent, remaining);
}
}
tempBasalText.setText(tbrStr);
// stats
bolusCount.setText(String.valueOf(SP.getLong(ComboPlugin.COMBO_BOLUSES_DELIVERED, 0L)));
tbrCount.setText(String.valueOf(SP.getLong(ComboPlugin.COMBO_TBRS_SET, 0L)));
}
}
}

View file

@ -390,7 +390,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
// ComboFragment updates state fully only after the pump has initialized,
// 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) {
pump.state = result.state;
}
MainApp.bus().post(new EventComboPumpUpdateGUI());
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
}
@Override
@ -485,7 +485,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
.comment(MainApp.gs(R.string.virtualpump_resultok));
}
} 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) {
try {
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
CommandResult stateResult = runCommand(null, 2, () -> ruffyScripter.readQuickInfo(1));
@ -628,7 +628,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
.carbsDelivered(detailedBolusInfo.carbs);
} finally {
pump.activity = null;
MainApp.bus().post(new EventComboPumpUpdateGUI());
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
RxBus.INSTANCE.send(new EventRefreshOverview("Bolus"));
cancelBolus = false;
}
@ -760,7 +760,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
.source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart);
MainApp.bus().post(new EventComboPumpUpdateGUI());
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
}
incrementTbrCount();
@ -848,7 +848,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
if (!ruffyScripter.isConnected()) {
String originalActivity = pump.activity;
pump.activity = MainApp.gs(R.string.combo_activity_checking_pump_state);
MainApp.bus().post(new EventComboPumpUpdateGUI());
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
CommandResult preCheckError = runOnConnectChecks();
pump.activity = originalActivity;
if (preCheckError != null) {
@ -859,7 +859,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
if (activity != null) {
pump.activity = activity;
MainApp.bus().post(new EventComboPumpUpdateGUI());
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
}
commandResult = commandExecution.execute();
@ -892,7 +892,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
} finally {
if (activity != null) {
pump.activity = null;
MainApp.bus().post(new EventComboPumpUpdateGUI());
RxBus.INSTANCE.send(new EventComboPumpUpdateGUI());
}
}

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.plugins.pump.combo.events;
/**
* Created by mike on 24.05.2017.
*/
public class EventComboPumpUpdateGUI {
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.pump.combo.events
import info.nightscout.androidaps.events.EventUpdateGui
class EventComboPumpUpdateGUI : EventUpdateGui()

View file

@ -8,7 +8,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.squareup.otto.Subscribe
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.TDDStatsActivity
@ -81,7 +80,6 @@ class DanaRFragment : Fragment() {
@Synchronized
override fun onResume() {
super.onResume()
MainApp.bus().register(this)
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
disposable += RxBus
.toObservable(EventDanaRNewStatus::class.java)
@ -95,6 +93,10 @@ class DanaRFragment : Fragment() {
.toObservable(EventTempBasalChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
disposable += RxBus
.toObservable(EventQueueChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
disposable += RxBus
.toObservable(EventPumpStatusChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
@ -118,14 +120,9 @@ class DanaRFragment : Fragment() {
override fun onPause() {
super.onPause()
disposable.clear()
MainApp.bus().unregister(this)
loopHandler.removeCallbacks(refreshLoop)
}
@Subscribe
fun onStatusEvent(s: EventQueueChanged) =
activity?.runOnUiThread { updateGUI() }
// GUI functions
@Synchronized
internal fun updateGUI() {

View file

@ -8,7 +8,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.squareup.otto.Subscribe
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventExtendedBolusChange
@ -104,7 +103,6 @@ class MedtronicFragment : Fragment() {
@Synchronized
override fun onResume() {
super.onResume()
MainApp.bus().register(this)
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
disposable += RxBus
.toObservable(EventRefreshButtonState::class.java)
@ -143,6 +141,10 @@ class MedtronicFragment : Fragment() {
.toObservable(EventPumpStatusChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
disposable += RxBus
.toObservable(EventQueueChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { FabricPrivacy.logException(it) })
updateGUI()
}
@ -151,15 +153,9 @@ class MedtronicFragment : Fragment() {
override fun onPause() {
super.onPause()
disposable.clear()
MainApp.bus().unregister(this)
loopHandler.removeCallbacks(refreshLoop)
}
@Subscribe
fun onStatusEvent(s: EventQueueChanged) {
activity?.runOnUiThread { updateGUI() }
}
@Synchronized
private fun setDeviceStatus() {
val pumpStatus: MedtronicPumpStatus = MedtronicUtil.getPumpStatus()

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.treatments;
import android.content.Intent;
import android.os.IBinder;
import androidx.annotation.Nullable;
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.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import com.squareup.otto.Subscribe;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
@ -35,7 +35,6 @@ import info.nightscout.androidaps.db.ICallback;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.events.EventNsTreatment;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventReloadTreatmentData;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.logging.L;
@ -191,7 +190,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
if (DatabaseHelper.earliestDataChange != null) {
if (L.isEnabled(L.DATATREATMENTS))
log.debug("Firing EventNewHistoryData");
MainApp.bus().post(new EventNewHistoryData(DatabaseHelper.earliestDataChange));
RxBus.INSTANCE.send(new EventNewHistoryData(DatabaseHelper.earliestDataChange));
}
DatabaseHelper.earliestDataChange = null;
callback.setPost(null);
@ -199,7 +198,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
}
// prepare task for execution in 1 sec
// cancel waiting task to prevent sending multiple posts
ScheduledFuture<?> scheduledFuture = callback.getPost();
ScheduledFuture<?> scheduledFuture = callback.getPost();
if (scheduledFuture != null)
scheduledFuture.cancel(false);
Runnable task = new PostRunnable();
@ -256,8 +255,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
createOrUpdate(treatment);
else
createOrUpdateMedtronic(treatment, false);
}
else
} else
log.error("Date is null: " + treatment.toString());
} catch (JSONException e) {
log.error("Unhandled exception", e);
@ -401,7 +399,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
Treatment existingTreatment = getRecord(treatment.pumpId, treatment.date);
if (existingTreatment==null) {
if (existingTreatment == null) {
getDao().create(treatment);
if (L.isEnabled(L.DATATREATMENTS))
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);
} else {
if (existingTreatment.date==treatment.date) {
if (existingTreatment.date == treatment.date) {
// we will do update only, if entry changed
if (!optionalTreatmentCopy(existingTreatment, treatment, fromNightScout)) {
return new UpdateReturn(true, false);
@ -483,15 +481,15 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
int source = Source.NONE;
if (oldTreatment.pumpId==0) {
if (oldTreatment.pumpId == 0) {
if (newTreatment.pumpId > 0) {
oldTreatment.pumpId=newTreatment.pumpId;
oldTreatment.pumpId = newTreatment.pumpId;
source = Source.PUMP;
changed = true;
}
}
if (source==Source.NONE) {
if (source == Source.NONE) {
if (oldTreatment.source == newTreatment.source) {
source = oldTreatment.source;
@ -522,7 +520,6 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
log.debug("treatmentCopy [old={}, new={}]", oldTreatment.toString(), newTreatment.toString());
if (fromNightScout) {
long pumpId_old = oldTreatment.pumpId;
boolean isSMB = (oldTreatment.isSMB || newTreatment.isSMB);
@ -552,7 +549,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
Treatment record = null;
if (pumpId>0) {
if (pumpId > 0) {
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
* if multiple records with the same pump id exist.
@ -693,7 +689,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
return new ArrayList<>();
}
public List<Treatment> getTreatmentDataFromTime(long from, long to, boolean ascending) {
public List<Treatment> getTreatmentDataFromTime(long from, long to, boolean ascending) {
try {
Dao<Treatment, Long> daoTreatments = getDao();
List<Treatment> treatments;

View file

@ -232,7 +232,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?");
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
TreatmentsPlugin.getPlugin().getService().resetTreatments();
MainApp.bus().post(new EventNSClientRestart());
RxBus.INSTANCE.send(new EventNSClientRestart());
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();

View file

@ -180,7 +180,7 @@ public class TreatmentsCareportalFragment extends Fragment implements View.OnCli
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainApp.getDbHelper().resetCareportalEvents();
MainApp.bus().post(new EventNSClientRestart());
RxBus.INSTANCE.send(new EventNSClientRestart());
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);

View file

@ -231,7 +231,7 @@ public class TreatmentsProfileSwitchFragment extends Fragment implements View.On
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainApp.getDbHelper().resetProfileSwitch();
MainApp.bus().post(new EventNSClientRestart());
RxBus.INSTANCE.send(new EventNSClientRestart());
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);

View file

@ -217,7 +217,7 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
MainApp.getDbHelper().resetTempTargets();
MainApp.bus().post(new EventNSClientRestart());
RxBus.INSTANCE.send(new EventNSClientRestart());
}
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);

View file

@ -51,7 +51,7 @@ public class QueueThread extends Thread {
public final void run() {
if (mWakeLock != null)
mWakeLock.acquire(T.mins(10).msecs());
MainApp.bus().post(new EventQueueChanged());
RxBus.INSTANCE.send(new EventQueueChanged());
long lastCommandTime;
long connectionStartTime = lastCommandTime = System.currentTimeMillis();
@ -145,10 +145,10 @@ public class QueueThread extends Thread {
if (queue.performing() != null) {
if (L.isEnabled(L.PUMPQUEUE))
log.debug("performing " + queue.performing().status());
MainApp.bus().post(new EventQueueChanged());
RxBus.INSTANCE.send(new EventQueueChanged());
queue.performing().execute();
queue.resetPerforming();
MainApp.bus().post(new EventQueueChanged());
RxBus.INSTANCE.send(new EventQueueChanged());
lastCommandTime = System.currentTimeMillis();
SystemClock.sleep(100);
continue;