AapsSchedulers

This commit is contained in:
Milos Kozak 2021-02-04 20:54:09 +01:00
parent b04862f602
commit cfe23cef96
115 changed files with 734 additions and 567 deletions

Binary file not shown.

View file

@ -57,10 +57,10 @@ import info.nightscout.androidaps.utils.extensions.isRunningRealPumpTest
import info.nightscout.androidaps.utils.locale.LocaleHelper
import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.resources.IconsProvider
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.androidaps.utils.tabs.TabPageAdapter
import info.nightscout.androidaps.utils.ui.UIRunnable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.util.*
import javax.inject.Inject
@ -71,6 +71,7 @@ class MainActivity : NoSplashAppCompatActivity() {
private val disposable = CompositeDisposable()
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var androidPermission: AndroidPermission
@Inject lateinit var sp: SP
@ -125,7 +126,7 @@ class MainActivity : NoSplashAppCompatActivity() {
setupViews()
disposable.add(rxBus
.toObservable(EventRebuildTabs::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
if (it.recreate) recreate()
else setupViews()
@ -134,7 +135,7 @@ class MainActivity : NoSplashAppCompatActivity() {
)
disposable.add(rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException)
)
if (!sp.getBoolean(R.string.key_setupwizard_processed, false) && !isRunningRealPumpTest()) {

View file

@ -17,6 +17,8 @@ import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.queue.CommandQueue
import info.nightscout.androidaps.utils.androidNotification.NotificationHolder
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.rx.DefaultAapsSchedulers
import info.nightscout.androidaps.utils.storage.FileStorage
import info.nightscout.androidaps.utils.storage.Storage
import javax.inject.Singleton
@ -46,6 +48,10 @@ open class AppModule {
return FileStorage()
}
@Provides
@Singleton
internal fun provideSchedulers(): AapsSchedulers = DefaultAapsSchedulers()
@Module
interface AppBindings {

View file

@ -36,9 +36,9 @@ import info.nightscout.androidaps.utils.SafeParse
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.androidaps.utils.wizard.BolusWizard
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.text.DecimalFormat
import java.util.*
@ -48,6 +48,7 @@ import kotlin.math.abs
class WizardDialog : DaggerDialogFragment() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var constraintChecker: ConstraintChecker
@Inject lateinit var mainApp: MainApp
@Inject lateinit var sp: SP
@ -188,10 +189,10 @@ class WizardDialog : DaggerDialogFragment() {
// bus
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
activity?.runOnUiThread { calculateInsulin() }
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
)
}

View file

@ -32,10 +32,9 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -46,6 +45,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
@Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var sp: SP
@Inject lateinit var profileFunction: ProfileFunction
@ -173,7 +173,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
super.onResume()
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
// catch only events from iobCobCalculatorPluginHistory
if (it.cause is EventCustomCalculationFinished) {
@ -183,7 +183,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
)
disposable.add(rxBus
.toObservable(EventAutosensBgLoaded::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
// catch only events from iobCobCalculatorPluginHistory
if (it.cause is EventCustomCalculationFinished) {
@ -193,12 +193,12 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
)
disposable.add(rxBus
.toObservable(EventIobCalculationProgress::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ binding.overviewIobcalculationprogess.text = it.progress }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventRefreshOverview::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
if (it.now) {
updateGUI("EventRefreshOverview", bgOnly = false)
@ -308,7 +308,6 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
// **** BG ****
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null)
// add target line
graphData.addTargetLine(fromTime, toTime, profile, null)

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAverage
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject
import javax.inject.Singleton
@ -20,6 +21,7 @@ import javax.inject.Singleton
class IobCobCalculatorPluginHistory @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
aapsSchedulers: AapsSchedulers,
rxBus: RxBusWrapper,
sp: SP,
resourceHelper: ResourceHelper,
@ -31,7 +33,7 @@ class IobCobCalculatorPluginHistory @Inject constructor(
sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin,
fabricPrivacy: FabricPrivacy,
dateUtil: DateUtil
) : IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction,
) : IobCobCalculatorPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, resourceHelper, profileFunction,
activePlugin, treatmentsPluginHistory, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil) {
override fun onStart() { // do not attach to rxbus

View file

@ -13,6 +13,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject
import javax.inject.Singleton
@ -21,6 +22,7 @@ import javax.inject.Singleton
class TreatmentsPluginHistory @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
aapsSchedulers: AapsSchedulers,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
context: Context,
@ -31,7 +33,7 @@ class TreatmentsPluginHistory @Inject constructor(
fabricPrivacy: FabricPrivacy,
dateUtil: DateUtil,
uploadQueue: UploadQueue
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue) {
) : TreatmentsPlugin(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue) {
init {
onStart()

View file

@ -17,13 +17,15 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
class LoopFragment : DaggerFragment() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var sp: SP
@Inject lateinit var resourceHelper: ResourceHelper
@ -59,18 +61,18 @@ class LoopFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventLoopUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
updateGUI()
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventLoopSetLastRunGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
clearGUI()
binding.lastrun.text = it.text
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
updateGUI()
sp.putBoolean(R.string.key_objectiveuseloop, true)

View file

@ -72,15 +72,16 @@ import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.HardLimits;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@Singleton
public class LoopPlugin extends PluginBase implements LoopInterface {
private final HasAndroidInjector injector;
private final SP sp;
private final RxBusWrapper rxBus;
private final AapsSchedulers aapsSchedulers;
private final ConstraintChecker constraintChecker;
private final ResourceHelper resourceHelper;
private final ProfileFunction profileFunction;
@ -123,6 +124,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
public LoopPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
AapsSchedulers aapsSchedulers,
RxBusWrapper rxBus,
SP sp,
Config config,
@ -153,6 +155,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
aapsLogger, resourceHelper, injector
);
this.injector = injector;
this.aapsSchedulers = aapsSchedulers;
this.sp = sp;
this.rxBus = rxBus;
this.constraintChecker = constraintChecker;
@ -181,7 +184,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
super.onStart();
disposable.add(rxBus
.toObservable(EventTempTargetChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> invoke("EventTempTargetChange", true), fabricPrivacy::logException)
);
/*
@ -193,7 +196,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
*/
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
// Autosens calculation not triggered by a new BG
if (!(event.getCause() instanceof EventNewBG)) return;

View file

@ -18,7 +18,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.JSONFormatter
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import org.json.JSONArray
import org.json.JSONException
@ -29,6 +29,7 @@ class OpenAPSAMAFragment : DaggerFragment() {
private var disposable: CompositeDisposable = CompositeDisposable()
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var fabricPrivacy: FabricPrivacy
@ -61,16 +62,16 @@ class OpenAPSAMAFragment : DaggerFragment() {
disposable += rxBus
.toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
updateGUI()
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
updateResultGUI(it.text)
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
updateGUI()
}

View file

@ -19,16 +19,18 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.JSONFormatter
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import org.json.JSONArray
import org.json.JSONException
import javax.inject.Inject
class OpenAPSSMBFragment : DaggerFragment() {
private var disposable: CompositeDisposable = CompositeDisposable()
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var fabricPrivacy: FabricPrivacy
@ -60,16 +62,16 @@ class OpenAPSSMBFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
updateGUI()
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventOpenAPSUpdateResultGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
updateResultGUI(it.text)
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
updateGUI()
}

View file

@ -22,13 +22,14 @@ import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.util.*
import javax.inject.Inject
class ConfigBuilderFragment : DaggerFragment() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
@ -77,10 +78,10 @@ class ConfigBuilderFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventConfigBuilderUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
for (pluginViewHolder in pluginViewHolders) pluginViewHolder.update()
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
updateGUI()
}

View file

@ -35,8 +35,8 @@ import info.nightscout.androidaps.utils.SntpClient
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -44,6 +44,7 @@ class ObjectivesFragment : DaggerFragment() {
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var sp: SP
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var fabricPrivacy: FabricPrivacy
@ -92,11 +93,10 @@ class ObjectivesFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventObjectivesUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
binding.recyclerview.adapter?.notifyDataSetChanged()
}, { fabricPrivacy.logException(it) }
)
}, fabricPrivacy::logException)
}
@Synchronized

View file

@ -36,10 +36,10 @@ import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.androidaps.utils.ui.SingleClickButton
import info.nightscout.androidaps.utils.ui.UIRunnable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.util.*
import javax.inject.Inject
@ -47,6 +47,7 @@ import javax.inject.Inject
class ActionsFragment : DaggerFragment() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var sp: SP
@Inject lateinit var profileFunction: ProfileFunction
@ -223,27 +224,27 @@ class ActionsFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventInitializationChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventRefreshOverview::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventCustomActionsChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventCareportalEventChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
updateGui()
}

View file

@ -35,13 +35,14 @@ import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.util.*
import javax.inject.Inject
class AutomationFragment : DaggerFragment(), OnStartDragListener {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var fabricPrivacy: FabricPrivacy
@ -93,16 +94,16 @@ class AutomationFragment : DaggerFragment(), OnStartDragListener {
super.onResume()
disposable += rxBus
.toObservable(EventAutomationUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
updateGui()
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventAutomationDataChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
eventListAdapter.notifyDataSetChanged()
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
updateGui()
}

View file

@ -32,9 +32,9 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
@ -54,6 +54,7 @@ class AutomationPlugin @Inject constructor(
private val rxBus: RxBusWrapper,
private val constraintChecker: ConstraintChecker,
aapsLogger: AAPSLogger,
private val aapsSchedulers: AapsSchedulers,
private val config: Config,
private val locationServiceHelper: LocationServiceHelper,
private val dateUtil: DateUtil
@ -103,7 +104,7 @@ class AutomationPlugin @Inject constructor(
disposable += rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ e ->
if (e.isChanged(resourceHelper, R.string.key_location)) {
locationServiceHelper.stopService(context)
@ -112,11 +113,11 @@ class AutomationPlugin @Inject constructor(
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventAutomationDataChanged::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ storeToSP() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventLocationChange::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ e ->
e?.let {
aapsLogger.debug(LTag.AUTOMATION, "Grabbed location: $it.location.latitude $it.location.longitude Provider: $it.location.provider")
@ -125,19 +126,19 @@ class AutomationPlugin @Inject constructor(
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventChargingState::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ processActions() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventNetworkChange::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ processActions() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ processActions() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventBTChange::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
aapsLogger.debug(LTag.AUTOMATION, "Grabbed new BT event: $it")
btConnects.add(it)

View file

@ -9,7 +9,7 @@ import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import info.nightscout.androidaps.MainApp
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.databinding.AutomationDialogEventBinding
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
@ -27,14 +27,15 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.extensions.toVisibility
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
class EditEventDialog : DialogFragmentWithDate() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var mainApp: MainApp
@Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var automationPlugin: AutomationPlugin
@ -52,11 +53,11 @@ class EditEventDialog : DialogFragmentWithDate() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View {
event = AutomationEvent(mainApp)
event = AutomationEvent(injector)
// load data from bundle
(savedInstanceState ?: arguments)?.let { bundle ->
position = bundle.getInt("position", -1)
bundle.getString("event")?.let { event = AutomationEvent(mainApp).fromJSON(it) }
bundle.getString("event")?.let { event = AutomationEvent(injector).fromJSON(it) }
}
onCreateViewGeneral()
@ -94,28 +95,28 @@ class EditEventDialog : DialogFragmentWithDate() {
disposable += rxBus
.toObservable(EventAutomationUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
actionListAdapter?.notifyDataSetChanged()
showPreconditions()
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventAutomationAddAction::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
event.addAction(it.action)
actionListAdapter?.notifyDataSetChanged()
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventAutomationUpdateTrigger::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
event.trigger = it.trigger
binding.triggerDescription.text = event.trigger.friendlyDescription()
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventAutomationUpdateAction::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
event.actions[it.position] = it.action
actionListAdapter?.notifyDataSetChanged()

View file

@ -4,7 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import info.nightscout.androidaps.MainApp
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.databinding.AutomationDialogEditTriggerBinding
import info.nightscout.androidaps.dialogs.DialogFragmentWithDate
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
@ -17,15 +17,16 @@ import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerCon
import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.extensions.plusAssign
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import org.json.JSONObject
import javax.inject.Inject
class EditTriggerDialog : DialogFragmentWithDate() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var mainApp: MainApp
@Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var fabricPrivacy: FabricPrivacy
private var disposable: CompositeDisposable = CompositeDisposable()
@ -42,7 +43,7 @@ class EditTriggerDialog : DialogFragmentWithDate() {
savedInstanceState: Bundle?): View {
// load data from bundle
(savedInstanceState ?: arguments)?.let { bundle ->
bundle.getString("trigger")?.let { triggers = TriggerDummy(mainApp).instantiate(JSONObject(it)) }
bundle.getString("trigger")?.let { triggers = TriggerDummy(injector).instantiate(JSONObject(it)) }
}
onCreateViewGeneral()
@ -55,28 +56,28 @@ class EditTriggerDialog : DialogFragmentWithDate() {
disposable += rxBus
.toObservable(EventTriggerChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
binding.layoutTrigger.removeAllViews()
triggers?.generateDialog(binding.layoutTrigger)
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTriggerRemove::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
findParent(triggers, it.trigger)?.list?.remove(it.trigger)
binding.layoutTrigger.removeAllViews()
triggers?.generateDialog(binding.layoutTrigger)
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTriggerClone::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
findParent(triggers, it.trigger)?.list?.add(it.trigger.duplicate())
binding.layoutTrigger.removeAllViews()
triggers?.generateDialog(binding.layoutTrigger)
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
// display root trigger
triggers?.generateDialog(binding.layoutTrigger)

View file

@ -30,8 +30,8 @@ import info.nightscout.androidaps.services.Intents
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
import javax.inject.Singleton
@ -40,6 +40,7 @@ class DataBroadcastPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val aapsSchedulers: AapsSchedulers,
private val context: Context,
private val fabricPrivacy: FabricPrivacy,
private val rxBus: RxBusWrapper,
@ -67,32 +68,32 @@ class DataBroadcastPlugin @Inject constructor(
super.onStart()
disposable.add(rxBus
.toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendData(it) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendData(it) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendData(it) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendData(it) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendData(it) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendData(it) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTreatmentChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendData(it) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendData(it) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventNewBasalProfile::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendData(it) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendData(it) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendData(it) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendData(it) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventOverviewBolusProgress::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendData(it) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendData(it) }, fabricPrivacy::logException))
}
override fun onStop() {

View file

@ -24,7 +24,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.util.*
import javax.inject.Inject
@ -32,6 +32,7 @@ import kotlin.collections.ArrayList
class FoodFragment : DaggerFragment() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var fabricPrivacy: FabricPrivacy
@ -106,8 +107,8 @@ class FoodFragment : DaggerFragment() {
super.onResume()
disposable.add(rxBus
.toObservable(EventFoodDatabaseChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
updateGui()
}

View file

@ -36,8 +36,8 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
/**
* Created by mike on 24.09.2017.
@ -47,6 +47,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
@Inject AAPSLogger aapsLogger;
@Inject RxBusWrapper rxBus;
@Inject FabricPrivacy fabricPrivacy;
@Inject AapsSchedulers aapsSchedulers;
private final CompositeDisposable disposable = new CompositeDisposable();
@ -59,7 +60,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
dbInitialize();
disposable.add(rxBus
.toObservable(EventNsFood.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
int mode = event.getMode();
JSONArray array = event.getFoods();

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.general.nsclient;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
@ -25,8 +24,8 @@ import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.HtmlHelper;
import info.nightscout.androidaps.utils.alertDialogs.OKDialog;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
public class NSClientFragment extends DaggerFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
@ -36,6 +35,7 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList
@Inject RxBusWrapper rxBus;
@Inject UploadQueue uploadQueue;
@Inject FabricPrivacy fabricPrivacy;
@Inject AapsSchedulers aapsSchedulers;
private final CompositeDisposable disposable = new CompositeDisposable();
@ -93,7 +93,7 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList
super.onResume();
disposable.add(rxBus
.toObservable(EventNSClientUpdateGUI.class)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.subscribe(event -> updateGui(), fabricPrivacy::logException)
);
updateGui();

View file

@ -59,9 +59,9 @@ import info.nightscout.androidaps.utils.JsonHelper;
import info.nightscout.androidaps.utils.ToastUtils;
import info.nightscout.androidaps.utils.buildHelper.BuildHelper;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@Singleton
public class NSClientPlugin extends PluginBase {
@ -71,6 +71,7 @@ public class NSClientPlugin extends PluginBase {
private final RxBusWrapper rxBus;
private final ResourceHelper resourceHelper;
private final Context context;
private final AapsSchedulers aapsSchedulers;
private final FabricPrivacy fabricPrivacy;
private final SP sp;
private final Config config;
@ -96,6 +97,7 @@ public class NSClientPlugin extends PluginBase {
public NSClientPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
AapsSchedulers aapsSchedulers,
RxBusWrapper rxBus,
ResourceHelper resourceHelper,
Context context,
@ -119,6 +121,7 @@ public class NSClientPlugin extends PluginBase {
);
this.aapsLogger = aapsLogger;
this.aapsSchedulers = aapsSchedulers;
this.rxBus = rxBus;
this.resourceHelper = resourceHelper;
this.context = context;
@ -158,7 +161,7 @@ public class NSClientPlugin extends PluginBase {
nsClientReceiverDelegate.grabReceiversState();
disposable.add(rxBus
.toObservable(EventNSClientStatus.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
status = event.getStatus(resourceHelper);
rxBus.send(new EventNSClientUpdateGUI());
@ -166,17 +169,17 @@ public class NSClientPlugin extends PluginBase {
);
disposable.add(rxBus
.toObservable(EventNetworkChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> nsClientReceiverDelegate.onStatusEvent(event), fabricPrivacy::logException)
);
disposable.add(rxBus
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> nsClientReceiverDelegate.onStatusEvent(event), fabricPrivacy::logException)
);
disposable.add(rxBus
.toObservable(EventAppExit.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
if (nsClientService != null) {
context.unbindService(mConnection);
@ -185,7 +188,7 @@ public class NSClientPlugin extends PluginBase {
);
disposable.add(rxBus
.toObservable(EventNSClientNewLog.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
addToLog(event);
aapsLogger.debug(LTag.NSCLIENT, event.getAction() + " " + event.getLogText());
@ -193,12 +196,12 @@ public class NSClientPlugin extends PluginBase {
);
disposable.add(rxBus
.toObservable(EventChargingState.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> nsClientReceiverDelegate.onStatusEvent(event), fabricPrivacy::logException)
);
disposable.add(rxBus
.toObservable(EventNSClientResend.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> resend(event.getReason()), fabricPrivacy::logException)
);
}

View file

@ -68,9 +68,9 @@ import info.nightscout.androidaps.utils.JsonHelper;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.buildHelper.BuildHelper;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
@ -78,6 +78,7 @@ import io.socket.emitter.Emitter;
public class NSClientService extends DaggerService {
@Inject HasAndroidInjector injector;
@Inject AAPSLogger aapsLogger;
@Inject AapsSchedulers aapsSchedulers;
@Inject NSSettingsStatus nsSettingsStatus;
@Inject NSDeviceStatus nsDeviceStatus;
@Inject DatabaseHelperInterface databaseHelper;
@ -147,7 +148,7 @@ public class NSClientService extends DaggerService {
disposable.add(rxBus
.toObservable(EventConfigBuilderChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
if (nsEnabled != nsClientPlugin.isEnabled(PluginType.GENERAL)) {
latestDateInReceivedData = 0;
@ -158,7 +159,7 @@ public class NSClientService extends DaggerService {
);
disposable.add(rxBus
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
if (event.isChanged(resourceHelper, R.string.key_nsclientinternal_url) ||
event.isChanged(resourceHelper, R.string.key_nsclientinternal_api_secret) ||
@ -172,7 +173,7 @@ public class NSClientService extends DaggerService {
);
disposable.add(rxBus
.toObservable(EventAppExit.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
aapsLogger.debug(LTag.NSCLIENT, "EventAppExit received");
destroy();
@ -181,7 +182,7 @@ public class NSClientService extends DaggerService {
);
disposable.add(rxBus
.toObservable(EventNSClientRestart.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
latestDateInReceivedData = 0;
restart();
@ -189,17 +190,17 @@ public class NSClientService extends DaggerService {
);
disposable.add(rxBus
.toObservable(NSAuthAck.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(this::processAuthAck, fabricPrivacy::logException)
);
disposable.add(rxBus
.toObservable(NSUpdateAck.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(this::processUpdateAck, fabricPrivacy::logException)
);
disposable.add(rxBus
.toObservable(NSAddAck.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(this::processAddAck, fabricPrivacy::logException)
);
}

View file

@ -18,11 +18,10 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.BackpressureStrategy
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@ -37,25 +36,23 @@ class OpenHumansFragment : DaggerFragment() {
private var queueSizeValue = 0L
private val compositeDisposable = CompositeDisposable()
@Inject
lateinit var rxBus: RxBusWrapper
@Inject
lateinit var openHumansUploader: OpenHumansUploader
@Inject
lateinit var resourceHelper: ResourceHelper
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var openHumansUploader: OpenHumansUploader
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var aapsSchedulers: AapsSchedulers
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
compositeDisposable += Single.fromCallable { MainApp.getDbHelper().ohQueueSize }
.subscribeOn(Schedulers.io())
.repeatWhen { rxBus.toObservable(UpdateViewEvent::class.java)
.cast(Any::class.java)
.mergeWith(rxBus.toObservable(UpdateQueueEvent::class.java)
.throttleLatest(5, TimeUnit.SECONDS))
.toFlowable(BackpressureStrategy.LATEST) }
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(aapsSchedulers.io)
.repeatWhen {
rxBus.toObservable(UpdateViewEvent::class.java)
.cast(Any::class.java)
.mergeWith(rxBus.toObservable(UpdateQueueEvent::class.java)
.throttleLatest(5, TimeUnit.SECONDS))
.toFlowable(BackpressureStrategy.LATEST)
}
.observeOn(aapsSchedulers.main)
.subscribe({
queueSizeValue = it
updateGUI()

View file

@ -14,8 +14,8 @@ import androidx.fragment.app.FragmentActivity
import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
@ -45,8 +45,8 @@ class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
class ExchangeAuthTokenDialog : DaggerDialogFragment() {
@Inject
lateinit var openHumansUploader: OpenHumansUploader
@Inject lateinit var openHumansUploader: OpenHumansUploader
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var disposable: Disposable? = null
@ -63,7 +63,7 @@ class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
disposable = openHumansUploader.login(arguments?.getString("authToken")!!).subscribeOn(Schedulers.io()).subscribe({
disposable = openHumansUploader.login(arguments?.getString("authToken")!!).subscribeOn(aapsSchedulers.io).subscribe({
dismiss()
SetupDoneDialog().show(parentFragmentManager, "SetupDoneDialog")
}, {

View file

@ -27,13 +27,13 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Completable
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
@ -52,10 +52,11 @@ class OpenHumansUploader @Inject constructor(
injector: HasAndroidInjector,
resourceHelper: ResourceHelper,
aapsLogger: AAPSLogger,
val sp: SP,
val rxBus: RxBusWrapper,
val context: Context,
val treatmentsPlugin: TreatmentsPlugin
private val aapsSchedulers: AapsSchedulers,
private val sp: SP,
private val rxBus: RxBusWrapper,
private val context: Context,
private val treatmentsPlugin: TreatmentsPlugin
) : PluginBase(
PluginDescription()
.mainType(PluginType.GENERAL)
@ -85,6 +86,7 @@ class OpenHumansUploader @Inject constructor(
}
private val openHumansAPI = OpenHumansAPI(OPEN_HUMANS_URL, CLIENT_ID, CLIENT_SECRET, REDIRECT_URL)
@Suppress("PrivatePropertyName")
private val FILE_NAME_DATE_FORMAT = SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.US).apply { timeZone = TimeZone.getTimeZone("UTC") }
@ -401,7 +403,7 @@ class OpenHumansUploader @Inject constructor(
wakeLock.release()
}
.onErrorComplete()
.subscribeOn(Schedulers.io())
.subscribeOn(aapsSchedulers.io)
.subscribe()
}

View file

@ -59,12 +59,11 @@ import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.androidaps.utils.ui.UIRunnable
import info.nightscout.androidaps.utils.wizard.QuickWizard
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -80,6 +79,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
@Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var sp: SP
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var resourceHelper: ResourceHelper
@ -209,63 +209,63 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
super.onResume()
disposable.add(rxBus
.toObservable(EventRefreshOverview::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
if (it.now) updateGUI(it.from)
else scheduleUpdateGUI(it.from)
}) { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventExtendedBolusChange") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventExtendedBolusChange") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventTempBasalChange") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventTempBasalChange") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTreatmentChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventTreatmentChange") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventTreatmentChange") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTempTargetChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventTempTargetChange") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventTempTargetChange") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventAcceptOpenLoopChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventAcceptOpenLoopChange") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventAcceptOpenLoopChange") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventCareportalEventChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventCareportalEventChange") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventCareportalEventChange") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventInitializationChanged::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventInitializationChanged") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventInitializationChanged") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventAutosensCalculationFinished") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventAutosensCalculationFinished") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventProfileNeedsUpdate::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventProfileNeedsUpdate") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventProfileNeedsUpdate") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventPreferenceChange") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventPreferenceChange") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventNewOpenLoopNotification::class.java)
.observeOn(Schedulers.io())
.subscribe({ scheduleUpdateGUI("EventNewOpenLoopNotification") }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ scheduleUpdateGUI("EventNewOpenLoopNotification") }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventPumpStatusChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updatePumpStatus(it) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.main)
.subscribe({ updatePumpStatus(it) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventIobCalculationProgress::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ binding.graphsLayout.iobCalculationProgress.text = it.progress }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.main)
.subscribe({ binding.graphsLayout.iobCalculationProgress.text = it.progress }, fabricPrivacy::logException))
refreshLoop = Runnable {
scheduleUpdateGUI("refreshLoop")

View file

@ -16,12 +16,11 @@ 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.NotificationStore
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.extensions.*
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.json.JSONObject
import javax.inject.Inject
import javax.inject.Singleton
@ -34,6 +33,7 @@ class OverviewPlugin @Inject constructor(
private val rxBus: RxBusWrapper,
private val sp: SP,
aapsLogger: AAPSLogger,
private val aapsSchedulers: AapsSchedulers,
resourceHelper: ResourceHelper,
private val config: Config
) : PluginBase(PluginDescription()
@ -56,18 +56,18 @@ class OverviewPlugin @Inject constructor(
notificationStore.createNotificationChannel()
disposable += rxBus
.toObservable(EventNewNotification::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ n ->
if (notificationStore.add(n.notification))
rxBus.send(EventRefreshOverview("EventNewNotification"))
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventDismissNotification::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ n ->
if (notificationStore.remove(n.id))
rxBus.send(EventRefreshOverview("EventDismissNotification"))
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
}
override fun onStop() {

View file

@ -18,13 +18,14 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWiza
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.wizard.QuickWizard
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
class QuickWizardListActivity : NoSplashAppCompatActivity() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var quickWizard: QuickWizard
@ -95,11 +96,11 @@ class QuickWizardListActivity : NoSplashAppCompatActivity() {
super.onResume()
disposable += rxBus
.toObservable(EventQuickWizardChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
val adapter = RecyclerViewAdapter(supportFragmentManager)
binding.recyclerview.swapAdapter(adapter, false)
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
}
override fun onPause() {

View file

@ -12,8 +12,8 @@ import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.androidNotification.NotificationHolder
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
/**
@ -21,6 +21,7 @@ import javax.inject.Inject
*/
class DummyService : DaggerService() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var fabricPrivacy: FabricPrivacy
@ -47,7 +48,7 @@ class DummyService : DaggerService() {
}
disposable.add(rxBus
.toObservable(EventAppExit::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
aapsLogger.debug(LTag.CORE, "EventAppExit received")
stopSelf()

View file

@ -7,10 +7,8 @@ import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.app.RemoteInput
import androidx.core.app.TaskStackBuilder
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainActivity
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.events.*
@ -26,8 +24,8 @@ import info.nightscout.androidaps.utils.androidNotification.NotificationHolder
import info.nightscout.androidaps.utils.androidNotification.openAppIntent
import info.nightscout.androidaps.utils.resources.IconsProvider
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
import javax.inject.Singleton
@ -37,6 +35,7 @@ class PersistentNotificationPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val aapsSchedulers: AapsSchedulers,
private val profileFunction: ProfileFunction,
private val fabricPrivacy: FabricPrivacy,
private val activePlugins: ActivePluginProvider,
@ -74,36 +73,36 @@ class PersistentNotificationPlugin @Inject constructor(
createNotificationChannel() // make sure channels exist before triggering updates through the bus
disposable.add(rxBus
.toObservable(EventRefreshOverview::class.java)
.observeOn(Schedulers.io())
.subscribe({ triggerNotificationUpdate() }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ triggerNotificationUpdate() }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ triggerNotificationUpdate() }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ triggerNotificationUpdate() }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ triggerNotificationUpdate() }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ triggerNotificationUpdate() }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTreatmentChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ triggerNotificationUpdate() }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ triggerNotificationUpdate() }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventInitializationChanged::class.java)
.observeOn(Schedulers.io())
.subscribe({ triggerNotificationUpdate() }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ triggerNotificationUpdate() }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventNewBasalProfile::class.java)
.observeOn(Schedulers.io())
.subscribe({ triggerNotificationUpdate() }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ triggerNotificationUpdate() }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(Schedulers.io())
.subscribe({ triggerNotificationUpdate() }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ triggerNotificationUpdate() }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ triggerNotificationUpdate() }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ triggerNotificationUpdate() }, fabricPrivacy::logException))
triggerNotificationUpdate()
}

View file

@ -12,7 +12,7 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.extensions.plusAssign
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.util.*
import javax.inject.Inject
@ -20,6 +20,7 @@ import kotlin.math.max
class SmsCommunicatorFragment : DaggerFragment() {
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin
@ -45,8 +46,8 @@ class SmsCommunicatorFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventSmsCommunicatorUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
updateGui()
}

View file

@ -38,10 +38,10 @@ import info.nightscout.androidaps.receivers.BundleStore
import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.apache.commons.lang3.StringUtils
import java.text.Normalizer
import java.util.*
@ -55,6 +55,7 @@ class SmsCommunicatorPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val aapsSchedulers: AapsSchedulers,
private val sp: SP,
private val constraintChecker: ConstraintChecker,
private val rxBus: RxBusWrapper,
@ -107,8 +108,8 @@ class SmsCommunicatorPlugin @Inject constructor(
super.onStart()
disposable += rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventPreferenceChange? -> processSettings(event) }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ event: EventPreferenceChange? -> processSettings(event) }, fabricPrivacy::logException)
}
override fun onStop() {

View file

@ -15,17 +15,19 @@ import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolR
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolUpdateGUI
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
class TidepoolFragment : DaggerFragment() {
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var tidepoolPlugin: TidepoolPlugin
@Inject lateinit var tidepoolUploader: TidepoolUploader
@Inject lateinit var sp: SP
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var disposable: CompositeDisposable = CompositeDisposable()
@ -53,7 +55,7 @@ class TidepoolFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventTidepoolUpdateGUI::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
if (_binding == null) return@subscribe
tidepoolPlugin.updateLog()
@ -61,7 +63,7 @@ class TidepoolFragment : DaggerFragment() {
binding.status.text = tidepoolUploader.connectionStatus.name
binding.log.text = tidepoolPlugin.textLog
binding.logscrollview.fullScroll(ScrollView.FOCUS_DOWN)
}, { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException)
}
@Synchronized
@ -76,5 +78,4 @@ class TidepoolFragment : DaggerFragment() {
_binding = null
}
}

View file

@ -32,9 +32,9 @@ import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
@ -44,6 +44,7 @@ class TidepoolPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val aapsSchedulers: AapsSchedulers,
private val rxBus: RxBusWrapper,
private val context: Context,
private val fabricPrivacy: FabricPrivacy,
@ -71,11 +72,11 @@ class TidepoolPlugin @Inject constructor(
super.onStart()
disposable += rxBus
.toObservable(EventTidepoolDoUpload::class.java)
.observeOn(Schedulers.io())
.subscribe({ doUpload() }, { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ doUpload() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTidepoolResetData::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
if (tidepoolUploader.connectionStatus != CONNECTED) {
aapsLogger.debug(LTag.TIDEPOOL, "Not connected for delete Dataset")
@ -84,18 +85,14 @@ class TidepoolPlugin @Inject constructor(
sp.putLong(R.string.key_tidepool_last_end, 0)
tidepoolUploader.doLogin()
}
}, {
fabricPrivacy.logException(it)
})
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTidepoolStatus::class.java)
.observeOn(Schedulers.io())
.subscribe({ event -> addToLog(event) }, {
fabricPrivacy.logException(it)
})
.observeOn(aapsSchedulers.io)
.subscribe({ event -> addToLog(event) }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventNewBG::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.filter { it.bgReading != null } // better would be optional in API level >24
.map { it.bgReading }
.subscribe({ bgReading ->
@ -106,27 +103,21 @@ class TidepoolPlugin @Inject constructor(
&& (!sp.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || receiverStatusStore.isWifiConnected)
&& rateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
doUpload()
}, {
fabricPrivacy.logException(it)
})
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ event ->
if (event.isChanged(resourceHelper, R.string.key_tidepool_dev_servers)
|| event.isChanged(resourceHelper, R.string.key_tidepool_username)
|| event.isChanged(resourceHelper, R.string.key_tidepool_password)
)
tidepoolUploader.resetInstance()
}, {
fabricPrivacy.logException(it)
})
}, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventNetworkChange::class.java)
.observeOn(Schedulers.io())
.subscribe({}, {
fabricPrivacy.logException(it)
}) // TODO start upload on wifi connect
.observeOn(aapsSchedulers.io)
.subscribe({}, fabricPrivacy::logException) // TODO start upload on wifi connect
}
@ -150,7 +141,7 @@ class TidepoolPlugin @Inject constructor(
private fun doUpload() =
when (tidepoolUploader.connectionStatus) {
DISCONNECTED -> tidepoolUploader.doLogin(true)
CONNECTED -> tidepoolUploader.doUpload()
CONNECTED -> tidepoolUploader.doUpload()
else -> {
}

View file

@ -10,8 +10,8 @@ import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
@ -19,9 +19,9 @@ import info.nightscout.androidaps.plugins.general.wear.wearintegration.WatchUpda
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
import javax.inject.Singleton
@ -30,6 +30,7 @@ class WearPlugin @Inject constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val aapsSchedulers: AapsSchedulers,
private val sp: SP,
private val mainApp: MainApp,
private val fabricPrivacy: FabricPrivacy,
@ -52,57 +53,57 @@ class WearPlugin @Inject constructor(
super.onStart()
disposable.add(rxBus
.toObservable(EventOpenAPSUpdateGui::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventTreatmentChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = false) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventNewBasalProfile::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendDataToWatch(status = false, basals = true, bgValue = false) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendDataToWatch(status = false, basals = true, bgValue = false) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = true) }) { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.io)
.subscribe({ sendDataToWatch(status = true, basals = true, bgValue = true) }, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
// possibly new high or low mark
resendDataToWatch()
// status may be formatted differently
sendDataToWatch(status = true, basals = false, bgValue = false)
}) { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventRefreshOverview::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
if (WatchUpdaterService.shouldReportLoopStatus(loopPlugin.get().isEnabled(PluginType.LOOP)))
sendDataToWatch(status = true, basals = false, bgValue = false)
}) { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventBolusRequested::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ event: EventBolusRequested ->
val status = String.format(resourceHelper.gs(R.string.bolusrequested), event.amount)
val intent = Intent(mainApp, WatchUpdaterService::class.java).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS)
intent.putExtra("progresspercent", 0)
intent.putExtra("progressstatus", status)
mainApp.startService(intent)
}) { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventDismissBolusProgressIfRunning::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ event: EventDismissBolusProgressIfRunning ->
if (event.result == null) return@subscribe
val status: String = if (event.result!!.success) {
@ -114,10 +115,10 @@ class WearPlugin @Inject constructor(
intent.putExtra("progresspercent", 100)
intent.putExtra("progressstatus", status)
mainApp.startService(intent)
}) { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException))
disposable.add(rxBus
.toObservable(EventOverviewBolusProgress::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ event: EventOverviewBolusProgress ->
if (!event.isSMB() || sp.getBoolean("wear_notifySMB", true)) {
val intent = Intent(mainApp, WatchUpdaterService::class.java).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS)
@ -125,7 +126,7 @@ class WearPlugin @Inject constructor(
intent.putExtra("progressstatus", event.status)
mainApp.startService(intent)
}
}) { fabricPrivacy.logException(it) })
}, fabricPrivacy::logException))
}
override fun onStop() {

View file

@ -11,19 +11,19 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished
import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
import javax.inject.Singleton
@ -33,6 +33,7 @@ class StatusLinePlugin @Inject constructor(
private val sp: SP,
private val profileFunction: ProfileFunction,
resourceHelper: ResourceHelper,
private val aapsSchedulers: AapsSchedulers,
private val context: Context,
private val fabricPrivacy: FabricPrivacy,
private val activePlugin: ActivePluginProvider,
@ -56,6 +57,7 @@ class StatusLinePlugin @Inject constructor(
private var lastLoopStatus = false
companion object {
//broadcast related constants
@Suppress("SpellCheckingInspection")
private const val EXTRA_STATUSLINE = "com.eveningoutpost.dexdrip.Extras.Statusline"
@ -70,29 +72,29 @@ class StatusLinePlugin @Inject constructor(
override fun onStart() {
super.onStart()
disposable += rxBus.toObservable(EventRefreshOverview::class.java)
.observeOn(Schedulers.io())
.subscribe({ if (lastLoopStatus != loopPlugin.isEnabled(PluginType.LOOP)) sendStatus() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ if (lastLoopStatus != loopPlugin.isEnabled(PluginType.LOOP)) sendStatus() }, fabricPrivacy::logException)
disposable += rxBus.toObservable(EventExtendedBolusChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendStatus() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ sendStatus() }, fabricPrivacy::logException)
disposable += rxBus.toObservable(EventTempBasalChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendStatus() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ sendStatus() }, fabricPrivacy::logException)
disposable += rxBus.toObservable(EventTreatmentChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendStatus() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ sendStatus() }, fabricPrivacy::logException)
disposable += rxBus.toObservable(EventConfigBuilderChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendStatus() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ sendStatus() }, fabricPrivacy::logException)
disposable += rxBus.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendStatus() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ sendStatus() }, fabricPrivacy::logException)
disposable += rxBus.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendStatus() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ sendStatus() }, fabricPrivacy::logException)
disposable += rxBus.toObservable(EventAppInitialized::class.java)
.observeOn(Schedulers.io())
.subscribe({ sendStatus() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ sendStatus() }, fabricPrivacy::logException)
}
override fun onStop() {

View file

@ -23,6 +23,7 @@ import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.events.EventAppInitialized;
import info.nightscout.androidaps.events.EventConfigBuilderChange;
@ -34,32 +35,32 @@ import info.nightscout.androidaps.interfaces.IobCobCalculatorInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryBgData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import static info.nightscout.androidaps.utils.DateUtil.now;
@Singleton
public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculatorInterface {
private final HasAndroidInjector injector;
private final AapsSchedulers aapsSchedulers;
private final SP sp;
private final RxBusWrapper rxBus;
private final ResourceHelper resourceHelper;
@ -96,6 +97,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
public IobCobCalculatorPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
AapsSchedulers aapsSchedulers,
RxBusWrapper rxBus,
SP sp,
ResourceHelper resourceHelper,
@ -117,6 +119,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
aapsLogger, resourceHelper, injector
);
this.injector = injector;
this.aapsSchedulers = aapsSchedulers;
this.sp = sp;
this.rxBus = rxBus;
this.resourceHelper = resourceHelper;
@ -136,7 +139,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
// EventConfigBuilderChange
disposable.add(rxBus
.toObservable(EventConfigBuilderChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
stopCalculation("onEventConfigBuilderChange");
synchronized (dataLock) {
@ -149,7 +152,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
// EventNewBasalProfile
disposable.add(rxBus
.toObservable(EventNewBasalProfile.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
if (event == null) { // on init no need of reset
return;
@ -165,7 +168,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
// EventNewBG .... cannot be used for invalidating because only event with last BG is fired
disposable.add(rxBus
.toObservable(EventNewBG.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
stopCalculation("onEventNewBG");
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, event);
@ -174,7 +177,7 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
// EventPreferenceChange
disposable.add(rxBus
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
if (event.isChanged(resourceHelper, R.string.key_openapsama_autosens_period) ||
event.isChanged(resourceHelper, R.string.key_age) ||
@ -197,19 +200,19 @@ public class IobCobCalculatorPlugin extends PluginBase implements IobCobCalculat
// EventAppInitialized
disposable.add(rxBus
.toObservable(EventAppInitialized.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event), fabricPrivacy::logException)
);
// EventNewHistoryData
disposable.add(rxBus
.toObservable(EventNewHistoryData.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> newHistoryData(event, false), fabricPrivacy::logException)
);
// EventNewHistoryBgData
disposable.add(rxBus
.toObservable(EventNewHistoryBgData.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> newHistoryData(new EventNewHistoryData(event.getTimestamp()), true), fabricPrivacy::logException)
);
}

View file

@ -22,7 +22,7 @@ import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.text.DecimalFormat
import javax.inject.Inject
@ -37,6 +37,7 @@ class LocalProfileFragment : DaggerFragment() {
@Inject lateinit var localProfilePlugin: LocalProfilePlugin
@Inject lateinit var hardLimits: HardLimits
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var disposable: CompositeDisposable = CompositeDisposable()
@ -213,9 +214,8 @@ class LocalProfileFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventLocalProfileChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ build() }, { fabricPrivacy.logException(it) }
)
.observeOn(aapsSchedulers.main)
.subscribe({ build() },fabricPrivacy::logException)
build()
}

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -31,6 +31,7 @@ class NSProfileFragment : DaggerFragment() {
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var nsProfilePlugin: NSProfilePlugin
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var disposable: CompositeDisposable = CompositeDisposable()
@ -117,8 +118,8 @@ class NSProfileFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventNSProfileUpdateGUI::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }, { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI() }, fabricPrivacy::logException)
updateGUI()
}

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.combo;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
@ -28,8 +27,8 @@ import info.nightscout.androidaps.queue.events.EventQueueChanged;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
public class ComboFragment extends DaggerFragment implements View.OnClickListener {
@ -39,6 +38,7 @@ public class ComboFragment extends DaggerFragment implements View.OnClickListene
@Inject RxBusWrapper rxBus;
@Inject SP sp;
@Inject FabricPrivacy fabricPrivacy;
@Inject AapsSchedulers aapsSchedulers;
private final CompositeDisposable disposable = new CompositeDisposable();
@ -81,12 +81,12 @@ public class ComboFragment extends DaggerFragment implements View.OnClickListene
super.onResume();
disposable.add(rxBus
.toObservable(EventComboPumpUpdateGUI.class)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.subscribe(event -> updateGui(), fabricPrivacy::logException)
);
disposable.add(rxBus
.toObservable(EventQueueChanged.class)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.subscribe(event -> updateGui(), fabricPrivacy::logException)
);
updateGui();

View file

@ -35,7 +35,7 @@ import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import io.reactivex.android.schedulers.AndroidSchedulers;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import io.reactivex.disposables.CompositeDisposable;
public class LocalInsightFragment extends DaggerFragment implements View.OnClickListener {
@ -45,6 +45,7 @@ public class LocalInsightFragment extends DaggerFragment implements View.OnClick
@Inject ResourceHelper resourceHelper;
@Inject FabricPrivacy fabricPrivacy;
@Inject DateUtil dateUtil;
@Inject AapsSchedulers aapsSchedulers;
private final CompositeDisposable disposable = new CompositeDisposable();
@ -80,7 +81,7 @@ public class LocalInsightFragment extends DaggerFragment implements View.OnClick
super.onResume();
disposable.add(rxBus
.toObservable(EventLocalInsightUpdateGUI.class)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.subscribe(event -> updateGUI(), fabricPrivacy::logException)
);
updateGUI();

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -28,6 +28,7 @@ class VirtualPumpFragment : DaggerFragment() {
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin
@Inject lateinit var aapsSchedulers: AapsSchedulers
private val disposable = CompositeDisposable()
@ -57,16 +58,16 @@ class VirtualPumpFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventVirtualPumpUpdateGui::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }, { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }, { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }, { fabricPrivacy.logException(it) })
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
updateGui()
}

View file

@ -20,22 +20,22 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.common.ManufacturerType
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType
import info.nightscout.androidaps.queue.commands.CustomCommand
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
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.queue.commands.CustomCommand
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.InstanceId.instanceId
import info.nightscout.androidaps.utils.TimeChangeType
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.json.JSONException
import org.json.JSONObject
import javax.inject.Inject
@ -49,6 +49,7 @@ class VirtualPumpPlugin @Inject constructor(
private val rxBus: RxBusWrapper,
private var fabricPrivacy: FabricPrivacy,
resourceHelper: ResourceHelper,
private val aapsSchedulers: AapsSchedulers,
private val sp: SP,
private val profileFunction: ProfileFunction,
private val treatmentsPlugin: TreatmentsPlugin,
@ -67,7 +68,6 @@ class VirtualPumpPlugin @Inject constructor(
injector, aapsLogger, resourceHelper, commandQueue
), PumpInterface {
private val disposable = CompositeDisposable()
var batteryPercent = 50
var reservoirInUnits = 50
@ -112,8 +112,8 @@ class VirtualPumpPlugin @Inject constructor(
super.onStart()
disposable += rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventPreferenceChange -> if (event.isChanged(resourceHelper, R.string.key_virtualpump_type)) refreshConfiguration() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.io)
.subscribe({ event: EventPreferenceChange -> if (event.isChanged(resourceHelper, R.string.key_virtualpump_type)) refreshConfiguration() }, fabricPrivacy::logException)
refreshConfiguration()
}

View file

@ -29,7 +29,7 @@ import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -41,6 +41,7 @@ class BGSourceFragment : DaggerFragment() {
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var databaseHelper: DatabaseHelperInterface
@Inject lateinit var aapsSchedulers: AapsSchedulers
private val disposable = CompositeDisposable()
private val millsToThePast = T.hours(12).msecs()
@ -68,13 +69,13 @@ class BGSourceFragment : DaggerFragment() {
super.onResume()
disposable.add(rxBus
.toObservable(EventNewBG::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventNewHistoryBgData::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGUI() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI() }, fabricPrivacy::logException)
)
updateGUI()
}

View file

@ -49,8 +49,8 @@ import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryDa
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.JsonHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
/**
@ -65,6 +65,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
@Inject DatabaseHelperInterface databaseHelper;
@Inject OpenHumansUploader openHumansUploader;
@Inject AapsSchedulers aapsSchedulers;
private final CompositeDisposable disposable = new CompositeDisposable();
@ -77,7 +78,7 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
dbInitialize();
disposable.add(rxBus
.toObservable(EventNsTreatment.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
int mode = event.getMode();
JSONObject payload = event.getPayload();

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -28,6 +28,7 @@ class TreatmentsFragment : DaggerFragment() {
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin
@Inject lateinit var aapsSchedulers: AapsSchedulers
private val disposable = CompositeDisposable()
@ -76,7 +77,7 @@ class TreatmentsFragment : DaggerFragment() {
super.onResume()
disposable += rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
updateGui()
}

View file

@ -62,14 +62,15 @@ import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@Singleton
public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface {
private final Context context;
private final AapsSchedulers aapsSchedulers;
private final SP sp;
private final RxBusWrapper rxBus;
private final ResourceHelper resourceHelper;
@ -98,6 +99,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
HasAndroidInjector injector,
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
AapsSchedulers aapsSchedulers,
ResourceHelper resourceHelper,
Context context,
SP sp,
@ -122,6 +124,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
this.resourceHelper = resourceHelper;
this.context = context;
this.rxBus = rxBus;
this.aapsSchedulers = aapsSchedulers;
this.sp = sp;
this.profileFunction = profileFunction;
this.activePlugin = activePlugin;
@ -138,7 +141,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
super.onStart();
disposable.add(rxBus
.toObservable(EventReloadTreatmentData.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
getAapsLogger().debug(LTag.DATATREATMENTS, "EventReloadTreatmentData");
initializeTreatmentData(range());
@ -150,19 +153,19 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
));
disposable.add(rxBus
.toObservable(EventReloadProfileSwitchData.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> initializeProfileSwitchData(range()),
fabricPrivacy::logException
));
disposable.add(rxBus
.toObservable(EventTempTargetChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> initializeTempTargetData(range()),
fabricPrivacy::logException
));
disposable.add(rxBus
.toObservable(EventReloadTempBasalData.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
getAapsLogger().debug(LTag.DATATREATMENTS, "EventReloadTempBasalData");
initializeTempBasalData(range());

View file

@ -28,8 +28,8 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -47,6 +47,7 @@ class TreatmentsBolusFragment : DaggerFragment() {
@Inject lateinit var uploadQueue: UploadQueue
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var buildHelper: BuildHelper
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var _binding: TreatmentsBolusFragmentBinding? = null
@ -94,13 +95,13 @@ class TreatmentsBolusFragment : DaggerFragment() {
super.onResume()
disposable.add(rxBus
.toObservable(EventTreatmentChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
updateGui()
}

View file

@ -25,8 +25,8 @@ import info.nightscout.androidaps.utils.Translator
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -43,6 +43,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
@Inject lateinit var uploadQueue: UploadQueue
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var buildHelper: BuildHelper
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var _binding: TreatmentsCareportalFragmentBinding? = null
@ -93,7 +94,7 @@ class TreatmentsCareportalFragment : DaggerFragment() {
super.onResume()
disposable.add(rxBus
.toObservable(EventCareportalEventChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
updateGui()

View file

@ -29,7 +29,7 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -45,6 +45,7 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
@Inject lateinit var uploadQueue: UploadQueue
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var _binding: TreatmentsExtendedbolusFragmentBinding? = null
@ -135,13 +136,13 @@ class TreatmentsExtendedBolusesFragment : DaggerFragment() {
super.onResume()
disposable.add(rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateGui() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
updateGui()
}

View file

@ -30,8 +30,8 @@ import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -48,6 +48,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
@Inject lateinit var uploadQueue: UploadQueue
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var buildHelper: BuildHelper
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var _binding: TreatmentsProfileswitchFragmentBinding? = null
@ -80,7 +81,7 @@ class TreatmentsProfileSwitchFragment : DaggerFragment() {
super.onResume()
disposable.add(rxBus
.toObservable(EventProfileNeedsUpdate::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI() }, fabricPrivacy::logException)
)
updateGUI()

View file

@ -30,8 +30,8 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -47,6 +47,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var buildHelper: BuildHelper
@Inject lateinit var aapsSchedulers: AapsSchedulers
private val disposable = CompositeDisposable()
@ -80,7 +81,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() {
super.onResume()
disposable.add(rxBus
.toObservable(EventTempTargetChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
updateGui()

View file

@ -27,7 +27,7 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -41,6 +41,7 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var _binding: TreatmentsTempbasalsFragmentBinding? = null
@ -63,12 +64,12 @@ class TreatmentsTemporaryBasalsFragment : DaggerFragment() {
super.onResume()
disposable.add(rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGui() }, fabricPrivacy::logException)
)
updateGui()

View file

@ -25,7 +25,6 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.queue.commands.CustomCommand
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
@ -36,9 +35,9 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
@ -87,16 +86,17 @@ import javax.inject.Singleton
@Singleton
class CommandQueue @Inject constructor(
private val injector: HasAndroidInjector,
val aapsLogger: AAPSLogger,
val rxBus: RxBusWrapper,
val resourceHelper: ResourceHelper,
val constraintChecker: ConstraintChecker,
val profileFunction: ProfileFunction,
val activePlugin: Lazy<ActivePluginProvider>,
val context: Context,
val sp: SP,
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val aapsSchedulers: AapsSchedulers,
private val resourceHelper: ResourceHelper,
private val constraintChecker: ConstraintChecker,
private val profileFunction: ProfileFunction,
private val activePlugin: Lazy<ActivePluginProvider>,
private val context: Context,
private val sp: SP,
private val buildHelper: BuildHelper,
val fabricPrivacy: FabricPrivacy
private val fabricPrivacy: FabricPrivacy
) : CommandQueueProvider {
private val disposable = CompositeDisposable()
@ -109,7 +109,7 @@ class CommandQueue @Inject constructor(
init {
disposable.add(rxBus
.toObservable(EventProfileNeedsUpdate::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
aapsLogger.debug(LTag.PROFILE, "onProfileSwitch")
profileFunction.getProfile()?.let {
@ -127,7 +127,7 @@ class CommandQueue @Inject constructor(
}
})
}
}) { exception: Throwable -> fabricPrivacy.logException(exception) }
}, fabricPrivacy::logException)
)
}
@ -208,7 +208,7 @@ class CommandQueue @Inject constructor(
override fun independentConnect(reason: String, callback: Callback?) {
aapsLogger.debug(LTag.PUMPQUEUE, "Starting new queue")
val tempCommandQueue = CommandQueue(injector, aapsLogger, rxBus, resourceHelper, constraintChecker, profileFunction, activePlugin, context, sp, buildHelper, fabricPrivacy)
val tempCommandQueue = CommandQueue(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, constraintChecker, profileFunction, activePlugin, context, sp, buildHelper, fabricPrivacy)
tempCommandQueue.readStatus(reason, callback)
}
@ -292,7 +292,7 @@ class CommandQueue @Inject constructor(
}
removeAll(CommandType.BOLUS)
removeAll(CommandType.SMB_BOLUS)
Thread(Runnable { activePlugin.get().activePump.stopBolusDelivering() }).run()
Thread { activePlugin.get().activePump.stopBolusDelivering() }.run()
}
// returns true if command is queued
@ -500,7 +500,7 @@ class CommandQueue @Inject constructor(
@Synchronized
override fun isCustomCommandInQueue(customCommandType: Class<out CustomCommand>): Boolean {
if(isCustomCommandRunning(customCommandType)) {
if (isCustomCommandRunning(customCommandType)) {
return true
}
synchronized(queue) {

View file

@ -25,9 +25,9 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.androidNotification.NotificationHolder
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
class LocationService : DaggerService() {
@ -35,6 +35,7 @@ class LocationService : DaggerService() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var sp: SP
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var notificationHolder: NotificationHolder
@Inject lateinit var lastLocationDataContainer: LastLocationDataContainer
@ -137,11 +138,11 @@ class LocationService : DaggerService() {
}
disposable.add(rxBus
.toObservable(EventAppExit::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
aapsLogger.debug(LTag.LOCATION, "EventAppExit received")
stopSelf()
}) { fabricPrivacy.logException(it) }
}, fabricPrivacy::logException)
)
}

View file

@ -7,8 +7,9 @@ import android.widget.TextView
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.events.EventStatus
import info.nightscout.androidaps.setupwizard.elements.SWItem
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
class SWEventListener constructor(
injector: HasAndroidInjector,
@ -21,11 +22,13 @@ class SWEventListener constructor(
private var textView: TextView? = null
private var visibilityValidator: SWValidator? = null
@Inject lateinit var aapsSchedulers: AapsSchedulers
// TODO: Adrian how to clear disposable in this case?
init {
disposable.add(rxBus
.toObservable(clazz)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe { event: Any ->
status = (event as EventStatus).getStatus(resourceHelper)
@SuppressLint("SetTextI18n")

View file

@ -21,8 +21,8 @@ import info.nightscout.androidaps.setupwizard.events.EventSWUpdate
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation
import info.nightscout.androidaps.utils.locale.LocaleHelper.update
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
import kotlin.math.max
@ -36,6 +36,7 @@ class SetupWizardActivity : NoSplashAppCompatActivity() {
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var sp: SP
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var aapsSchedulers: AapsSchedulers
private val disposable = CompositeDisposable()
private lateinit var screens: List<SWScreen>
@ -77,36 +78,36 @@ class SetupWizardActivity : NoSplashAppCompatActivity() {
swDefinition.activity = this
disposable.add(rxBus
.toObservable(EventPumpStatusChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateButtons() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateButtons() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventRileyLinkDeviceStatusChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateButtons() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateButtons() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventNSClientStatus::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateButtons() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateButtons() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventProfileNeedsUpdate::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateButtons() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateButtons() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventProfileStoreChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ updateButtons() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ updateButtons() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventSWUpdate::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ event: EventSWUpdate ->
if (event.redraw) generateLayout()
updateButtons()
}) { fabricPrivacy.logException(it) }
}, fabricPrivacy::logException)
)
updateButtons()
}

View file

@ -1,9 +1,9 @@
package info.nightscout.androidaps.utils.stats
import android.content.Context
import android.text.Spanned
import android.util.LongSparseArray
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.db.TDD
import info.nightscout.androidaps.interfaces.ActivePluginProvider
@ -21,6 +21,7 @@ import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.MidnightTime
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject
@ -29,15 +30,16 @@ class TddCalculator @Inject constructor(
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
val mainApp: MainApp,
val sp: SP,
val activePlugin: ActivePluginProvider,
val profileFunction: ProfileFunction,
context: Context,
private val aapsSchedulers: AapsSchedulers,
private val sp: SP,
private val activePlugin: ActivePluginProvider,
private val profileFunction: ProfileFunction,
fabricPrivacy: FabricPrivacy,
nsUpload: NSUpload,
private val dateUtil: DateUtil,
uploadQueue: UploadQueue
) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue) {
) : TreatmentsPlugin(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue) {
init {
service = TreatmentService(injector) // plugin is not started

View file

@ -1,6 +1,8 @@
package info.nightscout.androidaps
import info.nightscout.androidaps.logging.AAPSLoggerTest
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.rx.TestAapsSchedulers
import org.junit.Before
import org.junit.Rule
import org.mockito.Mockito
@ -11,6 +13,7 @@ import java.util.*
open class TestBase {
val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
// Add a JUnit rule that will setup the @Mock annotated vars and log.
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.

View file

@ -14,6 +14,8 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DefaultValueHelper
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.rx.TestAapsSchedulers
import org.json.JSONObject
import org.junit.Before
import org.mockito.Mock
@ -29,7 +31,7 @@ open class TestBaseWithProfile : TestBase() {
@Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var dateUtil: DateUtil
val rxBus = RxBusWrapper()
val rxBus = RxBusWrapper(aapsSchedulers)
val profileInjector = HasAndroidInjector {
AndroidInjector {
@ -57,7 +59,7 @@ open class TestBaseWithProfile : TestBase() {
}
}
lateinit var validProfileJSON: String
private lateinit var validProfileJSON: String
lateinit var validProfile: Profile
val TESTPROFILENAME = "someProfile"

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.danars.comm
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.danars.DanaRSPlugin
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.Constraint
@ -55,7 +54,7 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() {
@Before
fun mock() {
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
danaRSPlugin = DanaRSPlugin({ AndroidInjector { } }, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0))
}
}

View file

@ -68,7 +68,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() {
@Before
fun mock() {
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
danaPump.bolusingTreatment = Treatment(packetInjector)
}
}

View file

@ -117,8 +117,8 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload)
objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, Config())
comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context)
danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy)
danaRSPlugin = DanaRSPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy)
danaRSPlugin = DanaRSPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, nsUpload, context, uploadQueue, Config(), dateUtil)
openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy, sp)
openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy)

View file

@ -39,7 +39,7 @@ import org.powermock.modules.junit4.PowerMockRunner
class LoopPluginTest : TestBase() {
@Mock lateinit var sp: SP
private val rxBus: RxBusWrapper = RxBusWrapper()
private val rxBus: RxBusWrapper = RxBusWrapper(aapsSchedulers)
@Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction
@ -62,7 +62,7 @@ class LoopPluginTest : TestBase() {
@Before fun prepareMock() {
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload)
loopPlugin = LoopPlugin(injector, aapsLogger, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, actionStringHandler, iobCobCalculatorPlugin, receiverStatusStore, fabricPrivacy, nsUpload, hardLimits)
loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, actionStringHandler, iobCobCalculatorPlugin, receiverStatusStore, fabricPrivacy, nsUpload, hardLimits)
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
`when`(context.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager)
}

View file

@ -28,7 +28,7 @@ class ConfigBuilderPluginTest : TestBase() {
@Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var activePlugin: ActivePluginProvider
lateinit var configBuilderPlugin: ConfigBuilderPlugin
private lateinit var configBuilderPlugin: ConfigBuilderPlugin
val injector = HasAndroidInjector {
AndroidInjector {
@ -43,6 +43,6 @@ class ConfigBuilderPluginTest : TestBase() {
@Before
fun prepareMock() {
configBuilderPlugin = ConfigBuilderPlugin(injector, aapsLogger, resourceHelper, sp, RxBusWrapper(), activePlugin)
configBuilderPlugin = ConfigBuilderPlugin(injector, aapsLogger, resourceHelper, sp, RxBusWrapper(aapsSchedulers), activePlugin)
}
}

View file

@ -4,7 +4,6 @@ import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -27,13 +26,13 @@ class DstHelperPluginTest : TestBase() {
@Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var loopPlugin: LoopPlugin
lateinit var plugin: DstHelperPlugin
private lateinit var plugin: DstHelperPlugin
val injector = HasAndroidInjector { AndroidInjector { } }
@Before
fun mock() {
plugin = DstHelperPlugin(injector, aapsLogger, RxBusWrapper(), resourceHelper, sp, activePlugin, loopPlugin)
plugin = DstHelperPlugin(injector, aapsLogger, RxBusWrapper(aapsSchedulers), resourceHelper, sp, activePlugin, loopPlugin)
}
@Test

View file

@ -4,7 +4,6 @@ import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
@ -13,10 +12,11 @@ import org.junit.Test
import org.mockito.Mock
class SignatureVerifierPluginTest : TestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var sp: SP
@Mock lateinit var context: Context
private val rxBus = RxBusWrapper()
private val rxBus = RxBusWrapper(aapsSchedulers)
val injector = HasAndroidInjector { AndroidInjector { } }

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.constraints.storage
import android.os.Environment
import android.os.StatFs
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
@ -14,26 +12,25 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class StorageConstraintPluginTest : TestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
private val rxBusWrapper = RxBusWrapper()
private val rxBusWrapper = RxBusWrapper(aapsSchedulers)
lateinit var storageConstraintPlugin: StorageConstraintPlugin
private lateinit var storageConstraintPlugin: StorageConstraintPlugin
@Before fun prepareMock() {
storageConstraintPlugin = StorageConstraintPlugin(HasAndroidInjector { AndroidInjector { } }, aapsLogger, resourceHelper, rxBusWrapper)
storageConstraintPlugin = StorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, resourceHelper, rxBusWrapper)
}
class MockedStorageConstraintPlugin constructor(
injector: HasAndroidInjector,
aapsLogger: AAPSLogger,
resourceHelper: ResourceHelper,
private val rxBus: RxBusWrapper
rxBus: RxBusWrapper
) : StorageConstraintPlugin(injector, aapsLogger, resourceHelper, rxBus) {
var memSize = 150L
@ -41,7 +38,7 @@ class StorageConstraintPluginTest : TestBase() {
}
@Test fun isLoopInvocationAllowedTest() {
val mocked = MockedStorageConstraintPlugin(HasAndroidInjector { AndroidInjector { } }, aapsLogger, resourceHelper, rxBusWrapper)
val mocked = MockedStorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, resourceHelper, rxBusWrapper)
// Set free space under 200(Mb) to disable loop
mocked.memSize = 150L
Assert.assertEquals(false, mocked.isClosedLoopAllowed(Constraint(true)).value())

View file

@ -21,7 +21,7 @@ class VersionCheckerUtilsKtTest : TestBase() {
@Mock lateinit var context: Context
val config = Config()
val rxBus = RxBusWrapper()
private val rxBus = RxBusWrapper(aapsSchedulers)
@Before fun setup() {
versionCheckerUtils = VersionCheckerUtils(aapsLogger, sp, resourceHelper, rxBus, config, context)

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.general.automation
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
@ -36,7 +35,7 @@ class AutomationEventTest : TestBase() {
it.loopPlugin = loopPlugin
it.resourceHelper = resourceHelper
it.configBuilderPlugin = configBuilderPlugin
it.rxBus = RxBusWrapper()
it.rxBus = RxBusWrapper(aapsSchedulers)
}
}
}

View file

@ -42,7 +42,7 @@ open class TriggerTestBase : TestBaseWithProfile() {
AndroidInjector {
if (it is Trigger) {
it.aapsLogger = aapsLogger
it.rxBus = RxBusWrapper()
it.rxBus = RxBusWrapper(aapsSchedulers)
it.resourceHelper = resourceHelper
it.profileFunction = profileFunction
it.sp = sp

View file

@ -33,7 +33,7 @@ class NsClientReceiverDelegateTest : TestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
lateinit var receiverStatusStore: ReceiverStatusStore
val rxBus: RxBusWrapper = RxBusWrapper()
val rxBus = RxBusWrapper(aapsSchedulers)
private var sut: NsClientReceiverDelegate? = null

View file

@ -114,7 +114,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
`when`(SmsManager.getDefault()).thenReturn(smsManager)
`when`(sp.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678")
smsCommunicatorPlugin = SmsCommunicatorPlugin(injector, aapsLogger, resourceHelper, sp, constraintChecker, rxBus, profileFunction, fabricPrivacy, activePlugin, commandQueue, loopPlugin, iobCobCalculatorPlugin, xdripCalibrations, otp, Config(), DateUtil(context, resourceHelper))
smsCommunicatorPlugin = SmsCommunicatorPlugin(injector, aapsLogger, resourceHelper, aapsSchedulers, sp, constraintChecker, rxBus, profileFunction, fabricPrivacy, activePlugin, commandQueue, loopPlugin, iobCobCalculatorPlugin, xdripCalibrations, otp, Config(), DateUtil(context, resourceHelper))
smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true)
Mockito.doAnswer { invocation: InvocationOnMock ->
val callback = invocation.getArgument<Callback>(1)

View file

@ -31,7 +31,7 @@ import java.util.*
class IobCobCalculatorPluginTest : TestBase() {
@Mock lateinit var sp: SP
private val rxBus: RxBusWrapper = RxBusWrapper()
private val rxBus = RxBusWrapper(aapsSchedulers)
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var activePlugin: ActivePluginProvider
@ -59,7 +59,7 @@ class IobCobCalculatorPluginTest : TestBase() {
@Before
fun mock() {
iobCobCalculatorPlugin = IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction, activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil)
iobCobCalculatorPlugin = IobCobCalculatorPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, resourceHelper, profileFunction, activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy, dateUtil)
}
@Test

View file

@ -51,7 +51,7 @@ class ComboPluginTest : TestBase() {
@Before
fun prepareMocks() {
`when`(resourceHelper.gs(R.string.novalidbasalrate)).thenReturn("No valid basal rate read from pump")
comboPlugin = ComboPlugin(injector, aapsLogger, RxBusWrapper(), resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context)
comboPlugin = ComboPlugin(injector, aapsLogger, RxBusWrapper(aapsSchedulers), resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context)
}
@Test

View file

@ -46,7 +46,7 @@ class DanaRPluginTest : TestBaseWithProfile() {
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
danaPump = info.nightscout.androidaps.dana.DanaPump(aapsLogger, sp, injector)
danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, dateUtil, fabricPrivacy)
danaRPlugin = DanaRPlugin(injector, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, danaPump, dateUtil, fabricPrivacy)
}
@Test @Throws(Exception::class)

View file

@ -55,7 +55,7 @@ open class DanaRTestBase : TestBase() {
it.danaRPlugin = danaRPlugin
it.danaRKoreanPlugin = danaRKoreanPlugin
it.danaRv2Plugin = danaRv2Plugin
it.rxBus = RxBusWrapper()
it.rxBus = RxBusWrapper(aapsSchedulers)
it.resourceHelper = resourceHelper
it.activePlugin = activePluginProvider
it.configBuilder = configBuilder

View file

@ -46,7 +46,7 @@ class DanaRKoreanPluginTest : TestBaseWithProfile() {
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
danaPump = DanaPump(aapsLogger, sp, injector)
danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, rxBus, danaPump, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, dateUtil, fabricPrivacy)
danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, aapsSchedulers, rxBus, danaPump, context, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, dateUtil, fabricPrivacy)
}
@Test @Throws(Exception::class)

View file

@ -65,6 +65,6 @@ class DanaRSPluginTest : DanaRSTestBase() {
Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio")
Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate")
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, aapsSchedulers, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
}
}

View file

@ -46,7 +46,7 @@ class DanaRv2PluginTest : TestBaseWithProfile() {
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
danaPump = DanaPump(aapsLogger, sp, injector)
danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, rxBus, context, danaPump, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, detailedBolusInfoStorage, dateUtil, fabricPrivacy)
danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, aapsSchedulers, rxBus, context, danaPump, resourceHelper, constraintChecker, activePluginProvider, sp, commandQueue, detailedBolusInfoStorage, dateUtil, fabricPrivacy)
}
@Test

View file

@ -1,13 +1,12 @@
package info.nightscout.androidaps.plugins.pump.virtual
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DateUtil
@ -27,7 +26,7 @@ import org.powermock.modules.junit4.PowerMockRunner
@PrepareForTest(FabricPrivacy::class)
class VirtualPumpPluginUTest : TestBase() {
val rxBus = RxBusWrapper()
private val rxBus = RxBusWrapper(aapsSchedulers)
@Mock lateinit var fabricPrivacy: FabricPrivacy
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var sp: SP
@ -40,7 +39,7 @@ class VirtualPumpPluginUTest : TestBase() {
@Before
fun prepareMocks() {
virtualPumpPlugin = VirtualPumpPlugin(HasAndroidInjector { AndroidInjector { } }, aapsLogger, rxBus, fabricPrivacy, resourceHelper, sp, profileFunction, treatmentsPlugin, commandQueue, Config(), dateUtil)
virtualPumpPlugin = VirtualPumpPlugin({ AndroidInjector { } }, aapsLogger, rxBus, fabricPrivacy, resourceHelper, aapsSchedulers, sp, profileFunction, treatmentsPlugin, commandQueue, Config(), dateUtil)
}
@Test

View file

@ -1,10 +1,8 @@
package info.nightscout.androidaps.plugins.source
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Assert
@ -24,7 +22,7 @@ class NSClientPluginTest : TestBase() {
@Before
fun setup() {
nsClientSourcePlugin = NSClientSourcePlugin(HasAndroidInjector { AndroidInjector { } }, resourceHelper, aapsLogger, sp, Config())
nsClientSourcePlugin = NSClientSourcePlugin({ AndroidInjector { } }, resourceHelper, aapsLogger, Config())
}
@Test fun advancedFilteringSupported() {

View file

@ -60,7 +60,7 @@ class TreatmentsPluginTest : TestBaseWithProfile() {
`when`(profileFunction.getProfile(ArgumentMatchers.anyLong())).thenReturn(validProfile)
`when`(activePluginProvider.activeInsulin).thenReturn(insulinOrefRapidActingPlugin)
sot = TreatmentsPlugin(profileInjector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePluginProvider, nsUpload, fabricPrivacy, dateUtil, uploadQueue)
sot = TreatmentsPlugin(profileInjector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, context, sp, profileFunction, activePluginProvider, nsUpload, fabricPrivacy, dateUtil, uploadQueue)
sot.service = treatmentService
}

View file

@ -11,10 +11,10 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PumpDescription
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.queue.commands.CustomCommand
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.queue.commands.Command
import info.nightscout.androidaps.queue.commands.CustomCommand
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
@ -55,7 +55,7 @@ class CommandQueueTest : TestBaseWithProfile() {
@Before
fun prepare() {
commandQueue = CommandQueue(injector, aapsLogger, rxBus, resourceHelper, constraintChecker, profileFunction, lazyActivePlugin, context, sp, buildHelper, fabricPrivacy)
commandQueue = CommandQueue(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, constraintChecker, profileFunction, lazyActivePlugin, context, sp, buildHelper, fabricPrivacy)
val pumpDescription = PumpDescription()
pumpDescription.basalMinimumRate = 0.1
@ -268,16 +268,19 @@ class CommandQueueTest : TestBaseWithProfile() {
}
private class CustomCommand1 : CustomCommand {
override val statusDescription: String
get() = "CUSTOM COMMAND 1"
}
private class CustomCommand2 : CustomCommand {
override val statusDescription: String
get() = "CUSTOM COMMAND 2"
}
private class CustomCommand3 : CustomCommand {
override val statusDescription: String
get() = "CUSTOM COMMAND 3"
}

View file

@ -52,7 +52,7 @@ class BolusWizardTest : TestBase() {
if (it is BolusWizard) {
it.aapsLogger = aapsLogger
it.resourceHelper = resourceHelper
it.rxBus = RxBusWrapper()
it.rxBus = RxBusWrapper(aapsSchedulers)
it.profileFunction = profileFunction
it.constraintChecker = constraintChecker
it.activePlugin = activePlugin

View file

@ -45,6 +45,7 @@ import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.SafeParse;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
@ -59,6 +60,7 @@ public class TDDStatsActivity extends NoSplashAppCompatActivity {
@Inject CommandQueueProvider commandQueue;
@Inject DatabaseHelperInterface databaseHelper;
@Inject FabricPrivacy fabricPrivacy;
@Inject AapsSchedulers aapsSchedulers;
private final CompositeDisposable disposable = new CompositeDisposable();
@ -83,12 +85,12 @@ public class TDDStatsActivity extends NoSplashAppCompatActivity {
super.onResume();
disposable.add(rxBus
.toObservable(EventPumpStatusChanged.class)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.subscribe(event -> statusView.setText(event.getStatus(resourceHelper)), exception -> fabricPrivacy.logException(exception))
);
disposable.add(rxBus
.toObservable(EventDanaRSyncStatus.class)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.subscribe(event -> {
aapsLogger.debug("EventDanaRSyncStatus: " + event.getMessage());
statusView.setText(event.getMessage());

View file

@ -20,7 +20,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBo
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -31,6 +31,7 @@ class BolusProgressDialog : DaggerDialogFragment() {
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var aapsSchedulers: AapsSchedulers
private val disposable = CompositeDisposable()
@ -111,17 +112,17 @@ class BolusProgressDialog : DaggerDialogFragment() {
disposable.add(rxBus
.toObservable(EventPumpStatusChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ binding.status.text = it.getStatus(resourceHelper) }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ binding.status.text = it.getStatus(resourceHelper) }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventDismissBolusProgressIfRunning::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ if (running) dismiss() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ if (running) dismiss() }, fabricPrivacy::logException)
)
disposable.add(rxBus
.toObservable(EventOverviewBolusProgress::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
aapsLogger.debug(LTag.UI, "Status: ${it.status} Percent: ${it.percent}")
binding.status.text = it.status
@ -131,7 +132,7 @@ class BolusProgressDialog : DaggerDialogFragment() {
scheduleDismiss()
}
state = it.status
}) { fabricPrivacy.logException(it) }
}, fabricPrivacy::logException)
)
}

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -25,6 +26,7 @@ class NtpProgressDialog : DaggerDialogFragment() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var aapsSchedulers: AapsSchedulers
private val disposable = CompositeDisposable()
@ -71,7 +73,7 @@ class NtpProgressDialog : DaggerDialogFragment() {
disposable += rxBus
.toObservable(EventNtpStatus::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ event: EventNtpStatus ->
if (_binding != null) {
aapsLogger.debug(LTag.UI, "Status: " + event.status + " Percent: " + event.percent)

View file

@ -1,14 +1,16 @@
package info.nightscout.androidaps.plugins.bus
import info.nightscout.androidaps.events.Event
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
open class RxBusWrapper @Inject constructor() {
open class RxBusWrapper @Inject constructor(
val aapsSchedulers: AapsSchedulers
) {
private val publisher = PublishSubject.create<Event>()
@ -20,6 +22,6 @@ open class RxBusWrapper @Inject constructor() {
// Using ofType we filter only events that match that class type
fun <T> toObservable(eventType: Class<T>): Observable<T> =
publisher
.subscribeOn(Schedulers.io())
.subscribeOn(aapsSchedulers.io)
.ofType(eventType)
}

View file

@ -41,6 +41,7 @@ import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@ -70,6 +71,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
protected PumpDriverState pumpState = PumpDriverState.NotInitialized;
protected boolean displayConnectionMessages = false;
protected PumpType pumpType;
protected AapsSchedulers aapsSchedulers;
protected PumpPluginAbstract(
@ -84,7 +86,8 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
SP sp,
Context context,
FabricPrivacy fabricPrivacy,
DateUtil dateUtil
DateUtil dateUtil,
AapsSchedulers aapsSchedulers
) {
super(pluginDescription, injector, aapsLogger, resourceHelper, commandQueue);
@ -100,6 +103,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
pumpDescription.setPumpDescription(pumpType);
this.pumpType = pumpType;
this.dateUtil = dateUtil;
this.aapsSchedulers = aapsSchedulers;
}
@ -119,7 +123,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
disposable.add(rxBus
.toObservable(EventAppExit.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> context.unbindService(serviceConnection), fabricPrivacy::logException)
);
onStartCustomActions();

View file

@ -0,0 +1,27 @@
package info.nightscout.androidaps.utils.rx
import io.reactivex.Scheduler
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
/**
* Created by adrian on 12.04.20.
*/
interface AapsSchedulers {
val main: Scheduler
val io: Scheduler
val cpu: Scheduler
}
class DefaultAapsSchedulers : AapsSchedulers {
override val main: Scheduler = AndroidSchedulers.mainThread()
override val io: Scheduler = Schedulers.io()
override val cpu: Scheduler = Schedulers.computation()
}
class TestAapsSchedulers : AapsSchedulers {
override val main: Scheduler = Schedulers.trampoline()
override val io: Scheduler = Schedulers.trampoline()
override val cpu: Scheduler = Schedulers.trampoline()
}

View file

@ -0,0 +1,43 @@
package info.nightscout.androidaps.utils.rx
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.Single
import java.util.concurrent.TimeUnit
import kotlin.math.pow
/**
* Created by adrian on 12.04.20.
*/
inline fun <reified T> Single<T>.retryExponentialBackoff(retries: Int, time: Long, timeUnit: TimeUnit): Single<T> =
this.retryWhen { throwables: Flowable<Throwable> ->
throwables.zipWith(
Flowable.range(0, retries),
{ throwable: Throwable, retryCount: Int ->
if (retryCount >= retries) {
throw throwable
} else {
retryCount
}
}
).flatMap { retryCount: Int ->
Flowable.timer(time * 2.toDouble().pow(retryCount.toDouble()).toLong(), timeUnit)
}
}
fun Completable.retryExponentialBackoff(retries: Int, time: Long, timeUnit: TimeUnit): Completable =
this.retryWhen { throwables: Flowable<Throwable> ->
throwables.zipWith(
Flowable.range(0, retries),
{ throwable: Throwable, retryCount: Int ->
if (retryCount >= retries) {
throw throwable
} else {
retryCount
}
}
).flatMap { retryCount: Int ->
Flowable.timer(time * 2.toDouble().pow(retryCount.toDouble()).toLong(), timeUnit)
}
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.dana
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.os.Handler
@ -30,8 +31,8 @@ import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
@ -47,6 +48,7 @@ class DanaFragment : DaggerFragment() {
@Inject lateinit var sp: SP
@Inject lateinit var warnColors: WarnColors
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var disposable: CompositeDisposable = CompositeDisposable()
@ -118,38 +120,39 @@ class DanaFragment : DaggerFragment() {
loopHandler.postDelayed(refreshLoop, T.mins(1).msecs())
disposable += rxBus
.toObservable(EventInitializationChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(info.nightscout.androidaps.dana.events.EventDanaRNewStatus::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventExtendedBolusChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventTempBasalChange::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventQueueChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ updateGUI() }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventPumpStatusChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
when {
it.status == EventPumpStatusChanged.Status.CONNECTING ->
when (it.status) {
EventPumpStatusChanged.Status.CONNECTING ->
@Suppress("SetTextI18n")
binding.btconnection.text = "{fa-bluetooth-b spin} ${it.secondsElapsed}s"
it.status == EventPumpStatusChanged.Status.CONNECTED ->
EventPumpStatusChanged.Status.CONNECTED ->
@Suppress("SetTextI18n")
binding.btconnection.text = "{fa-bluetooth}"
it.status == EventPumpStatusChanged.Status.DISCONNECTED ->
EventPumpStatusChanged.Status.DISCONNECTED ->
@Suppress("SetTextI18n")
binding.btconnection.text = "{fa-bluetooth-b}"
else -> {}
}
if (it.getStatus(resourceHelper) != "") {
binding.danaPumpstatus.text = it.getStatus(resourceHelper)
@ -174,6 +177,7 @@ class DanaFragment : DaggerFragment() {
_binding = null
}
@SuppressLint("SetTextI18n")
@Synchronized
fun updateGUI() {
if (_binding == null) return
@ -199,7 +203,7 @@ class DanaFragment : DaggerFragment() {
warnColors.setColor(binding.dailyunits, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75, pump.maxDailyTotalUnits * 0.9)
binding.basabasalrate.text = "( " + (pump.activeProfile + 1) + " ) " + resourceHelper.gs(R.string.pump_basebasalrate, plugin.baseBasalRate)
// DanaRPlugin, DanaRKoreanPlugin
if (activePlugin.activePump.isFakingTempsByExtendedBoluses == true) {
if (activePlugin.activePump.isFakingTempsByExtendedBoluses) {
binding.tempbasal.text = activePlugin.activeTreatments.getRealTempBasalFromHistory(System.currentTimeMillis())?.toStringFull()
?: ""
} else {

View file

@ -31,7 +31,7 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.DecimalFormatter
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.extensions.plusAssign
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.util.*
import javax.inject.Inject
@ -46,6 +46,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
@Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var databaseHelper: DatabaseHelperInterface
@Inject lateinit var dateUtil: DateUtil
@Inject lateinit var aapsSchedulers: AapsSchedulers
private val disposable = CompositeDisposable()
@ -63,15 +64,15 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
super.onResume()
disposable += rxBus
.toObservable(EventPumpStatusChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ binding.status.text = it.getStatus(resourceHelper) }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ binding.status.text = it.getStatus(resourceHelper) }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventDanaRSyncStatus::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
aapsLogger.debug(LTag.PUMP, "EventDanaRSyncStatus: " + it.message)
binding.status.text = it.message
}) { fabricPrivacy.logException(it) }
}, fabricPrivacy::logException)
}
override fun onPause() {

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.extensions.plusAssign
import io.reactivex.android.schedulers.AndroidSchedulers
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.text.DecimalFormat
import javax.inject.Inject
@ -35,6 +35,7 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() {
@Inject lateinit var danaPump: DanaPump
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var aapsSchedulers: AapsSchedulers
private val disposable = CompositeDisposable()
@ -52,8 +53,8 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() {
super.onResume()
disposable += rxBus
.toObservable(EventInitializationChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ setData() }) { fabricPrivacy.logException(it) }
.observeOn(aapsSchedulers.main)
.subscribe({ setData() }, fabricPrivacy::logException)
}
@Synchronized

View file

@ -37,9 +37,9 @@ import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@Singleton
public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
@ -55,6 +55,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
public DanaRKoreanPlugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
AapsSchedulers aapsSchedulers,
RxBusWrapper rxBus,
DanaPump danaPump,
Context context,
@ -66,7 +67,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
DateUtil dateUtil,
FabricPrivacy fabricPrivacy
) {
super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, activePlugin, sp, dateUtil);
super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, aapsSchedulers, commandQueue, rxBus, activePlugin, sp, dateUtil);
this.aapsLogger = aapsLogger;
this.context = context;
this.resourceHelper = resourceHelper;
@ -84,7 +85,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
disposable.add(rxBus
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
if (isEnabled(PluginType.PUMP)) {
boolean previousValue = useExtendedBoluses;
@ -98,7 +99,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
);
disposable.add(rxBus
.toObservable(EventAppExit.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> context.unbindService(mConnection), fabricPrivacy::logException)
);
super.onStart();

View file

@ -36,9 +36,9 @@ import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@Singleton
public class DanaRv2Plugin extends AbstractDanaRPlugin {
@ -58,6 +58,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
public DanaRv2Plugin(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
AapsSchedulers aapsSchedulers,
RxBusWrapper rxBus,
Context context,
DanaPump danaPump,
@ -70,7 +71,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
DateUtil dateUtil,
FabricPrivacy fabricPrivacy
) {
super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, activePlugin, sp, dateUtil);
super(injector, danaPump, resourceHelper, constraintChecker, aapsLogger, aapsSchedulers, commandQueue, rxBus, activePlugin, sp, dateUtil);
this.aapsLogger = aapsLogger;
this.context = context;
this.resourceHelper = resourceHelper;
@ -90,7 +91,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
disposable.add(rxBus
.toObservable(EventAppExit.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> context.unbindService(mConnection), fabricPrivacy::logException)
);
super.onStart();

View file

@ -38,18 +38,18 @@ import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.queue.commands.CustomCommand;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.queue.commands.CustomCommand;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.Round;
import info.nightscout.androidaps.utils.TimeChangeType;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
/**
* Created by mike on 28.01.2018.
@ -69,6 +69,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
protected ActivePluginProvider activePlugin;
protected SP sp;
protected DateUtil dateUtil;
protected AapsSchedulers aapsSchedulers;
protected AbstractDanaRPlugin(
HasAndroidInjector injector,
@ -76,6 +77,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
ResourceHelper resourceHelper,
ConstraintChecker constraintChecker,
AAPSLogger aapsLogger,
AapsSchedulers aapsSchedulers,
CommandQueueProvider commandQueue,
RxBusWrapper rxBus,
ActivePluginProvider activePlugin,
@ -98,18 +100,19 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
this.activePlugin = activePlugin;
this.sp = sp;
this.dateUtil = dateUtil;
this.aapsSchedulers = aapsSchedulers;
}
@Override protected void onStart() {
super.onStart();
disposable.add(rxBus
.toObservable(EventConfigBuilderChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> danaPump.reset())
);
disposable.add(rxBus
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.subscribe(event -> {
if (event.isChanged(getResourceHelper(), R.string.key_danar_bt_name)) {
danaPump.reset();

Some files were not shown because too many files have changed in this diff Show more