This commit is contained in:
Milos Kozak 2019-06-07 12:46:08 +02:00
parent 643ddfae52
commit 10584d9b00
11 changed files with 97 additions and 91 deletions

View file

@ -0,0 +1,20 @@
package info.nightscout.androidaps
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
// Use object so we have a singleton instance
object RxBus {
private val publisher = PublishSubject.create<Any>()
fun send(event: Any) {
publisher.onNext(event)
}
fun toObservable(): Observable<Any> = publisher
// Listen should return an Observable and not the publisher
// Using ofType we filter only events that match that class type
fun <T> toObservable(eventType: Class<T>): Observable<T> = publisher.ofType(eventType)
}

View file

@ -15,6 +15,7 @@ import android.text.TextUtils;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.RxBus;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
@ -65,6 +66,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
MainApp.bus().post(new EventPreferenceChange(key)); MainApp.bus().post(new EventPreferenceChange(key));
RxBus.INSTANCE.send(new EventPreferenceChange(key));
if (key.equals("language")) { if (key.equals("language")) {
String lang = sharedPreferences.getString("language", "en"); String lang = sharedPreferences.getString("language", "en");
LocaleHelper.setLocale(getApplicationContext(), lang); LocaleHelper.setLocale(getApplicationContext(), lang);

View file

@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.RxBus;
import info.nightscout.androidaps.data.OverlappingIntervals; import info.nightscout.androidaps.data.OverlappingIntervals;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
@ -410,6 +411,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
if (L.isEnabled(L.DATABASE)) if (L.isEnabled(L.DATABASE))
log.debug("Firing EventNewBg"); log.debug("Firing EventNewBg");
MainApp.bus().post(new EventNewBG(bgReading)); MainApp.bus().post(new EventNewBG(bgReading));
RxBus.INSTANCE.send(new EventNewBG(bgReading));
scheduledBgPost = null; scheduledBgPost = null;
} }
} }

View file

@ -22,6 +22,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.RxBus;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventChargingState; import info.nightscout.androidaps.events.EventChargingState;
import info.nightscout.androidaps.events.EventNetworkChange; import info.nightscout.androidaps.events.EventNetworkChange;
@ -213,6 +214,7 @@ public class NSClientPlugin extends PluginBase {
SP.putBoolean(R.string.key_nsclientinternal_paused, newState); SP.putBoolean(R.string.key_nsclientinternal_paused, newState);
paused = newState; paused = newState;
MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused)); MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
} }
public UploadQueue queue() { public UploadQueue queue() {

View file

@ -10,6 +10,7 @@ import com.squareup.otto.Bus;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.RxBus;
import info.nightscout.androidaps.events.EventChargingState; import info.nightscout.androidaps.events.EventChargingState;
import info.nightscout.androidaps.events.EventNetworkChange; import info.nightscout.androidaps.events.EventNetworkChange;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
@ -99,6 +100,7 @@ class NsClientReceiverDelegate {
if (newAllowedState != allowed) { if (newAllowedState != allowed) {
allowed = newAllowedState; allowed = newAllowedState;
bus.post(new EventPreferenceChange(R.string.key_nsclientinternal_paused)); bus.post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
} }
} }

View file

@ -5,13 +5,12 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.RxBus;
import info.nightscout.androidaps.plugins.common.SubscriberFragment; import info.nightscout.androidaps.plugins.common.SubscriberFragment;
import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader; import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader;
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload; import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload;
@ -28,20 +27,10 @@ public class TidepoolJavaFragment extends SubscriberFragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tidepool_fragment, container, false); View view = inflater.inflate(R.layout.tidepool_fragment, container, false);
Button login = view.findViewById(R.id.tidepool_login); view.findViewById(R.id.tidepool_login).setOnClickListener(v1 -> TidepoolUploader.INSTANCE.doLogin(false));
login.setOnClickListener(v1 -> { view.findViewById(R.id.tidepool_uploadnow).setOnClickListener(v2 -> RxBus.INSTANCE.send(new EventTidepoolDoUpload()));
TidepoolUploader.INSTANCE.doLogin(false); view.findViewById(R.id.tidepool_removeall).setOnClickListener(v3 -> RxBus.INSTANCE.send(new EventTidepoolResetData()));
}); view.findViewById(R.id.tidepool_resertstart).setOnClickListener(v4 -> SP.putLong(R.string.key_tidepool_last_end, 0));
Button uploadnow = view.findViewById(R.id.tidepool_uploadnow);
uploadnow.setOnClickListener(v2 -> MainApp.bus().post(new EventTidepoolDoUpload()));
Button removeall = view.findViewById(R.id.tidepool_removeall);
removeall.setOnClickListener(v3 -> {
MainApp.bus().post(new EventTidepoolResetData());
});
Button resetStart = view.findViewById(R.id.tidepool_resertstart);
resetStart.setOnClickListener(v4 -> {
SP.putLong(R.string.key_tidepool_last_end, 0);
});
logTextView = view.findViewById(R.id.tidepool_log); logTextView = view.findViewById(R.id.tidepool_log);
statusTextView = view.findViewById(R.id.tidepool_status); statusTextView = view.findViewById(R.id.tidepool_status);

