Events to RxBus
This commit is contained in:
parent
1aa8771f4d
commit
837cb0d4a2
|
@ -1,10 +1,8 @@
|
|||
package info.nightscout.androidaps.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -18,7 +16,7 @@ import android.widget.TableLayout;
|
|||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -37,7 +35,6 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.TDD;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
|
@ -86,6 +83,14 @@ public class TDDStatsActivity extends NoSplashActivity {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.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
|
||||
|
@ -251,7 +256,7 @@ public class TDDStatsActivity extends NoSplashActivity {
|
|||
statsMessage.setText(MainApp.gs(R.string.danar_stats_warning_Message));
|
||||
}
|
||||
});
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().loadTDDs( new Callback() {
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().loadTDDs(new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadDataFromDB();
|
||||
|
@ -411,7 +416,7 @@ public class TDDStatsActivity extends NoSplashActivity {
|
|||
|
||||
//cumulative TDDs
|
||||
for (TDD record : historyList) {
|
||||
if(!historyList.isEmpty() && df.format(new Date(record.date)).equals(df.format(new Date()))) {
|
||||
if (!historyList.isEmpty() && df.format(new Date(record.date)).equals(df.format(new Date()))) {
|
||||
//Today should not be included
|
||||
continue;
|
||||
}
|
||||
|
@ -460,7 +465,7 @@ public class TDDStatsActivity extends NoSplashActivity {
|
|||
tl.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
if(!historyList.isEmpty() && df.format(new Date(historyList.get(0).date)).equals(df.format(new Date()))) {
|
||||
if (!historyList.isEmpty() && df.format(new Date(historyList.get(0).date)).equals(df.format(new Date()))) {
|
||||
//Today should not be included
|
||||
historyList.remove(0);
|
||||
}
|
||||
|
@ -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) {
|
||||
Object activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||
PumpInterface dana = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
||||
|
@ -555,6 +547,6 @@ public class TDDStatsActivity extends NoSplashActivity {
|
|||
boolean startsYesterday = activePump == dana || activePump == danaRS || activePump == danaV2 || activePump == danaKorean || activePump == insight;
|
||||
|
||||
DateFormat df = new SimpleDateFormat("dd.MM.");
|
||||
return (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).date)).equals(df.format(new Date(System.currentTimeMillis() - (startsYesterday?1000 * 60 * 60 * 24:0))))));
|
||||
return (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).date)).equals(df.format(new Date(System.currentTimeMillis() - (startsYesterday ? 1000 * 60 * 60 * 24 : 0))))));
|
||||
}
|
||||
}
|
|
@ -15,8 +15,6 @@ import androidx.cardview.widget.CardView;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -86,18 +84,25 @@ public class DanaRHistoryActivity extends NoSplashActivity {
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPumpStatusChanged.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.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
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
}
|
||||
|
||||
|
@ -327,13 +332,4 @@ public class DanaRHistoryActivity extends NoSplashActivity {
|
|||
historyList = new ArrayList<>();
|
||||
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.DanaRHistoryRecord;
|
||||
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.pump.danaR.comm.RecordTypes;
|
||||
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 List<DanaRHistoryRecord> historyRecords;
|
||||
|
||||
public final static int SYNC_BOLUS = 0b00000001;
|
||||
public final static int SYNC_ERROR = 0b00000010;
|
||||
public final static int SYNC_REFILL = 0b00000100;
|
||||
public final static int SYNC_GLUCOSE = 0b00001000;
|
||||
public final static int SYNC_CARBO = 0b00010000;
|
||||
public final static int SYNC_ALARM = 0b00100000;
|
||||
public final static int SYNC_BASALHOURS = 0b01000000;
|
||||
private final static int SYNC_BOLUS = 0b00000001;
|
||||
private final static int SYNC_ERROR = 0b00000010;
|
||||
private final static int SYNC_REFILL = 0b00000100;
|
||||
private final static int SYNC_GLUCOSE = 0b00001000;
|
||||
private final static int SYNC_CARBO = 0b00010000;
|
||||
private final static int SYNC_ALARM = 0b00100000;
|
||||
private final static int SYNC_BASALHOURS = 0b01000000;
|
||||
public final static int SYNC_ALL = 0b11111111;
|
||||
|
||||
public final static String DANARSIGNATURE = "DANARMESSAGE";
|
||||
|
@ -52,13 +53,13 @@ public class DanaRNSHistorySync {
|
|||
long uploaded = 0;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Database contains " + records + " records");
|
||||
EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
|
||||
EventDanaRSyncStatus ev = new EventDanaRSyncStatus("");
|
||||
for (DanaRHistoryRecord record : historyRecords) {
|
||||
processing++;
|
||||
if (record._id != null) continue;
|
||||
//log.debug(record.bytes);
|
||||
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) {
|
||||
case RecordTypes.RECORD_TYPE_BOLUS:
|
||||
if ((what & SYNC_BOLUS) == 0) break;
|
||||
|
@ -73,7 +74,7 @@ public class DanaRNSHistorySync {
|
|||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_sbolus);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_sbolus));
|
||||
break;
|
||||
case "E":
|
||||
if (record.recordDuration > 0) {
|
||||
|
@ -92,7 +93,7 @@ public class DanaRNSHistorySync {
|
|||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_ebolus);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_ebolus));
|
||||
} else {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
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));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_dsbolus);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_dsbolus));
|
||||
break;
|
||||
case "DE":
|
||||
if (L.isEnabled(L.PUMP))
|
||||
|
@ -127,7 +128,7 @@ public class DanaRNSHistorySync {
|
|||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_debolus);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_debolus));
|
||||
break;
|
||||
default:
|
||||
log.error("Unknown bolus record");
|
||||
|
@ -145,7 +146,7 @@ public class DanaRNSHistorySync {
|
|||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_error);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_error));
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_REFILL:
|
||||
if ((what & SYNC_REFILL) == 0) break;
|
||||
|
@ -158,7 +159,7 @@ public class DanaRNSHistorySync {
|
|||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_refill);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_refill));
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_BASALHOUR:
|
||||
if ((what & SYNC_BASALHOURS) == 0) break;
|
||||
|
@ -172,7 +173,7 @@ public class DanaRNSHistorySync {
|
|||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_basalhour);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_basalhour));
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_TB:
|
||||
//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));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_glucose);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_glucose));
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_CARBO:
|
||||
if ((what & SYNC_CARBO) == 0) break;
|
||||
|
@ -202,7 +203,7 @@ public class DanaRNSHistorySync {
|
|||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_carbohydrate);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_carbohydrate));
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_ALARM:
|
||||
if ((what & SYNC_ALARM) == 0) break;
|
||||
|
@ -215,7 +216,7 @@ public class DanaRNSHistorySync {
|
|||
nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
|
||||
NSUpload.uploadCareportalEntryToNS(nsrec);
|
||||
uploaded++;
|
||||
ev.message += MainApp.gs(R.string.danar_alarm);
|
||||
ev.setMessage(ev.getMessage() + MainApp.gs(R.string.danar_alarm));
|
||||
break;
|
||||
case RecordTypes.RECORD_TYPE_SUSPEND: // TODO: this too
|
||||
case RecordTypes.RECORD_TYPE_DAILY:
|
||||
|
@ -226,10 +227,10 @@ public class DanaRNSHistorySync {
|
|||
log.error("Unknown record type");
|
||||
break;
|
||||
}
|
||||
MainApp.bus().post(ev);
|
||||
RxBus.INSTANCE.send(ev);
|
||||
}
|
||||
ev.message = String.format(MainApp.gs(R.string.danar_totaluploaded), uploaded);
|
||||
MainApp.bus().post(ev);
|
||||
ev.setMessage(String.format(MainApp.gs(R.string.danar_totaluploaded), uploaded));
|
||||
RxBus.INSTANCE.send(ev);
|
||||
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
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.utils.DateUtil;
|
||||
|
||||
|
@ -33,8 +34,6 @@ public class MsgHistoryAll extends MessageBase {
|
|||
byte paramByte8 = (byte) intFromBuff(bytes, 7, 1);
|
||||
double value = (double) intFromBuff(bytes, 8, 2);
|
||||
|
||||
EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
|
||||
|
||||
DanaRHistoryRecord danaRHistoryRecord = new DanaRHistoryRecord();
|
||||
|
||||
danaRHistoryRecord.recordCode = recordCode;
|
||||
|
@ -145,11 +144,6 @@ public class MsgHistoryAll extends MessageBase {
|
|||
}
|
||||
|
||||
MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord);
|
||||
|
||||
ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate);
|
||||
ev.message += " " + messageType;
|
||||
MainApp.bus().post(ev);
|
||||
|
||||
return;
|
||||
RxBus.INSTANCE.send(new EventDanaRSyncStatus(DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.fragment.app.FragmentActivity;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -40,7 +38,6 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
|||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
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.general.actions.defs.CustomAction;
|
||||
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.notifications.Notification;
|
||||
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.danaR.DanaRFragment;
|
||||
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);
|
||||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
|
@ -126,7 +123,14 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
}, 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();
|
||||
}
|
||||
|
||||
|
@ -135,7 +139,6 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
Context context = MainApp.instance().getApplicationContext();
|
||||
context.unbindService(mConnection);
|
||||
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
@ -161,8 +164,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
}
|
||||
};
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDanaRSDeviceChange e) {
|
||||
private void loadAddress() {
|
||||
mDeviceAddress = SP.getString(R.string.key_danars_address, "");
|
||||
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.Pattern;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
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.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_name, mName.getText().toString());
|
||||
item.device.createBond();
|
||||
MainApp.bus().post(new EventDanaRSDeviceChange());
|
||||
RxBus.INSTANCE.send(new EventDanaRSDeviceChange());
|
||||
finish();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.app.Activity;
|
|||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -13,14 +12,19 @@ import android.widget.Button;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
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.utils.FabricPrivacy;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
public class PairingProgressDialog extends DialogFragment implements View.OnClickListener {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
TextView statusView;
|
||||
ProgressBar progressBar;
|
||||
|
@ -101,7 +105,11 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic
|
|||
@Override
|
||||
public void 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;
|
||||
if (pairingEnded) dismiss();
|
||||
}
|
||||
|
@ -117,15 +125,10 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic
|
|||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
running = false;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDanaRSPairingSuccess ev) {
|
||||
pairingEnded = true;
|
||||
}
|
||||
|
||||
public void setHelperActivity(PairingHelperActivity activity) {
|
||||
this.helperActivity = activity;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.GregorianCalendar;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||
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.events.EventDanaRSyncStatus;
|
||||
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);
|
||||
|
||||
|
||||
EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
|
||||
DanaRHistoryRecord danaRHistoryRecord = new DanaRHistoryRecord();
|
||||
|
||||
danaRHistoryRecord.setBytes(data);
|
||||
|
@ -224,9 +224,7 @@ public abstract class DanaRS_Packet_History_ extends DanaRS_Packet {
|
|||
|
||||
MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord);
|
||||
|
||||
ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate);
|
||||
ev.message += " " + messageType;
|
||||
MainApp.bus().post(ev);
|
||||
RxBus.INSTANCE.send(new EventDanaRSyncStatus(DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.comm.DanaRSMessageHashTable;
|
||||
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.utils.SP;
|
||||
|
||||
|
@ -496,7 +495,7 @@ public class BLEComm {
|
|||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug("<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(inputBuffer));
|
||||
// Paring is successfull, sending time info
|
||||
MainApp.bus().post(new EventDanaRSPairingSuccess());
|
||||
RxBus.INSTANCE.send(new EventDanaRSPairingSuccess());
|
||||
SendTimeInfo();
|
||||
byte[] pairingKey = {inputBuffer[2], inputBuffer[3]};
|
||||
// store pairing key to preferences
|
||||
|
@ -546,7 +545,6 @@ public class BLEComm {
|
|||
// notify to sendMessage
|
||||
message.notify();
|
||||
}
|
||||
MainApp.bus().post(new EventDanaRSPacket(message));
|
||||
} else {
|
||||
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.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
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.LoggerFactory;
|
||||
|
@ -19,15 +19,18 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
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.virtual.events.EventVirtualPumpUpdateGui;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
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 CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
TextView basaBasalRateView;
|
||||
TextView tempBasalView;
|
||||
|
@ -45,12 +48,11 @@ public class VirtualPumpFragment extends SubscriberFragment {
|
|||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (sRefreshLoop == null) {
|
||||
sRefreshLoop = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGUI();
|
||||
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
||||
}
|
||||
sRefreshLoop = () -> {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(this::updateGui);
|
||||
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
||||
};
|
||||
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
|
||||
}
|
||||
|
@ -59,67 +61,62 @@ public class VirtualPumpFragment extends SubscriberFragment {
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
try {
|
||||
View view = inflater.inflate(R.layout.virtualpump_fragment, container, false);
|
||||
basaBasalRateView = (TextView) view.findViewById(R.id.virtualpump_basabasalrate);
|
||||
tempBasalView = (TextView) view.findViewById(R.id.virtualpump_tempbasal);
|
||||
extendedBolusView = (TextView) view.findViewById(R.id.virtualpump_extendedbolus);
|
||||
batteryView = (TextView) view.findViewById(R.id.virtualpump_battery);
|
||||
reservoirView = (TextView) view.findViewById(R.id.virtualpump_reservoir);
|
||||
pumpTypeView = (TextView) view.findViewById(R.id.virtualpump_type);
|
||||
pumpSettingsView = (TextView) view.findViewById(R.id.virtualpump_type_def);
|
||||
View view = inflater.inflate(R.layout.virtualpump_fragment, container, false);
|
||||
basaBasalRateView = (TextView) view.findViewById(R.id.virtualpump_basabasalrate);
|
||||
tempBasalView = (TextView) view.findViewById(R.id.virtualpump_tempbasal);
|
||||
extendedBolusView = (TextView) view.findViewById(R.id.virtualpump_extendedbolus);
|
||||
batteryView = (TextView) view.findViewById(R.id.virtualpump_battery);
|
||||
reservoirView = (TextView) view.findViewById(R.id.virtualpump_reservoir);
|
||||
pumpTypeView = (TextView) view.findViewById(R.id.virtualpump_type);
|
||||
pumpSettingsView = (TextView) view.findViewById(R.id.virtualpump_type_def);
|
||||
|
||||
return view;
|
||||
} catch (Exception e) {
|
||||
FabricPrivacy.logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventVirtualPumpUpdateGui ev) {
|
||||
updateGUI();
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null && basaBasalRateView != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getPlugin();
|
||||
basaBasalRateView.setText(virtualPump.getBaseBasalRate() + "U");
|
||||
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (activeTemp != null) {
|
||||
tempBasalView.setText(activeTemp.toStringFull());
|
||||
} else {
|
||||
tempBasalView.setText("");
|
||||
}
|
||||
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (activeExtendedBolus != null) {
|
||||
extendedBolusView.setText(activeExtendedBolus.toString());
|
||||
} else {
|
||||
extendedBolusView.setText("");
|
||||
}
|
||||
batteryView.setText(virtualPump.batteryPercent + "%");
|
||||
reservoirView.setText(virtualPump.reservoirInUnits + "U");
|
||||
|
||||
virtualPump.refreshConfiguration();
|
||||
|
||||
PumpType pumpType = virtualPump.getPumpType();
|
||||
|
||||
pumpTypeView.setText(pumpType.getDescription());
|
||||
|
||||
String template = MainApp.gs(R.string.virtualpump_pump_def);
|
||||
|
||||
|
||||
pumpSettingsView.setText(pumpType.getFullDescription(template, pumpType.hasExtendedBasals()));
|
||||
|
||||
}
|
||||
});
|
||||
public synchronized void onResume() {
|
||||
super.onResume();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventVirtualPumpUpdateGui.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||
);
|
||||
updateGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onPause() {
|
||||
super.onPause();
|
||||
disposable.clear();
|
||||
}
|
||||
|
||||
protected void updateGui() {
|
||||
VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getPlugin();
|
||||
basaBasalRateView.setText(virtualPump.getBaseBasalRate() + "U");
|
||||
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (activeTemp != null) {
|
||||
tempBasalView.setText(activeTemp.toStringFull());
|
||||
} else {
|
||||
tempBasalView.setText("");
|
||||
}
|
||||
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
|
||||
if (activeExtendedBolus != null) {
|
||||
extendedBolusView.setText(activeExtendedBolus.toString());
|
||||
} else {
|
||||
extendedBolusView.setText("");
|
||||
}
|
||||
batteryView.setText(virtualPump.batteryPercent + "%");
|
||||
reservoirView.setText(virtualPump.reservoirInUnits + "U");
|
||||
|
||||
virtualPump.refreshConfiguration();
|
||||
|
||||
PumpType pumpType = virtualPump.getPumpType();
|
||||
|
||||
pumpTypeView.setText(pumpType.getDescription());
|
||||
|
||||
String template = MainApp.gs(R.string.virtualpump_pump_def);
|
||||
|
||||
|
||||
pumpSettingsView.setText(pumpType.getFullDescription(template, pumpType.hasExtendedBasals()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,7 +285,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
|||
SystemClock.sleep(1000);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
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();
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
return result;
|
||||
|
@ -313,7 +313,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
|||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Setting temp basal absolute: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||
lastDataTime = System.currentTimeMillis();
|
||||
return result;
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
|||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Settings temp basal percent: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||
lastDataTime = System.currentTimeMillis();
|
||||
return result;
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
|||
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Setting extended bolus: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||
lastDataTime = System.currentTimeMillis();
|
||||
return result;
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
|||
//tempBasal = null;
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Canceling temp basal: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||
}
|
||||
lastDataTime = System.currentTimeMillis();
|
||||
return result;
|
||||
|
@ -399,7 +399,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
|||
result.comment = MainApp.gs(R.string.virtualpump_resultok);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Canceling extended bolus: " + result);
|
||||
MainApp.bus().post(new EventVirtualPumpUpdateGui());
|
||||
RxBus.INSTANCE.send(new EventVirtualPumpUpdateGui());
|
||||
lastDataTime = System.currentTimeMillis();
|
||||
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