EOPATCH: migrate to rx3

This commit is contained in:
Milos Kozak 2022-09-12 09:14:24 +02:00
parent e42a21207b
commit 8fe336b3ce
67 changed files with 274 additions and 344 deletions

View file

@ -323,7 +323,7 @@ class CommandQueueImplementation @Inject constructor(
}
@Synchronized
override fun cancelAllBoluses(id: Long) {
override fun cancelAllBoluses(id: Long?) {
if (!isRunning(CommandType.BOLUS)) {
rxBus.send(EventDismissBolusProgressIfRunning(PumpEnactResult(injector).success(true).enacted(false), id))
}

View file

@ -17,7 +17,7 @@ interface CommandQueue {
fun independentConnect(reason: String, callback: Callback?)
fun bolusInQueue(): Boolean
fun bolus(detailedBolusInfo: DetailedBolusInfo, callback: Callback?): Boolean
fun cancelAllBoluses(id: Long)
fun cancelAllBoluses(id: Long?)
fun stopPump(callback: Callback?)
fun startPump(callback: Callback?)
fun setTBROverNotification(callback: Callback?, enable: Boolean)

View file

@ -10,28 +10,20 @@ apply from: "${project.rootDir}/core/test_dependencies.gradle"
apply from: "${project.rootDir}/core/jacoco_global.gradle"
android {
namespace 'info.nightscout.androidaps.plugins.pump.eopatch'
dataBinding {
enabled = true
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation (name: 'eopatch_core', ext: 'aar')
// implementation (files("libs/eopatch_core.aar"))
implementation (files("libs/eopatch_core.aar"))
implementation project(':core')
implementation project(':shared')
implementation project(':database')
//RxAndroidBle
implementation "com.polidea.rxandroidble2:rxandroidble:1.12.1"
implementation "com.jakewharton.rx2:replaying-share:2.2.0"
implementation "com.polidea.rxandroidble3:rxandroidble:1.16.0"
implementation "com.jakewharton.rx3:replaying-share:3.0.0"
}

Binary file not shown.

View file

@ -1,25 +0,0 @@
package info.nightscout.androidaps.plugins.pump.eopatch
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.eoflow.patch", appContext.packageName)
}
}

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.nightscout.androidaps.plugins.pump.eopatch">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity android:name=".ui.EopatchActivity" />

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.plugins.pump.eopatch
import io.reactivex.disposables.Disposable
import io.reactivex.rxjava3.disposables.Disposable
import java.util.*
import kotlin.math.abs
import kotlin.math.min

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.plugins.pump.eopatch
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.PublishSubject
object EoPatchRxBus {
private val publishSubject: PublishSubject<Any> = PublishSubject.create()

View file

@ -1,17 +1,20 @@
package info.nightscout.androidaps.plugins.pump.eopatch
import android.os.SystemClock
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.events.EventAppInitialized
import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.interfaces.*
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.Pump
import info.nightscout.androidaps.interfaces.PumpDescription
import info.nightscout.androidaps.interfaces.PumpPluginBase
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.common.ManufacturerType
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction
@ -31,13 +34,12 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.TimeChangeType
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 io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.BehaviorSubject
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.functions.Consumer
import io.reactivex.rxjava3.subjects.BehaviorSubject
import org.json.JSONObject
import javax.inject.Inject
import javax.inject.Singleton
@ -78,7 +80,7 @@ class EopatchPumpPlugin @Inject constructor(
super.onStart()
mDisposables.add(rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({ event: EventPreferenceChange ->
if (event.isChanged(rh, SettingKeys.LOW_RESERVOIR_REMINDERS) || event.isChanged(rh, SettingKeys.EXPIRATION_REMINDERS)) {
patchManager.changeReminderSetting()
@ -90,7 +92,7 @@ class EopatchPumpPlugin @Inject constructor(
mDisposables.add(rxBus
.toObservable(EventAppInitialized::class.java)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.io)
.subscribe({
aapsLogger.debug(LTag.PUMP,"EventAppInitialized")
preferenceManager.init()
@ -109,35 +111,11 @@ class EopatchPumpPlugin @Inject constructor(
return super.specialEnableCondition()
}
override fun specialShowInListCondition(): Boolean {
return super.specialShowInListCondition()
}
override fun onStop() {
super.onStop()
aapsLogger.debug(LTag.PUMP, "EOPatchPumpPlugin onStop()")
}
override fun onStateChange(type: PluginType?, oldState: State?, newState: State?) {
super.onStateChange(type, oldState, newState)
}
override fun preprocessPreferences(preferenceFragment: PreferenceFragmentCompat) {
super.preprocessPreferences(preferenceFragment)
}
override fun updatePreferenceSummary(pref: Preference) {
super.updatePreferenceSummary(pref)
}
override fun isUnreachableAlertTimeoutExceeded(alertTimeoutMilliseconds: Long): Boolean {
return super.isUnreachableAlertTimeoutExceeded(alertTimeoutMilliseconds)
}
override fun setNeutralTempAtFullHour(): Boolean {
return super.setNeutralTempAtFullHour()
}
override fun isInitialized(): Boolean {
return isConnected() && patchManager.isActivated
}
@ -207,7 +185,7 @@ class EopatchPumpPlugin @Inject constructor(
val nb = preferenceManager.getNormalBasalManager().convertProfileToNormalBasal(profile)
mDisposables.add(patchManager.startBasal(nb)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({ response ->
result.onNext(response.isSuccess)
}, {

View file

@ -8,7 +8,7 @@ import android.os.IBinder;
import java.util.Objects;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
public class OsAlarmService extends Service {

View file

@ -5,7 +5,8 @@ package info.nightscout.androidaps.plugins.pump.eopatch
import android.os.SystemClock
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
import io.reactivex.*
import io.reactivex.rxjava3.core.Scheduler
import io.reactivex.rxjava3.core.Single
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton

View file

@ -4,15 +4,14 @@ import android.content.Context
import android.content.Intent
import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmCode.*
import info.nightscout.androidaps.plugins.pump.eopatch.EONotification
import info.nightscout.androidaps.plugins.pump.eopatch.EoPatchRxBus
import info.nightscout.androidaps.plugins.pump.eopatch.R
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmCode.*
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPatchManager
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager
import info.nightscout.androidaps.plugins.pump.eopatch.code.AlarmCategory
@ -20,14 +19,14 @@ import info.nightscout.androidaps.plugins.pump.eopatch.event.EventEoPatchAlarm
import info.nightscout.androidaps.plugins.pump.eopatch.ui.AlarmHelperActivity
import info.nightscout.androidaps.plugins.pump.eopatch.vo.Alarms
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.disposables.Disposable
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton
@ -49,6 +48,7 @@ class AlarmManager @Inject constructor() : IAlarmManager {
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var sp: SP
@Inject lateinit var context: Context
@Inject lateinit var aapsSchedulers: AapsSchedulers
@Inject lateinit var pm: IPreferenceManager
@Inject lateinit var mAlarmRegistry: IAlarmRegistry
@ -69,8 +69,8 @@ class AlarmManager @Inject constructor() : IAlarmManager {
.doOnNext { aapsLogger.info(LTag.PUMP,"EventEoPatchAlarm Received") }
.concatMap {
Observable.fromArray(it)
.observeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.io)
.subscribeOn(aapsSchedulers.main)
.doOnNext { alarmCodes ->
alarmCodes.forEach { alarmCode ->
aapsLogger.info(LTag.PUMP,"alarmCode: ${alarmCode.name}")

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.plugins.pump.eopatch.event.EventDialog
import info.nightscout.androidaps.plugins.pump.eopatch.event.EventProgressDialog
import info.nightscout.androidaps.plugins.pump.eopatch.extension.takeOne
import info.nightscout.androidaps.plugins.pump.eopatch.ui.dialogs.CommonDialog
import io.reactivex.Single
import io.reactivex.rxjava3.core.Single
import java.lang.Exception
import java.util.concurrent.Callable
@ -119,7 +119,6 @@ class AlarmProcess(val patchManager: IPatchManager, val rxBus: RxBus) : IAlarmPr
.filter{ok -> ok}
.flatMap { patchManager.resumeBasal().map { it.isSuccess.takeOne(IAlarmProcess.ALARM_HANDLED, IAlarmProcess.ALARM_UNHANDLED) }.toMaybe() }
.defaultIfEmpty(IAlarmProcess.ALARM_UNHANDLED)
.toSingle()
}
}
}

View file

@ -1,27 +1,26 @@
package info.nightscout.androidaps.plugins.pump.eopatch.alarm
import android.app.AlarmManager
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmCode.Companion.getUri
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.pump.eopatch.event.EventEoPatchAlarm
import android.app.PendingIntent
import android.app.AlarmManager.AlarmClockInfo
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.eopatch.EoPatchRxBus
import info.nightscout.androidaps.plugins.pump.eopatch.OsAlarmReceiver
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmCode.Companion.getUri
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager
import info.nightscout.androidaps.plugins.pump.eopatch.code.PatchLifecycle
import info.nightscout.androidaps.plugins.pump.eopatch.core.code.PatchAeCode
import info.nightscout.androidaps.plugins.pump.eopatch.event.EventEoPatchAlarm
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import info.nightscout.shared.logging.AAPSLogger
import io.reactivex.rxjava3.core.Maybe
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.disposables.Disposable
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton
@ -109,10 +108,10 @@ class AlarmRegistry @Inject constructor() : IAlarmRegistry {
override fun add(patchAeCodes: Set<PatchAeCode>) {
compositeDisposable.add(
Observable.fromIterable(patchAeCodes)
.filter{patchAeCodeItem -> AlarmCode.findByPatchAeCode(patchAeCodeItem.getAeValue()) != null}
.observeOn(AndroidSchedulers.mainThread())
.filter { aeCodes -> AlarmCode.findByPatchAeCode(aeCodes.getAeValue()) != null }
.flatMapMaybe{aeCodeResponse -> add(AlarmCode.findByPatchAeCode(aeCodeResponse.getAeValue())!!,0L, true)}
.filter{patchAeCodeItem -> AlarmCode.findByPatchAeCode(patchAeCodeItem.aeValue) != null}
.observeOn(aapsSchedulers.main)
.filter { aeCodes -> AlarmCode.findByPatchAeCode(aeCodes.aeValue) != null }
.flatMapMaybe{aeCodeResponse -> add(AlarmCode.findByPatchAeCode(aeCodeResponse.aeValue)!!, 0L, true)}
.subscribe()
)
}

View file

@ -23,8 +23,8 @@ import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchConfig;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchLifecycleEvent;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.TempBasal;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
public interface IPatchManager {
void init();

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.interfaces.ActivePlugin;
import info.nightscout.androidaps.interfaces.CommandQueue;
import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.interfaces.PumpSync;
import info.nightscout.androidaps.interfaces.ResourceHelper;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.eopatch.R;
@ -47,15 +48,13 @@ import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchLifecycleEvent;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.TempBasal;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.sharedPreferences.SP;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;
@Singleton
public class PatchManager implements IPatchManager {
@ -73,6 +72,7 @@ public class PatchManager implements IPatchManager {
@Inject PumpSync pumpSync;
@Inject DateUtil dateUtil;
@Inject RxAction rxAction;
@Inject AapsSchedulers aapsSchedulers;
private IPatchScanner patchScanner;
private final CompositeDisposable mCompositeDisposable = new CompositeDisposable();
@ -104,7 +104,7 @@ public class PatchManager implements IPatchManager {
case CONNECTING:
mConnectingDisposable = Observable.interval(0, 1, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.takeUntil(n -> getPatchConnectionState().isConnected() || n > 10 * 60)
.subscribe(n -> rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTING, n.intValue())));
break;
@ -116,8 +116,8 @@ public class PatchManager implements IPatchManager {
);
mCompositeDisposable.add(rxBus
.toObservable(EventPatchActivationNotComplete.class)
.observeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getIo())
.subscribeOn(aapsSchedulers.getMain())
.subscribe(eventPatchActivationNotComplete -> {
Intent i = new Intent(context, DialogHelperActivity.class);
i.putExtra("title", resourceHelper.gs(R.string.patch_activate_reminder_title));
@ -383,7 +383,7 @@ public class PatchManager implements IPatchManager {
if(pm.getPatchConfig().getInfoReminder() != buzzer) {
if (isActivated()) {
mCompositeDisposable.add(infoReminderSet(buzzer)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.subscribe(patchBooleanResponse -> {
pm.getPatchConfig().setInfoReminder(buzzer);
pm.flushPatchConfig();
@ -403,7 +403,7 @@ public class PatchManager implements IPatchManager {
if(pc.getLowReservoirAlertAmount() != doseUnit || pc.getPatchExpireAlertTime() != hours) {
if (isActivated()) {
mCompositeDisposable.add(setLowReservoir(doseUnit, hours)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.subscribe(patchBooleanResponse -> {
pc.setLowReservoirAlertAmount(doseUnit);
pc.setPatchExpireAlertTime(hours);

View file

@ -10,9 +10,30 @@ import android.content.IntentFilter;
import androidx.annotation.Nullable;
import java.math.BigInteger;
import java.security.AlgorithmParameters;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.ECGenParameterSpec;
import java.security.spec.ECParameterSpec;
import java.security.spec.ECPoint;
import java.security.spec.ECPublicKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.InvalidParameterSpecException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import javax.crypto.KeyAgreement;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.pump.eopatch.EoPatchRxBus;
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmCode;
import info.nightscout.androidaps.plugins.pump.eopatch.ble.task.ActivateTask;
@ -38,10 +59,10 @@ import info.nightscout.androidaps.plugins.pump.eopatch.ble.task.SyncBasalHistory
import info.nightscout.androidaps.plugins.pump.eopatch.ble.task.TaskBase;
import info.nightscout.androidaps.plugins.pump.eopatch.ble.task.TaskFunc;
import info.nightscout.androidaps.plugins.pump.eopatch.ble.task.UpdateConnectionTask;
import info.nightscout.androidaps.plugins.pump.eopatch.core.scan.BleConnectionState;
import info.nightscout.androidaps.plugins.pump.eopatch.core.scan.IBleDevice;
import info.nightscout.androidaps.plugins.pump.eopatch.code.BolusExDuration;
import info.nightscout.androidaps.plugins.pump.eopatch.code.DeactivationStatus;
import info.nightscout.androidaps.plugins.pump.eopatch.code.SettingKeys;
import info.nightscout.androidaps.plugins.pump.eopatch.core.Patch;
import info.nightscout.androidaps.plugins.pump.eopatch.core.scan.PatchSelfTestResult;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.BuzzerStop;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.GetTemperature;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.PublicKeySend;
@ -51,35 +72,18 @@ import info.nightscout.androidaps.plugins.pump.eopatch.core.code.BolusType;
import info.nightscout.androidaps.plugins.pump.eopatch.core.noti.AlarmNotification;
import info.nightscout.androidaps.plugins.pump.eopatch.core.noti.BaseNotification;
import info.nightscout.androidaps.plugins.pump.eopatch.core.noti.InfoNotification;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.*;
import info.nightscout.androidaps.plugins.pump.eopatch.code.BolusExDuration;
import info.nightscout.androidaps.plugins.pump.eopatch.code.DeactivationStatus;
import java.math.BigInteger;
import java.security.AlgorithmParameters;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.ECGenParameterSpec;
import java.security.spec.ECParameterSpec;
import java.security.spec.ECPoint;
import java.security.spec.ECPublicKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.InvalidParameterSpecException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import javax.crypto.KeyAgreement;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.code.SettingKeys;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BasalScheduleSetResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BaseResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BolusResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BolusStopResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.ComboBolusStopResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.KeyResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.PatchBooleanResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.TempBasalScheduleSetResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.TemperatureResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.scan.BleConnectionState;
import info.nightscout.androidaps.plugins.pump.eopatch.core.scan.IBleDevice;
import info.nightscout.androidaps.plugins.pump.eopatch.core.scan.PatchSelfTestResult;
import info.nightscout.androidaps.plugins.pump.eopatch.event.EventEoPatchAlarm;
import info.nightscout.androidaps.plugins.pump.eopatch.ui.receiver.RxBroadcastReceiver;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.BolusCurrent;
@ -87,13 +91,16 @@ import info.nightscout.androidaps.plugins.pump.eopatch.vo.NormalBasal;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchConfig;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.TempBasal;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
import info.nightscout.shared.sharedPreferences.SP;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.Single;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;
@Singleton
public class PatchManagerImpl{
@ -101,6 +108,7 @@ public class PatchManagerImpl{
@Inject Context context;
@Inject SP sp;
@Inject AAPSLogger aapsLogger;
@Inject AapsSchedulers aapsSchedulers;
@Inject StartBondTask START_BOND;
@Inject GetPatchInfoTask GET_PATCH_INFO;
@ -146,17 +154,19 @@ public class PatchManagerImpl{
compositeDisposable.add(
Observable.combineLatest(patch.observeConnected(), pm.observePatchLifeCycle(),
(connected, lifeCycle) -> (connected && lifeCycle.isActivated()))
.subscribeOn(Schedulers.io())
.subscribeOn(aapsSchedulers.getIo())
.filter(ok -> ok)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.doOnNext(v -> TaskBase.enqueue(TaskFunc.UPDATE_CONNECTION))
.retry()
.subscribe());
compositeDisposable.add(
Observable.combineLatest(patch.observeConnected(), pm.observePatchLifeCycle().distinctUntilChanged(), dateTimeChanged.startWith(new Intent()),
Observable.combineLatest(patch.observeConnected(),
pm.observePatchLifeCycle().distinctUntilChanged(),
dateTimeChanged.startWith(Observable.just(new Intent())),
(connected, lifeCycle, value) -> (connected && lifeCycle.isActivated()))
.subscribeOn(Schedulers.io())
.subscribeOn(aapsSchedulers.getIo())
.doOnNext(v -> aapsLogger.debug(LTag.PUMP,"Has the date or time changed? "+v))
.filter(ok -> ok)
.doOnNext(v -> TaskBase.enqueue(TaskFunc.SET_GLOBAL_TIME))
@ -279,7 +289,7 @@ public class PatchManagerImpl{
// synchronized lock
private final Object lock = new Object();
private void updatePatchConfig(Consumer<PatchConfig> consumer, boolean needSave) throws Exception {
private void updatePatchConfig(Consumer<PatchConfig> consumer, boolean needSave) throws Throwable {
synchronized (lock) {
consumer.accept(pm.getPatchConfig());
if (needSave) {
@ -549,7 +559,7 @@ public class PatchManagerImpl{
@Inject
SyncBasalHistoryTask syncBasalHistoryTask;
void onAlarmNotification(AlarmNotification notification) throws Exception {
void onAlarmNotification(AlarmNotification notification) throws Throwable {
patchStateManager.updatePatchState(PatchState.create(notification.patchState, System.currentTimeMillis()));
if (pm.getPatchConfig().isActivated()) {
@ -562,7 +572,7 @@ public class PatchManagerImpl{
}
}
private void onInfoNotification(InfoNotification notification) throws Exception {
private void onInfoNotification(InfoNotification notification) throws Throwable {
readBolusStatusFromNotification(notification);
updateInjected(notification, false);
if (notification.isBolusDone()) {
@ -570,7 +580,7 @@ public class PatchManagerImpl{
}
}
void updateInjected(BaseNotification notification, boolean needSave) throws Exception {
void updateInjected(BaseNotification notification, boolean needSave) throws Throwable {
updatePatchConfig(patchConfig -> {
patchConfig.setInjectCount(notification.getTotalInjected());
patchConfig.setStandardBolusInjectCount(notification.getSB_CNT());

View file

@ -6,6 +6,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.interfaces.CommandQueue;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.pump.eopatch.core.code.BolusType;
@ -17,9 +18,8 @@ import info.nightscout.androidaps.plugins.pump.eopatch.vo.BolusCurrent;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.NormalBasal;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.TempBasal;
import io.reactivex.Maybe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.schedulers.Schedulers;
@Singleton
@ -32,6 +32,7 @@ public class PatchStateManager {
@Inject FetchAlarmTask FETCH_ALARM;
@Inject CommandQueue commandQueue;
@Inject AAPSLogger aapsLogger;
@Inject AapsSchedulers aapsSchedulers;
@Inject
public PatchStateManager() {
@ -41,7 +42,7 @@ public class PatchStateManager {
public synchronized void updatePatchState(PatchState newState) {
Maybe.fromCallable(() -> newState).observeOn(Schedulers.single())
.doOnSuccess(patchState -> updatePatchStateInner(patchState))
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.doOnSuccess(patchState -> aapsLogger.debug(LTag.PUMP, patchState.toString()))
.subscribe();
}

View file

@ -8,7 +8,7 @@ import info.nightscout.androidaps.plugins.pump.eopatch.code.SettingKeys
import info.nightscout.androidaps.plugins.pump.eopatch.code.PatchLifecycle
import info.nightscout.androidaps.plugins.pump.eopatch.vo.*
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.Observable
import io.reactivex.rxjava3.core.Observable
import javax.inject.Inject
import javax.inject.Singleton

View file

@ -9,8 +9,8 @@ import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.NormalBasal;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchLifecycleEvent;
import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;
@Singleton
public class ActivateTask extends TaskBase {

View file

@ -1,27 +1,27 @@
package info.nightscout.androidaps.plugins.pump.eopatch.ble.task;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager;
import info.nightscout.androidaps.plugins.pump.eopatch.core.code.BolusType;
import info.nightscout.androidaps.plugins.pump.eopatch.code.DeactivationStatus;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager;
import info.nightscout.androidaps.plugins.pump.eopatch.code.DeactivationStatus;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.DeActivation;
import info.nightscout.androidaps.plugins.pump.eopatch.core.code.BolusType;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.BolusCurrent;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchLifecycleEvent;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.TempBasal;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.shared.logging.LTag;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class DeactivateTask extends TaskBase {
@Inject StopBasalTask stopBasalTask;
@Inject IPreferenceManager pm;
@Inject AapsSchedulers aapsSchedulers;
private final DeActivation DEACTIVATION;
@ -37,7 +37,7 @@ public class DeactivateTask extends TaskBase {
.concatMapSingle(v ->
DEACTIVATION.start()
.doOnSuccess(this::checkResponse)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.doOnSuccess(response -> onDeactivated()))
.map(response -> DeactivationStatus.of(response.isSuccess(), forced))
.firstOrError()

View file

@ -11,7 +11,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.AeCodeResponse;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class FetchAlarmTask extends TaskBase {

View file

@ -21,8 +21,8 @@ import java.util.Arrays;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;
@Singleton
public class GetPatchInfoTask extends TaskBase {

View file

@ -10,7 +10,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class InfoReminderTask extends TaskBase {

View file

@ -18,9 +18,9 @@ import info.nightscout.androidaps.plugins.pump.eopatch.core.response.PatchIntern
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
@Singleton
public class InternalSuspendedTask extends BolusTask {
@ -64,7 +64,7 @@ public class InternalSuspendedTask extends BolusTask {
if (commandQueue.isRunning(Command.CommandType.BOLUS)) {
uel.log(UserEntryMapper.Action.CANCEL_BOLUS, UserEntryMapper.Sources.EOPatch2);
commandQueue.cancelAllBoluses();
commandQueue.cancelAllBoluses(null);
SystemClock.sleep(650);
}
bolusCheckSubject.onNext(true);

View file

@ -9,7 +9,7 @@ import info.nightscout.androidaps.plugins.pump.eopatch.core.api.StartNeedleCheck
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.UpdateConnection;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState;
import info.nightscout.shared.logging.LTag;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class NeedleSensingTask extends TaskBase {

View file

@ -23,9 +23,9 @@ import info.nightscout.androidaps.plugins.pump.eopatch.core.api.BasalPause;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.PatchBooleanResponse;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
@Singleton
public class PauseBasalTask extends BolusTask {
@ -71,7 +71,7 @@ public class PauseBasalTask extends BolusTask {
if (commandQueue.isRunning(Command.CommandType.BOLUS)) {
uel.log(UserEntryMapper.Action.CANCEL_BOLUS, UserEntryMapper.Sources.EOPatch2);
commandQueue.cancelAllBoluses();
commandQueue.cancelAllBoluses(null);
SystemClock.sleep(650);
}
bolusCheckSubject.onNext(true);

View file

@ -10,7 +10,7 @@ import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.StartPriming;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.UpdateConnection;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState;
import io.reactivex.Observable;
import io.reactivex.rxjava3.core.Observable;
@Singleton
public class PrimingTask extends TaskBase {

View file

@ -11,7 +11,7 @@ import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BolusFinish
import info.nightscout.androidaps.plugins.pump.eopatch.core.code.BolusType;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.BolusCurrent;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class ReadBolusFinishTimeTask extends BolusTask {

View file

@ -9,7 +9,7 @@ import javax.inject.Singleton;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.TempBasalFinishTimeGet;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.TempBasalFinishTimeResponse;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class ReadTempBasalFinishTimeTask extends TaskBase {

View file

@ -14,7 +14,7 @@ import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.PatchBooleanResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.NormalBasal;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class ResumeBasalTask extends TaskBase {

View file

@ -14,7 +14,7 @@ import java.util.Arrays;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class SelfTestTask extends TaskBase {

View file

@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class SetGlobalTimeTask extends TaskBase {

View file

@ -10,7 +10,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class SetLowReservoirTask extends TaskBase {

View file

@ -10,7 +10,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
import static info.nightscout.androidaps.plugins.pump.eopatch.core.api.StartBonding.OPTION_NUMERIC;

View file

@ -9,7 +9,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BolusResponse;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class StartCalcBolusTask extends BolusTask {

View file

@ -1,25 +1,22 @@
package info.nightscout.androidaps.plugins.pump.eopatch.ble.task;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.pump.eopatch.ble.PatchStateManager;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.BasalScheduleSetBig;
import java.sql.SQLException;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.ble.PatchStateManager;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.BasalScheduleSetBig;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BasalScheduleSetResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.NormalBasal;
import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.shared.logging.LTag;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class StartNormalBasalTask extends TaskBase {
private final BasalScheduleSetBig BASAL_SCHEDULE_SET_BIG;
@Inject
PatchStateManager patchStateManager;
@Inject PatchStateManager patchStateManager;
@Inject AapsSchedulers aapsSchedulers;
@Inject
public StartNormalBasalTask() {
@ -34,7 +31,7 @@ public class StartNormalBasalTask extends TaskBase {
public Single<BasalScheduleSetResponse> startJob(NormalBasal basal) {
return BASAL_SCHEDULE_SET_BIG.set(basal.getDoseUnitPerSegmentArray())
.doOnSuccess(this::checkResponse)
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.doOnSuccess(v -> onStartNormalBasalResponse(v, basal))
.doOnError(e -> aapsLogger.error(LTag.PUMPCOMM, (e.getMessage() != null) ? e.getMessage() : "StartNormalBasalTask error"));
}

View file

@ -11,7 +11,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BolusResponse;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class StartQuickBolusTask extends BolusTask {

View file

@ -1,20 +1,21 @@
package info.nightscout.androidaps.plugins.pump.eopatch.ble.task;
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.TempBasalScheduleStart;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.TempBasalScheduleStart;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.TempBasalScheduleSetResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.vo.TempBasal;
import io.reactivex.Single;
import io.reactivex.schedulers.Schedulers;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.shared.logging.LTag;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class StartTempBasalTask extends TaskBase {
@Inject IPreferenceManager pm;
@Inject AapsSchedulers aapsSchedulers;
private final TempBasalScheduleStart TEMP_BASAL_SCHEDULE_START;
@Inject
@ -29,7 +30,7 @@ public class StartTempBasalTask extends TaskBase {
.concatMapSingle(v -> TEMP_BASAL_SCHEDULE_START.start(tempBasal.getDurationMinutes(), tempBasal.getDoseUnitPerHour(), tempBasal.getPercent()))
.doOnNext(this::checkResponse)
.firstOrError()
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.doOnSuccess(v -> onTempBasalStarted(tempBasal))
.doOnError(e -> aapsLogger.error(LTag.PUMPCOMM, (e.getMessage() != null) ? e.getMessage() : "StartTempBasalTask error"));
}

View file

@ -19,9 +19,9 @@ import info.nightscout.androidaps.interfaces.CommandQueue;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
@Singleton
public class StopBasalTask extends TaskBase {
@ -59,7 +59,7 @@ public class StopBasalTask extends TaskBase {
if (commandQueue.isRunning(Command.CommandType.BOLUS)) {
uel.log(UserEntryMapper.Action.CANCEL_BOLUS, UserEntryMapper.Sources.EOPatch2);
commandQueue.cancelAllBoluses();
commandQueue.cancelAllBoluses(null);
SystemClock.sleep(650);
}
bolusCheckSubject.onNext(true);

View file

@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class StopComboBolusTask extends BolusTask {

View file

@ -10,7 +10,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class StopExtBolusTask extends BolusTask {

View file

@ -1,22 +1,23 @@
package info.nightscout.androidaps.plugins.pump.eopatch.ble.task;
import info.nightscout.shared.logging.LTag;
import info.nightscout.androidaps.plugins.pump.eopatch.core.define.IPatchConstant;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.BolusStop;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BolusStopResponse;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.BolusStop;
import info.nightscout.androidaps.plugins.pump.eopatch.core.define.IPatchConstant;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BolusStopResponse;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.shared.logging.LTag;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class StopNowBolusTask extends BolusTask {
private final BolusStop BOLUS_STOP;
@Inject AapsSchedulers aapsSchedulers;
@Inject
public StopNowBolusTask() {
super(TaskFunc.STOP_NOW_BOLUS);
@ -25,7 +26,7 @@ public class StopNowBolusTask extends BolusTask {
public Single<BolusStopResponse> stop() {
return isReady()
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.getMain())
.concatMapSingle(v -> stopJob()).firstOrError()
.doOnError(e -> aapsLogger.error(LTag.PUMPCOMM, (e.getMessage() != null) ? e.getMessage() : "StopNowBolusTask error"));
}

View file

@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class StopTempBasalTask extends TaskBase {

View file

@ -12,7 +12,7 @@ import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BasalHistoryIndexResponse;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BasalHistoryResponse;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
import static info.nightscout.androidaps.plugins.pump.eopatch.core.define.IPatchConstant.BASAL_HISTORY_SIZE_BIG;

View file

@ -14,8 +14,8 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.shared.logging.AAPSLogger;
import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.disposables.Disposable;
@Singleton
public class TaskBase {

View file

@ -7,15 +7,16 @@ import java.util.Queue;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
@Singleton
public class TaskQueue {
@Inject AAPSLogger aapsLogger;
@Inject AapsSchedulers aapsSchedulers;
Queue<PatchTask> queue = new LinkedList<>();
@ -37,7 +38,7 @@ public class TaskQueue {
.takeUntil(it -> it.number > v)
.filter(it -> it.number == v))
.doOnNext(v -> aapsLogger.debug(LTag.PUMPCOMM, String.format("Task #:%s started func:%s", v.number, v.func.name())))
.observeOn(Schedulers.io())
.observeOn(aapsSchedulers.getIo())
.map(it -> it.func)
.doFinally(this::done);
}

View file

@ -11,7 +11,7 @@ import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.pump.eopatch.core.api.UpdateConnection;
import info.nightscout.androidaps.plugins.pump.eopatch.core.response.UpdateConnectionResponse;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Single;
@Singleton
public class UpdateConnectionTask extends TaskBase {

View file

@ -2,10 +2,10 @@ package info.nightscout.androidaps.plugins.pump.eopatch.extension
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
fun <T> Observable<T>.observeOnMainThread(): Observable<T> = observeOn(AndroidSchedulers.mainThread())

View file

@ -2,10 +2,10 @@ package info.nightscout.androidaps.plugins.pump.eopatch.extension
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
fun <T> Single<T>.subscribeDefault(aapsLogger: AAPSLogger, onSuccess: (T) -> Unit): Disposable = subscribe(onSuccess, {
aapsLogger.error(LTag.PUMP, "onError", it)

View file

@ -10,14 +10,15 @@ import info.nightscout.androidaps.plugins.pump.eopatch.event.EventDialog
import info.nightscout.androidaps.plugins.pump.eopatch.event.EventProgressDialog
import info.nightscout.androidaps.plugins.pump.eopatch.ui.dialogs.AlarmDialog
import info.nightscout.androidaps.plugins.pump.eopatch.ui.dialogs.ProgressDialogHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxjava3.disposables.CompositeDisposable
import javax.inject.Inject
class AlarmHelperActivity : DialogAppCompatActivity() {
@Inject lateinit var sp : SP
@Inject lateinit var rxBus: RxBus
@Inject lateinit var aapsSchedulers: AapsSchedulers
private var disposable: CompositeDisposable = CompositeDisposable()
private var mProgressDialog: AlertDialog? = null
@ -42,7 +43,7 @@ class AlarmHelperActivity : DialogAppCompatActivity() {
disposable.add(rxBus
.toObservable(EventProgressDialog::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
if(it.show){
showProgressDialog(it.resId)
@ -54,7 +55,7 @@ class AlarmHelperActivity : DialogAppCompatActivity() {
disposable.add(rxBus
.toObservable(EventDialog::class.java)
.observeOn(AndroidSchedulers.mainThread())
.observeOn(aapsSchedulers.main)
.subscribe({
if(it.show) it.dialog.show(supportFragmentManager, "")
}, { })

View file

@ -13,10 +13,8 @@ import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.plugins.pump.eopatch.dagger.EopatchPluginQualifier
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.rxjava3.disposables.CompositeDisposable
import javax.inject.Inject
import io.reactivex.rxkotlin.addTo
abstract class EoBaseActivity<B : ViewDataBinding> : NoSplashAppCompatActivity(), EoBaseNavigator {
@Inject
@ -66,6 +64,4 @@ abstract class EoBaseActivity<B : ViewDataBinding> : NoSplashAppCompatActivity()
finish()
}
}
fun Disposable.addTo() = addTo(compositeDisposable)
}

View file

@ -12,10 +12,8 @@ import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.plugins.pump.eopatch.dagger.EopatchPluginQualifier
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.rxjava3.disposables.CompositeDisposable
import javax.inject.Inject
import io.reactivex.rxkotlin.addTo
abstract class EoBaseFragment<B : ViewDataBinding> : DaggerFragment(), EoBaseNavigator {
@Inject
@ -73,7 +71,4 @@ abstract class EoBaseFragment<B : ViewDataBinding> : DaggerFragment(), EoBaseNav
override fun finish(finishAffinity: Boolean) {
baseActivity?.finish(finishAffinity)
}
fun Disposable.addTo() = addTo(compositeDisposable)
}

View file

@ -20,7 +20,7 @@ import info.nightscout.androidaps.plugins.pump.eopatch.extension.takeOne
import info.nightscout.androidaps.plugins.pump.eopatch.ui.viewmodel.EopatchOverviewViewModel
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.rxjava3.disposables.CompositeDisposable
import javax.inject.Inject
class EopatchOverviewFragment: EoBaseFragment<FragmentEopatchOverviewBinding>() {

View file

@ -4,13 +4,16 @@ import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.view.*
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.core.R
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmProcess
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmCode
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmProcess
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.IAlarmProcess
import info.nightscout.androidaps.plugins.pump.eopatch.bindingadapters.setOnSafeClickListener
import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPatchManager
@ -19,8 +22,8 @@ import info.nightscout.androidaps.plugins.pump.eopatch.ui.AlarmHelperActivity
import info.nightscout.androidaps.services.AlarmSoundServiceHelper
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import info.nightscout.shared.logging.AAPSLogger
import io.reactivex.rxjava3.disposables.Disposable
import javax.inject.Inject
class AlarmDialog : DaggerDialogFragment() {
@ -79,7 +82,7 @@ class AlarmDialog : DaggerDialogFragment() {
aapsLogger.debug("USER ENTRY: Alarm dialog ok button pressed")
alarmCode?.let { ac ->
mAlarmProcess.doAction(requireContext(), ac)
.subscribeOn(Schedulers.io())
.subscribeOn(aapsSchedulers.io)
.subscribe ({ ret ->
aapsLogger.debug("Alarm processing result :${ret}")
if (ret == IAlarmProcess.ALARM_HANDLED) {
@ -92,25 +95,25 @@ class AlarmDialog : DaggerDialogFragment() {
isHolding = true
}else if (ret == IAlarmProcess.ALARM_UNHANDLED) {
if(!isMute){
startAlarm()
startAlarm("ALARM_UNHANDLED")
}
}
}, { t -> aapsLogger.error("${t.printStackTrace()}") })
}
stopAlarm()
stopAlarm("OK clicked")
}
binding.mute.setOnSafeClickListener {
aapsLogger.debug("USER ENTRY: Error dialog mute button pressed")
isMute = true
stopAlarm()
stopAlarm("Mute clicked")
}
binding.mute5min.setOnSafeClickListener {
aapsLogger.debug("USER ENTRY: Error dialog mute 5 min button pressed")
stopAlarm()
stopAlarm("Mute5m clicked")
isMute = true
handler.postDelayed(this::startAlarm, T.mins(5).msecs())
handler.postDelayed({ startAlarm("post") }, T.mins(5).msecs())
}
startAlarm()
startAlarm("onViewCreated")
disposable = patchManager.observePatchLifeCycle()
.observeOn(aapsSchedulers.main)
@ -137,7 +140,7 @@ class AlarmDialog : DaggerDialogFragment() {
override fun onResume() {
super.onResume()
if(isHolding && !isMute){
startAlarm()
startAlarm("onResume")
}
binding.status.text = status
}
@ -155,17 +158,17 @@ class AlarmDialog : DaggerDialogFragment() {
helperActivity?.finish()
}
private fun startAlarm() {
private fun startAlarm(reason: String) {
if (sound != 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context?.let { context -> alarmSoundServiceHelper.startAlarm(context, sound) }
context?.let { context -> alarmSoundServiceHelper.startAlarm(context, sound, reason) }
}
}
}
private fun stopAlarm() {
private fun stopAlarm(reason: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context?.let { context -> alarmSoundServiceHelper.stopService(context) }
context?.let { context -> alarmSoundServiceHelper.stopService(context, reason) }
}
}
}

View file

@ -5,9 +5,9 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.annotation.CheckResult
import io.reactivex.android.MainThreadDisposable
import io.reactivex.Observable
import io.reactivex.Observer
import io.reactivex.rxjava3.android.MainThreadDisposable
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Observer
class RxBroadcastReceiver private constructor() {
internal class BroadcastReceiverObservable : Observable<Intent> {

View file

@ -2,9 +2,8 @@ package info.nightscout.androidaps.plugins.pump.eopatch.ui.viewmodel
import androidx.lifecycle.ViewModel
import info.nightscout.androidaps.plugins.pump.eopatch.ui.EoBaseNavigator
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.rxkotlin.addTo
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.disposables.Disposable
import java.lang.ref.WeakReference
abstract class EoBaseViewModel<N : EoBaseNavigator> : ViewModel() {
@ -27,6 +26,6 @@ abstract class EoBaseViewModel<N : EoBaseNavigator> : ViewModel() {
fun finish() = navigator?.finish()
fun Disposable.addTo() = addTo(compositeDisposable)
fun Disposable.addTo() = apply { compositeDisposable.add(this) }
}

View file

@ -15,10 +15,10 @@ import info.nightscout.androidaps.plugins.pump.eopatch.ui.event.UIEvent
import info.nightscout.androidaps.plugins.pump.eopatch.vo.Alarms
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchConfig
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import io.reactivex.Observable
import io.reactivex.disposables.Disposable
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import java.util.*
import java.util.concurrent.TimeUnit
import javax.inject.Inject

View file

@ -28,15 +28,15 @@ import info.nightscout.androidaps.plugins.pump.eopatch.ui.viewmodel.EopatchViewM
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchConfig
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchLifecycleEvent
import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.disposables.Disposable
import io.reactivex.subjects.PublishSubject
import io.reactivex.rxjava3.core.Maybe
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.subjects.PublishSubject
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import javax.inject.Inject

View file

@ -4,8 +4,8 @@ import info.nightscout.androidaps.plugins.pump.eopatch.GsonHelper
import info.nightscout.androidaps.plugins.pump.eopatch.alarm.AlarmCode
import info.nightscout.androidaps.plugins.pump.eopatch.code.SettingKeys
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.BehaviorSubject
import java.util.*
class Alarms: IPreference<Alarms> {

View file

@ -6,8 +6,8 @@ import info.nightscout.androidaps.plugins.pump.eopatch.core.code.BolusType
import info.nightscout.androidaps.plugins.pump.eopatch.core.util.FloatAdjusters
import info.nightscout.androidaps.plugins.pump.eopatch.code.SettingKeys
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.BehaviorSubject
/**
* 볼루스 주입 형태 2가지 모드

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.plugins.pump.eopatch.vo
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.Observable
import io.reactivex.rxjava3.core.Observable
interface IPreference<T>{
fun flush(sp: SP)

View file

@ -6,8 +6,8 @@ import info.nightscout.androidaps.plugins.pump.eopatch.GsonHelper
import info.nightscout.androidaps.plugins.pump.eopatch.code.SettingKeys
import info.nightscout.androidaps.plugins.pump.eopatch.code.BasalStatus
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.BehaviorSubject
import java.util.concurrent.TimeUnit
class NormalBasalManager : IPreference<NormalBasalManager> {

View file

@ -9,8 +9,8 @@ import info.nightscout.androidaps.plugins.pump.eopatch.core.define.IPatchConstan
import info.nightscout.androidaps.plugins.pump.eopatch.code.SettingKeys
import info.nightscout.androidaps.plugins.pump.eopatch.code.PatchLifecycle
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.BehaviorSubject
import java.util.concurrent.TimeUnit
// @Singleton

View file

@ -6,8 +6,8 @@ import info.nightscout.androidaps.plugins.pump.eopatch.core.code.BolusType
import info.nightscout.androidaps.plugins.pump.eopatch.core.util.FloatAdjusters
import info.nightscout.androidaps.plugins.pump.eopatch.code.SettingKeys
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.BehaviorSubject
import java.io.Serializable
import java.text.SimpleDateFormat
import java.util.*

View file

@ -6,8 +6,8 @@ import info.nightscout.androidaps.plugins.pump.eopatch.GsonHelper
import info.nightscout.androidaps.plugins.pump.eopatch.code.SettingKeys
import info.nightscout.androidaps.plugins.pump.eopatch.code.UnitOrPercent
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.Observable
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.BehaviorSubject
class TempBasalManager : IPreference<TempBasalManager>{
@Transient

View file

@ -1,18 +0,0 @@
package info.nightscout.androidaps.plugins.pump.eopatch
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}