View file

@ -1,10 +1,10 @@
package info.nightscout.androidaps.plugins.general.tidepool package info.nightscout.androidaps.plugins.general.tidepool
import android.text.Html import android.text.Html
import com.squareup.otto.Subscribe
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.RxBus
import info.nightscout.androidaps.events.EventNetworkChange import info.nightscout.androidaps.events.EventNetworkChange
import info.nightscout.androidaps.events.EventNewBG import info.nightscout.androidaps.events.EventNewBG
import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.events.EventPreferenceChange
@ -23,6 +23,7 @@ import info.nightscout.androidaps.receivers.NetworkChangeReceiver
import info.nightscout.androidaps.utils.SP import info.nightscout.androidaps.utils.SP
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.ToastUtils
import io.reactivex.disposables.Disposable
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.util.* import java.util.*
@ -35,18 +36,21 @@ object TidepoolPlugin : PluginBase(PluginDescription()
.description(R.string.description_tidepool) .description(R.string.description_tidepool)
) { ) {
private val log = LoggerFactory.getLogger(L.TIDEPOOL) private val log = LoggerFactory.getLogger(L.TIDEPOOL)
private var disposable: Disposable? = null
private val listLog = ArrayList<EventTidepoolStatus>() private val listLog = ArrayList<EventTidepoolStatus>()
@Suppress("DEPRECATION") // API level 24 to replace call @Suppress("DEPRECATION") // API level 24 to replace call
var textLog = Html.fromHtml("") var textLog = Html.fromHtml("")
override fun onStart() { override fun onStart() {
MainApp.bus().register(this) disposable = RxBus
.toObservable()
.subscribe { event: Any -> onEvent(event) }
super.onStart() super.onStart()
} }
override fun onStop() { override fun onStop() {
MainApp.bus().unregister(this) disposable?.dispose()
super.onStop() super.onStop()
} }
@ -57,36 +61,10 @@ object TidepoolPlugin : PluginBase(PluginDescription()
TidepoolUploader.doUpload() TidepoolUploader.doUpload()
} }
@Suppress("UNUSED_PARAMETER") private fun onEvent(event: Any) {
@Subscribe when (event) {
fun onStatusEvent(ev: EventNewBG) { is EventTidepoolDoUpload -> doUpload()
if (ev.bgReading!!.date!! < TidepoolUploader.getLastEnd()) is EventTidepoolResetData -> {
TidepoolUploader.setLastEnd(ev.bgReading!!.date!!)
if (isEnabled(PluginType.GENERAL)
&& (!SP.getBoolean(R.string.key_tidepool_only_while_charging, false) || ChargingStateReceiver.isCharging())
&& (!SP.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || NetworkChangeReceiver.isWifiConnected())
&& RateLimit.ratelimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
doUpload()
}
@Suppress("UNUSED_PARAMETER")
@Subscribe
fun onEventTidepoolDoUpload(ev: EventTidepoolDoUpload) {
doUpload()
}
@Subscribe
fun onEventPreferenceChange(ev: EventPreferenceChange) {
if (ev.isChanged(R.string.key_tidepool_dev_servers)
|| ev.isChanged(R.string.key_tidepool_username)
|| ev.isChanged(R.string.key_tidepool_password)
)
TidepoolUploader.resetInstance()
}
@Suppress("UNUSED_PARAMETER")
@Subscribe
fun onEventTidepoolResetData(ev: EventTidepoolResetData) {
if (TidepoolUploader.connectionStatus != TidepoolUploader.ConnectionStatus.CONNECTED) { if (TidepoolUploader.connectionStatus != TidepoolUploader.ConnectionStatus.CONNECTED) {
log.debug("Not connected for deleteDataset") log.debug("Not connected for deleteDataset")
return return
@ -95,15 +73,26 @@ object TidepoolPlugin : PluginBase(PluginDescription()
SP.putLong(R.string.key_tidepool_last_end, 0) SP.putLong(R.string.key_tidepool_last_end, 0)
TidepoolUploader.doLogin() TidepoolUploader.doLogin()
} }
is EventTidepoolStatus -> addToLog(event)
@Subscribe is EventNewBG -> {
fun onEventNetworkChange(ev: EventNetworkChange) { if (event.bgReading!!.date!! < TidepoolUploader.getLastEnd())
// TODO start upload on wifi connect TidepoolUploader.setLastEnd(event.bgReading!!.date!!)
if (isEnabled(PluginType.GENERAL)
&& (!SP.getBoolean(R.string.key_tidepool_only_while_charging, false) || ChargingStateReceiver.isCharging())
&& (!SP.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || NetworkChangeReceiver.isWifiConnected())
&& RateLimit.ratelimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
doUpload()
}
is EventPreferenceChange -> {
if (event.isChanged(R.string.key_tidepool_dev_servers)
|| event.isChanged(R.string.key_tidepool_username)
|| event.isChanged(R.string.key_tidepool_password)
)
TidepoolUploader.resetInstance()
}
is EventNetworkChange -> {
} // TODO start upload on wifi connect
} }
@Subscribe
fun onStatusEvent(ev: EventTidepoolStatus) {
addToLog(ev)
} }
@Synchronized @Synchronized

View file

@ -1,8 +1,7 @@
package info.nightscout.androidaps.plugins.general.tidepool.comm package info.nightscout.androidaps.plugins.general.tidepool.comm
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.RxBus
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
@ -20,7 +19,7 @@ internal class TidepoolCallback<T>(val session: Session, val name: String, val o
} else { } else {
val msg = name + " was not successful: " + response.code() + " " + response.message() val msg = name + " was not successful: " + response.code() + " " + response.message()
if (L.isEnabled(L.TIDEPOOL)) log.debug(msg) if (L.isEnabled(L.TIDEPOOL)) log.debug(msg)
status(msg) RxBus.send(msg)
onFail() onFail()
} }
} }
@ -28,11 +27,8 @@ internal class TidepoolCallback<T>(val session: Session, val name: String, val o
override fun onFailure(call: Call<T>, t: Throwable) { override fun onFailure(call: Call<T>, t: Throwable) {
val msg = "$name Failed: $t" val msg = "$name Failed: $t"
if (L.isEnabled(L.TIDEPOOL)) log.debug(msg) if (L.isEnabled(L.TIDEPOOL)) log.debug(msg)
status(msg) RxBus.send(msg)
onFail() onFail()
} }
private fun status(status: String) {
MainApp.bus().post(EventTidepoolStatus(status))
}
} }

View file

@ -5,6 +5,7 @@ import android.os.PowerManager
import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.RxBus
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
import info.nightscout.androidaps.plugins.general.tidepool.messages.* import info.nightscout.androidaps.plugins.general.tidepool.messages.*
@ -80,7 +81,7 @@ object TidepoolUploader {
session = Session(AuthRequestMessage.getAuthRequestHeader(), SESSION_TOKEN_HEADER) session = Session(AuthRequestMessage.getAuthRequestHeader(), SESSION_TOKEN_HEADER)
if (session?.authHeader != null) { if (session?.authHeader != null) {
connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTING connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTING
MainApp.bus().post(EventTidepoolStatus(("Connecting"))) RxBus.send(EventTidepoolStatus(("Connecting")))
val call = session!!.service?.getLogin(session?.authHeader!!) val call = session!!.service?.getLogin(session?.authHeader!!)
call?.enqueue(TidepoolCallback<AuthReplyMessage>(session!!, "Login", { call?.enqueue(TidepoolCallback<AuthReplyMessage>(session!!, "Login", {
@ -93,7 +94,7 @@ object TidepoolUploader {
} else { } else {
if (L.isEnabled(L.TIDEPOOL)) log.debug("Cannot do login as user credentials have not been set correctly") if (L.isEnabled(L.TIDEPOOL)) log.debug("Cannot do login as user credentials have not been set correctly")
connectionStatus = TidepoolUploader.ConnectionStatus.FAILED; connectionStatus = TidepoolUploader.ConnectionStatus.FAILED;
MainApp.bus().post(EventTidepoolStatus(("Invalid credentials"))) RxBus.send(EventTidepoolStatus(("Invalid credentials")))
releaseWakeLock() releaseWakeLock()
return return
} }
@ -130,15 +131,15 @@ object TidepoolUploader {
datasetCall.enqueue(TidepoolCallback<List<DatasetReplyMessage>>(session, "Get Open Datasets", { datasetCall.enqueue(TidepoolCallback<List<DatasetReplyMessage>>(session, "Get Open Datasets", {
if (session.datasetReply == null) { if (session.datasetReply == null) {
MainApp.bus().post(EventTidepoolStatus(("Creating new dataset"))) RxBus.send(EventTidepoolStatus(("Creating new dataset")))
val call = session.service.openDataSet(session.token!!, session.authReply!!.userid!!, OpenDatasetRequestMessage().getBody()) val call = session.service.openDataSet(session.token!!, session.authReply!!.userid!!, OpenDatasetRequestMessage().getBody())
call.enqueue(TidepoolCallback<DatasetReplyMessage>(session, "Open New Dataset", { call.enqueue(TidepoolCallback<DatasetReplyMessage>(session, "Open New Dataset", {
connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTED; connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTED;
MainApp.bus().post(EventTidepoolStatus(("New dataset OK"))) RxBus.send(EventTidepoolStatus(("New dataset OK")))
if (doUpload) doUpload() if (doUpload) doUpload()
releaseWakeLock() releaseWakeLock()
}, { }, {
MainApp.bus().post(EventTidepoolStatus(("New dataset FAILED"))) RxBus.send(EventTidepoolStatus(("New dataset FAILED")))
connectionStatus = TidepoolUploader.ConnectionStatus.FAILED; connectionStatus = TidepoolUploader.ConnectionStatus.FAILED;
releaseWakeLock() releaseWakeLock()
})) }))
@ -148,19 +149,19 @@ object TidepoolUploader {
// TODO: Wouldn't need to do this if we could block on the above `call.enqueue`. // TODO: Wouldn't need to do this if we could block on the above `call.enqueue`.
// ie, do the openDataSet conditionally, and then do `doUpload` either way. // ie, do the openDataSet conditionally, and then do `doUpload` either way.
connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTED; connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTED;
MainApp.bus().post(EventTidepoolStatus(("Appending to existing dataset"))) RxBus.send(EventTidepoolStatus(("Appending to existing dataset")))
if (doUpload) doUpload() if (doUpload) doUpload()
releaseWakeLock() releaseWakeLock()
} }
}, { }, {
connectionStatus = TidepoolUploader.ConnectionStatus.FAILED; connectionStatus = TidepoolUploader.ConnectionStatus.FAILED;
MainApp.bus().post(EventTidepoolStatus(("Open dataset FAILED"))) RxBus.send(EventTidepoolStatus(("Open dataset FAILED")))
releaseWakeLock() releaseWakeLock()
})) }))
} else { } else {
log.error("Got login response but cannot determine userid - cannot proceed") log.error("Got login response but cannot determine userid - cannot proceed")
connectionStatus = TidepoolUploader.ConnectionStatus.FAILED; connectionStatus = TidepoolUploader.ConnectionStatus.FAILED;
MainApp.bus().post(EventTidepoolStatus(("Error userid"))) RxBus.send(EventTidepoolStatus(("Error userid")))
releaseWakeLock() releaseWakeLock()
} }
} }
@ -179,19 +180,19 @@ object TidepoolUploader {
releaseWakeLock() releaseWakeLock()
} else if (chunk.length == 2) { } else if (chunk.length == 2) {
if (L.isEnabled(L.TIDEPOOL)) log.debug("Empty dataset - marking as succeeded") if (L.isEnabled(L.TIDEPOOL)) log.debug("Empty dataset - marking as succeeded")
MainApp.bus().post(EventTidepoolStatus(("No data to upload"))) RxBus.send(EventTidepoolStatus(("No data to upload")))
releaseWakeLock() releaseWakeLock()
} else { } else {
val body = RequestBody.create(MediaType.parse("application/json"), chunk) val body = RequestBody.create(MediaType.parse("application/json"), chunk)
MainApp.bus().post(EventTidepoolStatus(("Uploading"))) RxBus.send(EventTidepoolStatus(("Uploading")))
val call = session!!.service!!.doUpload(session!!.token!!, session!!.datasetReply!!.getUploadId()!!, body) val call = session!!.service!!.doUpload(session!!.token!!, session!!.datasetReply!!.getUploadId()!!, body)
call.enqueue(TidepoolCallback<UploadReplyMessage>(session!!, "Data Upload", { call.enqueue(TidepoolCallback<UploadReplyMessage>(session!!, "Data Upload", {
setLastEnd(session!!.end) setLastEnd(session!!.end)
MainApp.bus().post(EventTidepoolStatus(("Upload completed OK"))) RxBus.send(EventTidepoolStatus(("Upload completed OK")))
releaseWakeLock() releaseWakeLock()
}, { }, {
MainApp.bus().post(EventTidepoolStatus(("Upload FAILED"))) RxBus.send(EventTidepoolStatus(("Upload FAILED")))
releaseWakeLock() releaseWakeLock()
})) }))
} }
@ -204,11 +205,11 @@ object TidepoolUploader {
val call = session!!.service?.deleteDataSet(session!!.token!!, session!!.datasetReply!!.id!!) val call = session!!.service?.deleteDataSet(session!!.token!!, session!!.datasetReply!!.id!!)
call?.enqueue(TidepoolCallback(session!!, "Delete Dataset", { call?.enqueue(TidepoolCallback(session!!, "Delete Dataset", {
connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED
MainApp.bus().post(EventTidepoolStatus(("Dataset removed OK"))) RxBus.send(EventTidepoolStatus(("Dataset removed OK")))
releaseWakeLock() releaseWakeLock()
}, { }, {
connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED
MainApp.bus().post(EventTidepoolStatus(("Dataset remove FAILED"))) RxBus.send(EventTidepoolStatus(("Dataset remove FAILED")))
releaseWakeLock() releaseWakeLock()
})) }))
} else { } else {
@ -225,7 +226,7 @@ object TidepoolUploader {
if (time > getLastEnd()) { if (time > getLastEnd()) {
SP.putLong(R.string.key_tidepool_last_end, time) SP.putLong(R.string.key_tidepool_last_end, time)
val friendlyEnd = DateUtil.dateAndTimeString(time) val friendlyEnd = DateUtil.dateAndTimeString(time)
MainApp.bus().post(EventTidepoolStatus(("Marking uploaded data up to $friendlyEnd"))) RxBus.send(EventTidepoolStatus(("Marking uploaded data up to $friendlyEnd")))
if (L.isEnabled(L.TIDEPOOL)) log.debug("Updating last end to: " + DateUtil.dateAndTimeString(time)) if (L.isEnabled(L.TIDEPOOL)) log.debug("Updating last end to: " + DateUtil.dateAndTimeString(time))
} else { } else {
if (L.isEnabled(L.TIDEPOOL)) log.debug("Cannot set last end to: " + DateUtil.dateAndTimeString(time) + " vs " + DateUtil.dateAndTimeString(getLastEnd())) if (L.isEnabled(L.TIDEPOOL)) log.debug("Cannot set last end to: " + DateUtil.dateAndTimeString(time) + " vs " + DateUtil.dateAndTimeString(getLastEnd()))

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.general.tidepool.comm package info.nightscout.androidaps.plugins.general.tidepool.comm
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.RxBus
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.general.tidepool.elements.* import info.nightscout.androidaps.plugins.general.tidepool.elements.*
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
@ -86,7 +87,7 @@ object UploadChunk {
val readings = MainApp.getDbHelper().getCareportalEvents(start, end, true) val readings = MainApp.getDbHelper().getCareportalEvents(start, end, true)
val selection = BloodGlucoseElement.fromCareportalEvents(readings) val selection = BloodGlucoseElement.fromCareportalEvents(readings)
if (selection.isNotEmpty()) if (selection.isNotEmpty())
MainApp.bus().post(EventTidepoolStatus("${selection.size} BGs selected for upload")) RxBus.send(EventTidepoolStatus("${selection.size} BGs selected for upload"))
return selection return selection
} }
@ -95,7 +96,7 @@ object UploadChunk {
val readings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, end, true) val readings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, end, true)
val selection = SensorGlucoseElement.fromBgReadings(readings) val selection = SensorGlucoseElement.fromBgReadings(readings)
if (selection.isNotEmpty()) if (selection.isNotEmpty())
MainApp.bus().post(EventTidepoolStatus("${selection.size} CGMs selected for upload")) RxBus.send(EventTidepoolStatus("${selection.size} CGMs selected for upload"))
return selection return selection
} }
@ -103,7 +104,7 @@ object UploadChunk {
val tbrs = MainApp.getDbHelper().getTemporaryBasalsDataFromTime(start, end, true) val tbrs = MainApp.getDbHelper().getTemporaryBasalsDataFromTime(start, end, true)
val selection = BasalElement.fromTemporaryBasals(tbrs) val selection = BasalElement.fromTemporaryBasals(tbrs)
if (selection.isNotEmpty()) if (selection.isNotEmpty())
MainApp.bus().post(EventTidepoolStatus("${selection.size} TBRs selected for upload")) RxBus.send(EventTidepoolStatus("${selection.size} TBRs selected for upload"))
return selection return selection
} }
@ -115,7 +116,7 @@ object UploadChunk {
selection.add(pe) selection.add(pe)
} }
if (selection.size > 0) if (selection.size > 0)
MainApp.bus().post(EventTidepoolStatus("${selection.size} ProfileSwitches selected for upload")) RxBus.send(EventTidepoolStatus("${selection.size} ProfileSwitches selected for upload"))
return selection return selection
} }

View file

@ -12,6 +12,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.RxBus;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.setupwizard.events.EventSWUpdate; import info.nightscout.androidaps.setupwizard.events.EventSWUpdate;
@ -98,6 +99,7 @@ public class SWItem {
if (L.isEnabled(L.CORE)) if (L.isEnabled(L.CORE))
log.debug("Firing EventPreferenceChange"); log.debug("Firing EventPreferenceChange");
MainApp.bus().post(new EventPreferenceChange(preferenceId)); MainApp.bus().post(new EventPreferenceChange(preferenceId));
RxBus.INSTANCE.send(new EventPreferenceChange(preferenceId));
MainApp.bus().post(new EventSWUpdate()); MainApp.bus().post(new EventSWUpdate());
scheduledEventPost = null; scheduledEventPost = null;
} }