Events to RxBus
This commit is contained in:
parent
1aa8771f4d
commit
837cb0d4a2
|
@ -1,10 +1,8 @@
|
||||||
package info.nightscout.androidaps.activities;
|
package info.nightscout.androidaps.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -18,7 +16,7 @@ import android.widget.TableLayout;
|
||||||
import android.widget.TableRow;
|
import android.widget.TableRow;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -37,7 +35,6 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TDD;
|
import info.nightscout.androidaps.db.TDD;
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
|
@ -86,6 +83,14 @@ public class TDDStatsActivity extends NoSplashActivity {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(event -> statusView.setText(event.getStatus()), FabricPrivacy::logException)
|
.subscribe(event -> statusView.setText(event.getStatus()), FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventDanaRSyncStatus.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> {
|
||||||
|
log.debug("EventDanaRSyncStatus: " + event.getMessage());
|
||||||
|
statusView.setText(event.getMessage());
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -531,19 +536,6 @@ public class TDDStatsActivity extends NoSplashActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventDanaRSyncStatus s) {
|
|
||||||
log.debug("EventDanaRSyncStatus: " + s.message);
|
|
||||||
runOnUiThread(
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
statusView.setText(s.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isOldData(List<TDD> historyList) {
|
public static boolean isOldData(List<TDD> historyList) {
|
||||||
Object activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
Object activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||||
PumpInterface dana = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
PumpInterface dana = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
||||||
|
|
|
@ -15,8 +15,6 @@ import androidx.cardview.widget.CardView;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -86,18 +84,25 @@ public class DanaRHistoryActivity extends NoSplashActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
MainApp.bus().register(this);
|
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
.toObservable(EventPumpStatusChanged.class)
|
.toObservable(EventPumpStatusChanged.class)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(event -> statusView.setText(event.getStatus()), FabricPrivacy::logException)
|
.subscribe(event -> statusView.setText(event.getStatus()), FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventDanaRSyncStatus.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> {
|
||||||
|
if (L.isEnabled(L.PUMP))
|
||||||
|
log.debug("EventDanaRSyncStatus: " + event.getMessage());
|
||||||
|
statusView.setText(event.getMessage());
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
MainApp.bus().unregister(this);
|
|
||||||
disposable.clear();
|
disposable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,13 +332,4 @@ public class DanaRHistoryActivity extends NoSplashActivity {
|
||||||
historyList = new ArrayList<>();
|
historyList = new ArrayList<>();
|
||||||
runOnUiThread(() -> recyclerView.swapAdapter(new RecyclerViewAdapter(historyList), false));
|
runOnUiThread(() -> recyclerView.swapAdapter(new RecyclerViewAdapter(historyList), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventDanaRSyncStatus s) {
|
|
||||||
if (L.isEnabled(L.PUMP))
|
|
||||||
log.debug("EventDanaRSyncStatus: " + s.message);
|
|
||||||
runOnUiThread(
|
|
||||||
() -> statusView.setText(s.message));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
|
import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
|
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
|
||||||
|
@ -28,13 +29,13 @@ public class DanaRNSHistorySync {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||||
private List<DanaRHistoryRecord> historyRecords;
|
private List<DanaRHistoryRecord> historyRecords;
|
||||||
|
|
||||||
public final static int SYNC_BOLUS = 0b00000001;
|
private final static int SYNC_BOLUS = 0b00000001;
|
||||||
public final static int SYNC_ERROR = 0b00000010;
|
private final static int SYNC_ERROR = 0b00000010;
|
||||||
public final static int SYNC_REFILL = 0b00000100;
|
private final static int SYNC_REFILL = 0b00000100;
|
||||||
public final static int SYNC_GLUCOSE = 0b00001000;
|
private final static int SYNC_GLUCOSE = 0b00001000;
|
||||||
public final static int SYNC_CARBO = 0b00010000;
|
private final static int SYNC_CARBO = 0b00010000;
|
||||||
public final static int SYNC_ALARM = 0b00100000;
|
private final static int SYNC_ALARM = 0b00100000;
|
||||||
public final static int SYNC_BASALHOURS = 0b01000000;
|
private final static int SYNC_BASALHOURS = 0b01000000;
|
||||||
public final static int SYNC_ALL = 0b11111111;
|
public final static int SYNC_ALL = 0b11111111;
|
||||||
|
|
||||||
public final static String DANARSIGNATURE = "DANARMESSAGE";
|
public final static String DANARSIGNATURE = "DANARMESSAGE";
|
||||||
|
@ -52,13 +53,13 @@ public class DanaRNSHistorySync {
|
||||||
long uploaded = 0;
|
long uploaded = 0;
|
||||||
if (L.isEnabled(L.PUMP))
|
if (L.isEnabled(L.PUMP))
|
||||||
log.debug("Database contains " + records + " records");
|
log.debug("Database contains " + records + " records");
|
||||||
EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
|
EventDanaRSyncStatus ev = new EventDanaRSyncStatus("");
|
||||||
for (DanaRHistoryRecord record : historyRecords) {
|
for (DanaRHistoryRecord record : historyRecords) {
|
||||||
processing++;
|
processing++;
|
||||||
if (record._id != null) continue;
|
if (record._id != null) continue;
|
||||||
//log.debug(record.bytes);
|
//log.debug(record.bytes);
|
||||||
JSONObject nsrec = new JSONObject();
|
JSONObject nsrec = new JSONObject();
|
||||||
ev.message = MainApp.gs(R.string.uploading) + " " + processing + "/" + records + " "; // TODO: translations
|
ev.setMessage(MainApp.gs(R.string.uploading) + " " + processing + "/" + records + " "); // TODO: translations
|
||||||
switch (record.recordCode) {
|
switch (record.recordCode) {
|
||||||
case RecordTypes.RECORD_TYPE_BOLUS:
|
case RecordTypes.RECORD_TYPE_BOLUS:
|
||||||
if ((what & SYNC_BOLUS) == 0) break;
|
if ((what & SYNC_BOLUS) == 0) break;
|
||||||
|
@ -73,7 +74,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_sbolus);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_sbolus));
|
||||||
break;
|
break;
|
||||||
case "E":
|
case "E":
|
||||||
if (record.recordDuration > 0) {
|
if (record.recordDuration > 0) {
|
||||||
|
@ -92,7 +93,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_ebolus);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_ebolus));
|
||||||
} else {
|
} else {
|
||||||
if (L.isEnabled(L.PUMP))
|
if (L.isEnabled(L.PUMP))
|
||||||
log.debug("NOT Syncing extended bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate) + " zero duration");
|
log.debug("NOT Syncing extended bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate) + " zero duration");
|
||||||
|
@ -110,7 +111,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_dsbolus);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_dsbolus));
|
||||||
break;
|
break;
|
||||||
case "DE":
|
case "DE":
|
||||||
if (L.isEnabled(L.PUMP))
|
if (L.isEnabled(L.PUMP))
|
||||||
|
@ -127,7 +128,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_debolus);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_debolus));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.error("Unknown bolus record");
|
log.error("Unknown bolus record");
|
||||||
|
@ -145,7 +146,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_error);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_error));
|
||||||
break;
|
break;
|
||||||
case RecordTypes.RECORD_TYPE_REFILL:
|
case RecordTypes.RECORD_TYPE_REFILL:
|
||||||
if ((what & SYNC_REFILL) == 0) break;
|
if ((what & SYNC_REFILL) == 0) break;
|
||||||
|
@ -158,7 +159,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_refill);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_refill));
|
||||||
break;
|
break;
|
||||||
case RecordTypes.RECORD_TYPE_BASALHOUR:
|
case RecordTypes.RECORD_TYPE_BASALHOUR:
|
||||||
if ((what & SYNC_BASALHOURS) == 0) break;
|
if ((what & SYNC_BASALHOURS) == 0) break;
|
||||||
|
@ -172,7 +173,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_basalhour);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_basalhour));
|
||||||
break;
|
break;
|
||||||
case RecordTypes.RECORD_TYPE_TB:
|
case RecordTypes.RECORD_TYPE_TB:
|
||||||
//log.debug("Ignoring TB record " + record.bytes + " " + DateUtil.toISOString(record.recordDate));
|
//log.debug("Ignoring TB record " + record.bytes + " " + DateUtil.toISOString(record.recordDate));
|
||||||
|
@ -189,7 +190,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_glucose);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_glucose));
|
||||||
break;
|
break;
|
||||||
case RecordTypes.RECORD_TYPE_CARBO:
|
case RecordTypes.RECORD_TYPE_CARBO:
|
||||||
if ((what & SYNC_CARBO) == 0) break;
|
if ((what & SYNC_CARBO) == 0) break;
|
||||||
|
@ -202,7 +203,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_carbohydrate);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_carbohydrate));
|
||||||
break;
|
break;
|
||||||
case RecordTypes.RECORD_TYPE_ALARM:
|
case RecordTypes.RECORD_TYPE_ALARM:
|
||||||
if ((what & SYNC_ALARM) == 0) break;
|
if ((what & SYNC_ALARM) == 0) break;
|
||||||
|
@ -215,7 +216,7 @@ public class DanaRNSHistorySync {
|
||||||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||||
uploaded++;
|
uploaded++;
|
||||||
ev.message += MainApp.gs(R.string.danar_alarm);
|
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_alarm));
|
||||||
break;
|
break;
|
||||||
case RecordTypes.RECORD_TYPE_SUSPEND: // TODO: this too
|
case RecordTypes.RECORD_TYPE_SUSPEND: // TODO: this too
|
||||||
case RecordTypes.RECORD_TYPE_DAILY:
|
case RecordTypes.RECORD_TYPE_DAILY:
|
||||||
|
@ -226,10 +227,10 @@ public class DanaRNSHistorySync {
|
||||||
log.error("Unknown record type");
|
log.error("Unknown record type");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
MainApp.bus().post(ev);
|
RxBus.INSTANCE.send(ev);
|
||||||
}
|
}
|
||||||
ev.message = String.format(MainApp.gs(R.string.danar_totaluploaded), uploaded);
|
ev.setMessage(String.format(MainApp.gs(R.string.danar_totaluploaded), uploaded));
|
||||||
MainApp.bus().post(ev);
|
RxBus.INSTANCE.send(ev);
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
|
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
|
||||||
|
@ -33,8 +34,6 @@ public class MsgHistoryAll extends MessageBase {
|
||||||
byte paramByte8 = (byte) intFromBuff(bytes, 7, 1);
|
byte paramByte8 = (byte) intFromBuff(bytes, 7, 1);
|
||||||
double value = (double) intFromBuff(bytes, 8, 2);
|
double value = (double) intFromBuff(bytes, 8, 2);
|
||||||
|
|
||||||
EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
|
|
||||||
|
|
||||||
DanaRHistoryRecord danaRHistoryRecord = new DanaRHistoryRecord();
|
DanaRHistoryRecord danaRHistoryRecord = new DanaRHistoryRecord();
|
||||||
|
|
||||||
danaRHistoryRecord.recordCode = recordCode;
|
danaRHistoryRecord.recordCode = recordCode;
|
||||||
|
@ -145,11 +144,6 @@ public class MsgHistoryAll extends MessageBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord);
|
MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord);
|
||||||
|
RxBus.INSTANCE.send(new EventDanaRSyncStatus(DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType));
|
||||||
ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate);
|
|
||||||
ev.message += " " + messageType;
|
|
||||||
MainApp.bus().post(ev);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaR.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 20.07.2016.
|
|
||||||
*/
|
|
||||||
public class EventDanaRSyncStatus extends Event {
|
|
||||||
public String message;
|
|
||||||
|
|
||||||
public EventDanaRSyncStatus() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaR.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventDanaRSyncStatus(var message: String) : Event()
|
|
@ -9,8 +9,6 @@ import android.os.IBinder;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -40,7 +38,6 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
||||||
|
@ -48,6 +45,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNo
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment;
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||||
|
@ -118,7 +116,6 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
Intent intent = new Intent(context, DanaRSService.class);
|
Intent intent = new Intent(context, DanaRSService.class);
|
||||||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
MainApp.bus().register(this);
|
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
.toObservable(EventAppExit.class)
|
.toObservable(EventAppExit.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
|
@ -126,7 +123,14 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
onStatusEvent(new EventDanaRSDeviceChange()); // load device name
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventDanaRSDeviceChange.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> {
|
||||||
|
loadAddress();
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
loadAddress(); // load device name
|
||||||
super.onStart();
|
super.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +139,6 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
context.unbindService(mConnection);
|
context.unbindService(mConnection);
|
||||||
|
|
||||||
MainApp.bus().unregister(this);
|
|
||||||
disposable.clear();
|
disposable.clear();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
@ -161,8 +164,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Subscribe
|
private void loadAddress() {
|
||||||
public void onStatusEvent(final EventDanaRSDeviceChange e) {
|
|
||||||
mDeviceAddress = SP.getString(R.string.key_danars_address, "");
|
mDeviceAddress = SP.getString(R.string.key_danars_address, "");
|
||||||
mDeviceName = SP.getString(R.string.key_danars_name, "");
|
mDeviceName = SP.getString(R.string.key_danars_name, "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ import java.util.ArrayList;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange;
|
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ public class BLEScanActivity extends NoSplashAppCompatActivity {
|
||||||
SP.putString(R.string.key_danars_address, item.device.getAddress());
|
SP.putString(R.string.key_danars_address, item.device.getAddress());
|
||||||
SP.putString(R.string.key_danars_name, mName.getText().toString());
|
SP.putString(R.string.key_danars_name, mName.getText().toString());
|
||||||
item.device.createBond();
|
item.device.createBond();
|
||||||
MainApp.bus().post(new EventDanaRSDeviceChange());
|
RxBus.INSTANCE.send(new EventDanaRSDeviceChange());
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -13,14 +12,19 @@ import android.widget.Button;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
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.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess;
|
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess;
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
|
|
||||||
public class PairingProgressDialog extends DialogFragment implements View.OnClickListener {
|
public class PairingProgressDialog extends DialogFragment implements View.OnClickListener {
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
TextView statusView;
|
TextView statusView;
|
||||||
ProgressBar progressBar;
|
ProgressBar progressBar;
|
||||||
|
@ -101,7 +105,11 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
MainApp.bus().register(this);
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventDanaRSPairingSuccess.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> pairingEnded = true, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
running = true;
|
running = true;
|
||||||
if (pairingEnded) dismiss();
|
if (pairingEnded) dismiss();
|
||||||
}
|
}
|
||||||
|
@ -117,15 +125,10 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
MainApp.bus().unregister(this);
|
disposable.clear();
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventDanaRSPairingSuccess ev) {
|
|
||||||
pairingEnded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHelperActivity(PairingHelperActivity activity) {
|
public void setHelperActivity(PairingHelperActivity activity) {
|
||||||
this.helperActivity = activity;
|
this.helperActivity = activity;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.GregorianCalendar;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
|
import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
|
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRSyncStatus;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
@ -109,7 +110,6 @@ public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
|
||||||
log.debug("History packet: " + recordCode + " Date: " + datetimewihtsec.toLocaleString() + " Code: " + historyCode + " Value: " + value);
|
log.debug("History packet: " + recordCode + " Date: " + datetimewihtsec.toLocaleString() + " Code: " + historyCode + " Value: " + value);
|
||||||
|
|
||||||
|
|
||||||
EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
|
|
||||||
DanaRHistoryRecord danaRHistoryRecord = new DanaRHistoryRecord();
|
DanaRHistoryRecord danaRHistoryRecord = new DanaRHistoryRecord();
|
||||||
|
|
||||||
danaRHistoryRecord.setBytes(data);
|
danaRHistoryRecord.setBytes(data);
|
||||||
|
@ -224,9 +224,7 @@ public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
|
||||||
|
|
||||||
MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord);
|
MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord);
|
||||||
|
|
||||||
ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate);
|
RxBus.INSTANCE.send(new EventDanaRSyncStatus(DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType));
|
||||||
ev.message += " " + messageType;
|
|
||||||
MainApp.bus().post(ev);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaRS.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 05.09.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventDanaRSDeviceChange extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaRS.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventDanaRSDeviceChange : Event()
|
|
@ -1,16 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaRS.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 01.09.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventDanaRSPacket extends Event{
|
|
||||||
public EventDanaRSPacket(DanaRS_Packet data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DanaRS_Packet data;
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaRS.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 01.09.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventDanaRSPairingSuccess extends Event{
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaRS.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventDanaRSPairingSuccess : Event()
|
|
@ -35,7 +35,6 @@ import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity;
|
import info.nightscout.androidaps.plugins.pump.danaRS.activities.PairingHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable;
|
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTable;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet;
|
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPacket;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess;
|
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
|
@ -496,7 +495,7 @@ public class BLEComm {
|
||||||
if (L.isEnabled(L.PUMPBTCOMM))
|
if (L.isEnabled(L.PUMPBTCOMM))
|
||||||
log.debug("<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(inputBuffer));
|
log.debug("<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(inputBuffer));
|
||||||
// Paring is successfull, sending time info
|
// Paring is successfull, sending time info
|
||||||
MainApp.bus().post(new EventDanaRSPairingSuccess());
|
RxBus.INSTANCE.send(new EventDanaRSPairingSuccess());
|
||||||
SendTimeInfo();
|
SendTimeInfo();
|
||||||
byte[] pairingKey = {inputBuffer[2], inputBuffer[3]};
|
byte[] pairingKey = {inputBuffer[2], inputBuffer[3]};
|
||||||
// store pairing key to preferences
|
// store pairing key to preferences
|
||||||
|
@ -546,7 +545,6 @@ public class BLEComm {
|
||||||
// notify to sendMessage
|
// notify to sendMessage
|
||||||
message.notify();
|
message.notify();
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventDanaRSPacket(message));
|
|
||||||
} else {
|
} else {
|
||||||
log.error("Unknown message received " + DanaRS_Packet.toHexString(inputBuffer));
|
log.error("Unknown message received " + DanaRS_Packet.toHexString(inputBuffer));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,13 @@ package info.nightscout.androidaps.plugins.pump.virtual;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
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.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -19,15 +19,18 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui;
|
import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
|
|
||||||
public class VirtualPumpFragment extends SubscriberFragment {
|
public class VirtualPumpFragment extends Fragment {
|
||||||
private static Logger log = LoggerFactory.getLogger(VirtualPumpFragment.class);
|
private static Logger log = LoggerFactory.getLogger(VirtualPumpFragment.class);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
TextView basaBasalRateView;
|
TextView basaBasalRateView;
|
||||||
TextView tempBasalView;
|
TextView tempBasalView;
|
||||||
|
@ -45,12 +48,11 @@ public class VirtualPumpFragment extends SubscriberFragment {
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (sRefreshLoop == null) {
|
if (sRefreshLoop == null) {
|
||||||
sRefreshLoop = new Runnable() {
|
sRefreshLoop = () -> {
|
||||||
@Override
|
Activity activity = getActivity();
|
||||||
public void run() {
|
if (activity != null)
|
||||||
updateGUI();
|
activity.runOnUiThread(this::updateGui);
|
||||||
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +61,6 @@ public class VirtualPumpFragment extends SubscriberFragment {
|
||||||
@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.virtualpump_fragment, container, false);
|
View view = inflater.inflate(R.layout.virtualpump_fragment, container, false);
|
||||||
basaBasalRateView = (TextView) view.findViewById(R.id.virtualpump_basabasalrate);
|
basaBasalRateView = (TextView) view.findViewById(R.id.virtualpump_basabasalrate);
|
||||||
tempBasalView = (TextView) view.findViewById(R.id.virtualpump_tempbasal);
|
tempBasalView = (TextView) view.findViewById(R.id.virtualpump_tempbasal);
|
||||||
|
@ -70,25 +71,26 @@ public class VirtualPumpFragment extends SubscriberFragment {
|
||||||
pumpSettingsView = (TextView) view.findViewById(R.id.virtualpump_type_def);
|
pumpSettingsView = (TextView) view.findViewById(R.id.virtualpump_type_def);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
} catch (Exception e) {
|
|
||||||
FabricPrivacy.logException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventVirtualPumpUpdateGui ev) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateGUI() {
|
public synchronized void onResume() {
|
||||||
Activity activity = getActivity();
|
super.onResume();
|
||||||
if (activity != null && basaBasalRateView != null)
|
disposable.add(RxBus.INSTANCE
|
||||||
activity.runOnUiThread(new Runnable() {
|
.toObservable(EventVirtualPumpUpdateGui.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
updateGui();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public synchronized void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
disposable.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateGui() {
|
||||||
VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getPlugin();
|
VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getPlugin();
|
||||||
basaBasalRateView.setText(virtualPump.getBaseBasalRate() + "U");
|
basaBasalRateView.setText(virtualPump.getBaseBasalRate() + "U");
|
||||||
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
||||||
|
@ -116,10 +118,5 @@ public class VirtualPumpFragment extends SubscriberFragment {
|
||||||
|
|
||||||
|
|
||||||
pumpSettingsView.setText(pumpType.getFullDescription(template, pumpType.hasExtendedBasals()));
|
pumpSettingsView.setText(pumpType.getFullDescription(template, pumpType.hasExtendedBasals()));
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,7 +285,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
SystemClock.sleep(1000);
|
SystemClock.sleep(1000);
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
if (L.isEnabled(L.PUMPCOMM))
|
||||||
log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);
|
log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result);
|
||||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||||
lastDataTime = System.currentTimeMillis();
|
lastDataTime = System.currentTimeMillis();
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
||||||
return result;
|
return result;
|
||||||
|
@ -313,7 +313,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
|
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
if (L.isEnabled(L.PUMPCOMM))
|
||||||
log.debug("Setting temp basal absolute: " + result);
|
log.debug("Setting temp basal absolute: " + result);
|
||||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||||
lastDataTime = System.currentTimeMillis();
|
lastDataTime = System.currentTimeMillis();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
|
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
if (L.isEnabled(L.PUMPCOMM))
|
||||||
log.debug("Settings temp basal percent: " + result);
|
log.debug("Settings temp basal percent: " + result);
|
||||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||||
lastDataTime = System.currentTimeMillis();
|
lastDataTime = System.currentTimeMillis();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
|
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
if (L.isEnabled(L.PUMPCOMM))
|
||||||
log.debug("Setting extended bolus: " + result);
|
log.debug("Setting extended bolus: " + result);
|
||||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||||
lastDataTime = System.currentTimeMillis();
|
lastDataTime = System.currentTimeMillis();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
//tempBasal = null;
|
//tempBasal = null;
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
if (L.isEnabled(L.PUMPCOMM))
|
||||||
log.debug("Canceling temp basal: " + result);
|
log.debug("Canceling temp basal: " + result);
|
||||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||||
}
|
}
|
||||||
lastDataTime = System.currentTimeMillis();
|
lastDataTime = System.currentTimeMillis();
|
||||||
return result;
|
return result;
|
||||||
|
@ -399,7 +399,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||||
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
if (L.isEnabled(L.PUMPCOMM))
|
||||||
log.debug("Canceling extended bolus: " + result);
|
log.debug("Canceling extended bolus: " + result);
|
||||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||||
lastDataTime = System.currentTimeMillis();
|
lastDataTime = System.currentTimeMillis();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.virtual.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.EventUpdateGui;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 05.08.2016.
|
|
||||||
*/
|
|
||||||
public class EventVirtualPumpUpdateGui extends EventUpdateGui {
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.virtual.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.EventUpdateGui
|
||||||
|
|
||||||
|
class EventVirtualPumpUpdateGui : EventUpdateGui()
|
Loading…
Reference in a new issue