lints, cleanup

This commit is contained in:
Milos Kozak 2023-07-15 11:21:29 +02:00
parent e3207405e8
commit fc1a471412
2 changed files with 33 additions and 30 deletions

View file

@ -22,7 +22,6 @@ import info.nightscout.interfaces.notifications.Notification
import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
@ -51,7 +50,6 @@ interface IAlarmManager {
class AlarmManager @Inject constructor() : IAlarmManager { class AlarmManager @Inject constructor() : IAlarmManager {
@Inject lateinit var patchManager: IPatchManager @Inject lateinit var patchManager: IPatchManager
@Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var activePlugin: ActivePlugin
@Inject lateinit var commandQueue: CommandQueue
@Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var rxBus: RxBus @Inject lateinit var rxBus: RxBus
@ -71,6 +69,7 @@ class AlarmManager @Inject constructor() : IAlarmManager {
private var compositeDisposable: CompositeDisposable = CompositeDisposable() private var compositeDisposable: CompositeDisposable = CompositeDisposable()
private var alarmDisposable: Disposable? = null private var alarmDisposable: Disposable? = null
@Suppress("unused")
@Inject @Inject
fun onInit() { fun onInit() {
mAlarmProcess = AlarmProcess(patchManager, rxBus) mAlarmProcess = AlarmProcess(patchManager, rxBus)
@ -150,7 +149,7 @@ class AlarmManager @Inject constructor() : IAlarmManager {
context.startActivity(i) context.startActivity(i)
} }
private fun showNotification(alarmCode: AlarmCode, timeOffset: Long = 0L) { private fun showNotification(alarmCode: AlarmCode) {
var alarmMsg = resourceHelper.gs(alarmCode.resId) var alarmMsg = resourceHelper.gs(alarmCode.resId)
if (alarmCode == B000) { if (alarmCode == B000) {
val expireTimeValue = pm.getPatchWakeupTimestamp() + TimeUnit.HOURS.toMillis(84) val expireTimeValue = pm.getPatchWakeupTimestamp() + TimeUnit.HOURS.toMillis(84)
@ -171,7 +170,8 @@ class AlarmManager @Inject constructor() : IAlarmManager {
else Single.just(IAlarmProcess.ALARM_HANDLED) else Single.just(IAlarmProcess.ALARM_HANDLED)
} }
.subscribe { ret -> .subscribe { ret ->
if (ret == IAlarmProcess.ALARM_HANDLED) { when (ret) {
IAlarmProcess.ALARM_HANDLED -> {
if (alarmCode == B001) { if (alarmCode == B001) {
pumpSync.syncStopTemporaryBasalWithPumpId( pumpSync.syncStopTemporaryBasalWithPumpId(
timestamp = dateUtil.now(), timestamp = dateUtil.now(),
@ -181,11 +181,14 @@ class AlarmManager @Inject constructor() : IAlarmManager {
) )
} }
updateState(alarmCode, AlarmState.HANDLE) updateState(alarmCode, AlarmState.HANDLE)
}else if(ret == IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP){ }
IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP -> {
pm.getAlarms().needToStopBeep.add(alarmCode) pm.getAlarms().needToStopBeep.add(alarmCode)
updateState(alarmCode, AlarmState.HANDLE) updateState(alarmCode, AlarmState.HANDLE)
} else { }
showNotification(alarmCode)
else -> showNotification(alarmCode)
} }
} }
) )

View file

@ -71,7 +71,7 @@ class AlarmProcess(val patchManager: IPatchManager, val rxBus: RxBus) : IAlarmPr
A007 -> inappropriateTemperatureAction(context) A007 -> inappropriateTemperatureAction(context)
A016 -> needleInsertionErrorAction(context) A016 -> needleInsertionErrorAction(context)
B000 -> Single.just(IAlarmProcess.ALARM_HANDLED) B000 -> Single.just(IAlarmProcess.ALARM_HANDLED)
B003, B005, B006, B018 -> stopAeBeepAction(context, code) B003, B005, B006, B018 -> stopAeBeepAction(code)
B012 -> Single.just(IAlarmProcess.ALARM_HANDLED) B012 -> Single.just(IAlarmProcess.ALARM_HANDLED)
} }
} }
@ -152,14 +152,14 @@ class AlarmProcess(val patchManager: IPatchManager, val rxBus: RxBus) : IAlarmPr
} }
} }
private fun stopAeBeepAction(context: Context, alarm: AlarmCode): Single<Int> { private fun stopAeBeepAction(alarm: AlarmCode): Single<Int> {
if (patchManager.patchConnectionState.isConnected) { return if (patchManager.patchConnectionState.isConnected) {
return patchManager.stopAeBeep(alarm.aeCode) patchManager.stopAeBeep(alarm.aeCode)
.map { obj: PatchBooleanResponse -> obj.isSuccess } .map { obj: PatchBooleanResponse -> obj.isSuccess }
.onErrorReturn { false } .onErrorReturn { false }
.flatMap { Single.just(it.takeOne(IAlarmProcess.ALARM_HANDLED, IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP)) } .flatMap { Single.just(it.takeOne(IAlarmProcess.ALARM_HANDLED, IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP)) }
} else { } else {
return Single.just(IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP) Single.just(IAlarmProcess.ALARM_HANDLED_BUT_NEED_STOP_BEEP)
} }
} }
} }