From 10584d9b00dfa31798219ec9bac5f7b859e2ad55 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 7 Jun 2019 12:46:08 +0200 Subject: [PATCH] RxBus --- .../java/info/nightscout/androidaps/RxBus.kt | 20 +++++ .../activities/PreferencesActivity.java | 2 + .../androidaps/db/DatabaseHelper.java | 2 + .../general/nsclient/NSClientPlugin.java | 2 + .../nsclient/NsClientReceiverDelegate.java | 2 + .../tidepool/TidepoolJavaFragment.java | 21 ++--- .../general/tidepool/TidepoolPlugin.kt | 87 ++++++++----------- .../general/tidepool/comm/TidepoolCallback.kt | 10 +-- .../general/tidepool/comm/TidepoolUploader.kt | 31 +++---- .../general/tidepool/comm/UploadChunk.kt | 9 +- .../setupwizard/elements/SWItem.java | 2 + 11 files changed, 97 insertions(+), 91 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/RxBus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/RxBus.kt b/app/src/main/java/info/nightscout/androidaps/RxBus.kt new file mode 100644 index 0000000000..ae370e05f2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/RxBus.kt @@ -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() + + fun send(event: Any) { + publisher.onNext(event) + } + + fun toObservable(): Observable = publisher + + // Listen should return an Observable and not the publisher + // Using ofType we filter only events that match that class type + fun toObservable(eventType: Class): Observable = publisher.ofType(eventType) +} diff --git a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java index 5e238dc14b..b6ebed9b5b 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java @@ -15,6 +15,7 @@ import android.text.TextUtils; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.RxBus; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; @@ -65,6 +66,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { MainApp.bus().post(new EventPreferenceChange(key)); + RxBus.INSTANCE.send(new EventPreferenceChange(key)); if (key.equals("language")) { String lang = sharedPreferences.getString("language", "en"); LocaleHelper.setLocale(getApplicationContext(), lang); diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 2f63c8e9ae..46bf2764c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.RxBus; import info.nightscout.androidaps.data.OverlappingIntervals; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; @@ -410,6 +411,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventNewBg"); MainApp.bus().post(new EventNewBG(bgReading)); + RxBus.INSTANCE.send(new EventNewBG(bgReading)); scheduledBgPost = null; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java index 1947c5911d..142c106953 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientPlugin.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.RxBus; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventChargingState; import info.nightscout.androidaps.events.EventNetworkChange; @@ -213,6 +214,7 @@ public class NSClientPlugin extends PluginBase { SP.putBoolean(R.string.key_nsclientinternal_paused, newState); paused = newState; MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused)); + RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused)); } public UploadQueue queue() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java index 8eeee8c43c..e3d8874ea9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegate.java @@ -10,6 +10,7 @@ import com.squareup.otto.Bus; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.RxBus; import info.nightscout.androidaps.events.EventChargingState; import info.nightscout.androidaps.events.EventNetworkChange; import info.nightscout.androidaps.events.EventPreferenceChange; @@ -99,6 +100,7 @@ class NsClientReceiverDelegate { if (newAllowedState != allowed) { allowed = newAllowedState; bus.post(new EventPreferenceChange(R.string.key_nsclientinternal_paused)); + RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolJavaFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolJavaFragment.java index cbae2eb992..c24dabfbf8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolJavaFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolJavaFragment.java @@ -5,13 +5,12 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.TextView; import com.squareup.otto.Subscribe; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.RxBus; import info.nightscout.androidaps.plugins.common.SubscriberFragment; import info.nightscout.androidaps.plugins.general.tidepool.comm.TidepoolUploader; import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolDoUpload; @@ -28,20 +27,10 @@ public class TidepoolJavaFragment extends SubscriberFragment { Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tidepool_fragment, container, false); - Button login = view.findViewById(R.id.tidepool_login); - login.setOnClickListener(v1 -> { - TidepoolUploader.INSTANCE.doLogin(false); - }); - 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); - }); + view.findViewById(R.id.tidepool_login).setOnClickListener(v1 -> TidepoolUploader.INSTANCE.doLogin(false)); + view.findViewById(R.id.tidepool_uploadnow).setOnClickListener(v2 -> RxBus.INSTANCE.send(new EventTidepoolDoUpload())); + 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)); logTextView = view.findViewById(R.id.tidepool_log); statusTextView = view.findViewById(R.id.tidepool_status); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt index 53218f281b..3cd3199331 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/TidepoolPlugin.kt @@ -1,10 +1,10 @@ package info.nightscout.androidaps.plugins.general.tidepool import android.text.Html -import com.squareup.otto.Subscribe import info.nightscout.androidaps.Constants import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.RxBus import info.nightscout.androidaps.events.EventNetworkChange import info.nightscout.androidaps.events.EventNewBG 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.T import info.nightscout.androidaps.utils.ToastUtils +import io.reactivex.disposables.Disposable import org.slf4j.LoggerFactory import java.util.* @@ -35,18 +36,21 @@ object TidepoolPlugin : PluginBase(PluginDescription() .description(R.string.description_tidepool) ) { private val log = LoggerFactory.getLogger(L.TIDEPOOL) + private var disposable: Disposable? = null private val listLog = ArrayList() @Suppress("DEPRECATION") // API level 24 to replace call var textLog = Html.fromHtml("") override fun onStart() { - MainApp.bus().register(this) + disposable = RxBus + .toObservable() + .subscribe { event: Any -> onEvent(event) } super.onStart() } override fun onStop() { - MainApp.bus().unregister(this) + disposable?.dispose() super.onStop() } @@ -57,53 +61,38 @@ object TidepoolPlugin : PluginBase(PluginDescription() TidepoolUploader.doUpload() } - @Suppress("UNUSED_PARAMETER") - @Subscribe - fun onStatusEvent(ev: EventNewBG) { - if (ev.bgReading!!.date!! < TidepoolUploader.getLastEnd()) - 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) { - log.debug("Not connected for deleteDataset") - return + private fun onEvent(event: Any) { + when (event) { + is EventTidepoolDoUpload -> doUpload() + is EventTidepoolResetData -> { + if (TidepoolUploader.connectionStatus != TidepoolUploader.ConnectionStatus.CONNECTED) { + log.debug("Not connected for deleteDataset") + return + } + TidepoolUploader.deleteDataSet() + SP.putLong(R.string.key_tidepool_last_end, 0) + TidepoolUploader.doLogin() + } + is EventTidepoolStatus -> addToLog(event) + is EventNewBG -> { + if (event.bgReading!!.date!! < TidepoolUploader.getLastEnd()) + 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 } - TidepoolUploader.deleteDataSet() - SP.putLong(R.string.key_tidepool_last_end, 0) - TidepoolUploader.doLogin() - } - - @Subscribe - fun onEventNetworkChange(ev: EventNetworkChange) { - // TODO start upload on wifi connect - } - - @Subscribe - fun onStatusEvent(ev: EventTidepoolStatus) { - addToLog(ev) } @Synchronized diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolCallback.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolCallback.kt index 89e9b49c71..200d9a929f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolCallback.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolCallback.kt @@ -1,8 +1,7 @@ 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.plugins.general.tidepool.events.EventTidepoolStatus import org.slf4j.LoggerFactory import retrofit2.Call import retrofit2.Callback @@ -20,7 +19,7 @@ internal class TidepoolCallback(val session: Session, val name: String, val o } else { val msg = name + " was not successful: " + response.code() + " " + response.message() if (L.isEnabled(L.TIDEPOOL)) log.debug(msg) - status(msg) + RxBus.send(msg) onFail() } } @@ -28,11 +27,8 @@ internal class TidepoolCallback(val session: Session, val name: String, val o override fun onFailure(call: Call, t: Throwable) { val msg = "$name Failed: $t" if (L.isEnabled(L.TIDEPOOL)) log.debug(msg) - status(msg) + RxBus.send(msg) onFail() } - private fun status(status: String) { - MainApp.bus().post(EventTidepoolStatus(status)) - } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolUploader.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolUploader.kt index d78088380c..54fc23ee26 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolUploader.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/TidepoolUploader.kt @@ -5,6 +5,7 @@ import android.os.PowerManager import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.RxBus import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus import info.nightscout.androidaps.plugins.general.tidepool.messages.* @@ -80,7 +81,7 @@ object TidepoolUploader { session = Session(AuthRequestMessage.getAuthRequestHeader(), SESSION_TOKEN_HEADER) if (session?.authHeader != null) { connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTING - MainApp.bus().post(EventTidepoolStatus(("Connecting"))) + RxBus.send(EventTidepoolStatus(("Connecting"))) val call = session!!.service?.getLogin(session?.authHeader!!) call?.enqueue(TidepoolCallback(session!!, "Login", { @@ -93,7 +94,7 @@ object TidepoolUploader { } else { if (L.isEnabled(L.TIDEPOOL)) log.debug("Cannot do login as user credentials have not been set correctly") connectionStatus = TidepoolUploader.ConnectionStatus.FAILED; - MainApp.bus().post(EventTidepoolStatus(("Invalid credentials"))) + RxBus.send(EventTidepoolStatus(("Invalid credentials"))) releaseWakeLock() return } @@ -130,15 +131,15 @@ object TidepoolUploader { datasetCall.enqueue(TidepoolCallback>(session, "Get Open Datasets", { 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()) call.enqueue(TidepoolCallback(session, "Open New Dataset", { connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTED; - MainApp.bus().post(EventTidepoolStatus(("New dataset OK"))) + RxBus.send(EventTidepoolStatus(("New dataset OK"))) if (doUpload) doUpload() releaseWakeLock() }, { - MainApp.bus().post(EventTidepoolStatus(("New dataset FAILED"))) + RxBus.send(EventTidepoolStatus(("New dataset FAILED"))) connectionStatus = TidepoolUploader.ConnectionStatus.FAILED; releaseWakeLock() })) @@ -148,19 +149,19 @@ object TidepoolUploader { // 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. connectionStatus = TidepoolUploader.ConnectionStatus.CONNECTED; - MainApp.bus().post(EventTidepoolStatus(("Appending to existing dataset"))) + RxBus.send(EventTidepoolStatus(("Appending to existing dataset"))) if (doUpload) doUpload() releaseWakeLock() } }, { connectionStatus = TidepoolUploader.ConnectionStatus.FAILED; - MainApp.bus().post(EventTidepoolStatus(("Open dataset FAILED"))) + RxBus.send(EventTidepoolStatus(("Open dataset FAILED"))) releaseWakeLock() })) } else { log.error("Got login response but cannot determine userid - cannot proceed") connectionStatus = TidepoolUploader.ConnectionStatus.FAILED; - MainApp.bus().post(EventTidepoolStatus(("Error userid"))) + RxBus.send(EventTidepoolStatus(("Error userid"))) releaseWakeLock() } } @@ -179,19 +180,19 @@ object TidepoolUploader { releaseWakeLock() } else if (chunk.length == 2) { 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() } else { 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) call.enqueue(TidepoolCallback(session!!, "Data Upload", { setLastEnd(session!!.end) - MainApp.bus().post(EventTidepoolStatus(("Upload completed OK"))) + RxBus.send(EventTidepoolStatus(("Upload completed OK"))) releaseWakeLock() }, { - MainApp.bus().post(EventTidepoolStatus(("Upload FAILED"))) + RxBus.send(EventTidepoolStatus(("Upload FAILED"))) releaseWakeLock() })) } @@ -204,11 +205,11 @@ object TidepoolUploader { val call = session!!.service?.deleteDataSet(session!!.token!!, session!!.datasetReply!!.id!!) call?.enqueue(TidepoolCallback(session!!, "Delete Dataset", { connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED - MainApp.bus().post(EventTidepoolStatus(("Dataset removed OK"))) + RxBus.send(EventTidepoolStatus(("Dataset removed OK"))) releaseWakeLock() }, { connectionStatus = TidepoolUploader.ConnectionStatus.DISCONNECTED - MainApp.bus().post(EventTidepoolStatus(("Dataset remove FAILED"))) + RxBus.send(EventTidepoolStatus(("Dataset remove FAILED"))) releaseWakeLock() })) } else { @@ -225,7 +226,7 @@ object TidepoolUploader { if (time > getLastEnd()) { SP.putLong(R.string.key_tidepool_last_end, 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)) } else { if (L.isEnabled(L.TIDEPOOL)) log.debug("Cannot set last end to: " + DateUtil.dateAndTimeString(time) + " vs " + DateUtil.dateAndTimeString(getLastEnd())) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/UploadChunk.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/UploadChunk.kt index 1ce2ea952d..3bebe710ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/UploadChunk.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/comm/UploadChunk.kt @@ -1,6 +1,7 @@ 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.plugins.general.tidepool.elements.* import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus @@ -86,7 +87,7 @@ object UploadChunk { val readings = MainApp.getDbHelper().getCareportalEvents(start, end, true) val selection = BloodGlucoseElement.fromCareportalEvents(readings) if (selection.isNotEmpty()) - MainApp.bus().post(EventTidepoolStatus("${selection.size} BGs selected for upload")) + RxBus.send(EventTidepoolStatus("${selection.size} BGs selected for upload")) return selection } @@ -95,7 +96,7 @@ object UploadChunk { val readings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, end, true) val selection = SensorGlucoseElement.fromBgReadings(readings) if (selection.isNotEmpty()) - MainApp.bus().post(EventTidepoolStatus("${selection.size} CGMs selected for upload")) + RxBus.send(EventTidepoolStatus("${selection.size} CGMs selected for upload")) return selection } @@ -103,7 +104,7 @@ object UploadChunk { val tbrs = MainApp.getDbHelper().getTemporaryBasalsDataFromTime(start, end, true) val selection = BasalElement.fromTemporaryBasals(tbrs) if (selection.isNotEmpty()) - MainApp.bus().post(EventTidepoolStatus("${selection.size} TBRs selected for upload")) + RxBus.send(EventTidepoolStatus("${selection.size} TBRs selected for upload")) return selection } @@ -115,7 +116,7 @@ object UploadChunk { selection.add(pe) } 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 } diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java index 4e8113c73c..6c5c0703c4 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.java @@ -12,6 +12,7 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.RxBus; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.setupwizard.events.EventSWUpdate; @@ -98,6 +99,7 @@ public class SWItem { if (L.isEnabled(L.CORE)) log.debug("Firing EventPreferenceChange"); MainApp.bus().post(new EventPreferenceChange(preferenceId)); + RxBus.INSTANCE.send(new EventPreferenceChange(preferenceId)); MainApp.bus().post(new EventSWUpdate()); scheduledEventPost = null; }