ktlint. update ktlint gradle plugin

This commit is contained in:
Andrei Vereha 2021-07-11 20:11:46 +02:00
parent 9a009d2f96
commit f289cd50c5
10 changed files with 78 additions and 77 deletions

View file

@ -63,7 +63,7 @@ buildscript {
plugins { plugins {
id "io.gitlab.arturbosch.detekt" version "1.16.0-RC2" id "io.gitlab.arturbosch.detekt" version "1.16.0-RC2"
id "org.jlleitschuh.gradle.ktlint" version "9.4.1" id "org.jlleitschuh.gradle.ktlint" version "10.1.0"
} }
allprojects { allprojects {

View file

@ -53,7 +53,6 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.concurrent.thread import kotlin.concurrent.thread
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.exp
import kotlin.random.Random import kotlin.random.Random
@Singleton @Singleton
@ -75,7 +74,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
@Volatile var bolusCanceled = false @Volatile var bolusCanceled = false
private val handler: Handler = Handler(Looper.getMainLooper()) private val handler: Handler = Handler(Looper.getMainLooper())
private lateinit var statusChecker: Runnable private lateinit var statusChecker: Runnable
var nextPodWarningCheck : Long = 0 var nextPodWarningCheck: Long = 0
@Volatile var stopConnecting: CountDownLatch? = null @Volatile var stopConnecting: CountDownLatch? = null
companion object { companion object {
@ -99,7 +98,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
statusChecker = Runnable { statusChecker = Runnable {
refreshStatusOnUnacknowledgedCommands() refreshStatusOnUnacknowledgedCommands()
updatePodWarnings() updatePodWarnings()
// createFakeTBRWhenNoActivePod() // createFakeTBRWhenNoActivePod()
// TODO: this is called from the main thread // TODO: this is called from the main thread
handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS) handler.postDelayed(statusChecker, STATUS_CHECK_INTERVAL_MS)
} }
@ -109,7 +108,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
if (!podStateManager.isPodRunning) { if (!podStateManager.isPodRunning) {
val expectedState = pumpSync.expectedPumpState() val expectedState = pumpSync.expectedPumpState()
val tbr = expectedState.temporaryBasal val tbr = expectedState.temporaryBasal
if (tbr == null || tbr.rate!=0.0) { if (tbr == null || tbr.rate != 0.0) {
aapsLogger.info(LTag.PUMP, "createFakeTBRWhenNoActivePod") aapsLogger.info(LTag.PUMP, "createFakeTBRWhenNoActivePod")
pumpSync.syncTemporaryBasalWithPumpId( pumpSync.syncTemporaryBasalWithPumpId(
timestamp = System.currentTimeMillis(), timestamp = System.currentTimeMillis(),
@ -147,7 +146,17 @@ class OmnipodDashPumpPlugin @Inject constructor(
rxBus.send(EventNewNotification(notification)) rxBus.send(EventNewNotification(notification))
} else { } else {
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED)) rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED))
// TODO: time out of sync notification? if (!TimeZone.getDefault().equals(podStateManager.timeZone)) {
val notification =
Notification(
Notification.OMNIPOD_TIME_OUT_OF_SYNC,
"Timezone on pod is different from the timezone on phone. " +
"Basal rate is incorrect" +
"Switch profile to fix",
Notification.NORMAL
)
rxBus.send(EventNewNotification(notification))
}
} }
} }
nextPodWarningCheck = DateTimeUtil.getTimeInFutureFromMinutes(15) nextPodWarningCheck = DateTimeUtil.getTimeInFutureFromMinutes(15)
@ -158,7 +167,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
if (podStateManager.isPodRunning && if (podStateManager.isPodRunning &&
podStateManager.activeCommand != null && podStateManager.activeCommand != null &&
commandQueue.size() == 0 && commandQueue.size() == 0 &&
commandQueue.performing() == null) { commandQueue.performing() == null
) {
commandQueue.readStatus("Unconfirmed command", null) commandQueue.readStatus("Unconfirmed command", null)
} }
} }
@ -180,7 +190,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
override fun isConnected(): Boolean { override fun isConnected(): Boolean {
return !podStateManager.isPodRunning || return !podStateManager.isPodRunning ||
podStateManager.bluetoothConnectionState == OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTED podStateManager.bluetoothConnectionState == OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTED
} }
override fun isConnecting(): Boolean { override fun isConnecting(): Boolean {

View file

@ -16,7 +16,7 @@ interface OmnipodDashBleManager {
fun getStatus(): ConnectionState fun getStatus(): ConnectionState
// used for sync connections // used for sync connections
fun connect(timeoutMs: Long = Connection.BASE_CONNECT_TIMEOUT_MS*3): Observable<PodEvent> fun connect(timeoutMs: Long = Connection.BASE_CONNECT_TIMEOUT_MS * 3): Observable<PodEvent>
// used for async connections // used for async connections
fun connect(stopConnectionLatch: CountDownLatch): Observable<PodEvent> fun connect(stopConnectionLatch: CountDownLatch): Observable<PodEvent>

View file

@ -114,40 +114,40 @@ class OmnipodDashBleManagerImpl @Inject constructor(
private fun connect(connectionWaitCond: ConnectionWaitCondition): Observable<PodEvent> = Observable private fun connect(connectionWaitCond: ConnectionWaitCondition): Observable<PodEvent> = Observable
.create { .create {
emitter -> emitter ->
if (!busy.compareAndSet(false, true)) { if (!busy.compareAndSet(false, true)) {
throw BusyException() throw BusyException()
}
try {
emitter.onNext(PodEvent.BluetoothConnecting)
val podAddress =
podState.bluetoothAddress
?: throw FailedToConnectException("Missing bluetoothAddress, activate the pod first")
val podDevice = bluetoothAdapter.getRemoteDevice(podAddress)
val conn = connection
?: Connection(podDevice, aapsLogger, context, podState)
connection = conn
if (conn.connectionState() is Connected && conn.session != null) {
emitter.onNext(PodEvent.AlreadyConnected(podAddress))
emitter.onComplete()
return@create
} }
try {
emitter.onNext(PodEvent.BluetoothConnecting)
conn.connect(connectionWaitCond) val podAddress =
podState.bluetoothAddress
?: throw FailedToConnectException("Missing bluetoothAddress, activate the pod first")
val podDevice = bluetoothAdapter.getRemoteDevice(podAddress)
val conn = connection
?: Connection(podDevice, aapsLogger, context, podState)
connection = conn
if (conn.connectionState() is Connected && conn.session != null) {
emitter.onNext(PodEvent.AlreadyConnected(podAddress))
emitter.onComplete()
return@create
}
emitter.onNext(PodEvent.BluetoothConnected(podAddress)) conn.connect(connectionWaitCond)
emitter.onNext(PodEvent.EstablishingSession)
establishSession(1.toByte())
emitter.onNext(PodEvent.Connected)
emitter.onComplete() emitter.onNext(PodEvent.BluetoothConnected(podAddress))
} catch (ex: Exception) { emitter.onNext(PodEvent.EstablishingSession)
disconnect() establishSession(1.toByte())
emitter.tryOnError(ex) emitter.onNext(PodEvent.Connected)
} finally {
busy.set(false) emitter.onComplete()
} catch (ex: Exception) {
disconnect()
emitter.tryOnError(ex)
} finally {
busy.set(false)
}
} }
}
private fun establishSession(msgSeq: Byte) { private fun establishSession(msgSeq: Byte) {
val conn = assertConnected() val conn = assertConnected()

View file

@ -24,15 +24,14 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state.OmnipodDashPodStateManager
import java.lang.IllegalArgumentException import java.lang.IllegalArgumentException
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
import kotlin.math.absoluteValue
sealed class ConnectionState sealed class ConnectionState
object Connecting: ConnectionState() object Connecting : ConnectionState()
object Connected : ConnectionState() object Connected : ConnectionState()
object NotConnected : ConnectionState() object NotConnected : ConnectionState()
data class ConnectionWaitCondition(var timeoutMs: Long?=null, val stopConnection: CountDownLatch?=null) { data class ConnectionWaitCondition(var timeoutMs: Long? = null, val stopConnection: CountDownLatch? = null) {
init { init {
if (timeoutMs == null && stopConnection == null) { if (timeoutMs == null && stopConnection == null) {
throw IllegalArgumentException("One of timeoutMs or stopConnection has to be non null") throw IllegalArgumentException("One of timeoutMs or stopConnection has to be non null")
@ -68,8 +67,8 @@ class Connection(
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING
val autoConnect = false val autoConnect = false
val gatt = gattConnection ?: val gatt = gattConnection
podDevice.connectGatt(context, autoConnect, bleCommCallbacks, BluetoothDevice.TRANSPORT_LE) ?: podDevice.connectGatt(context, autoConnect, bleCommCallbacks, BluetoothDevice.TRANSPORT_LE)
gattConnection = gatt gattConnection = gatt
if (!gatt.connect()) { if (!gatt.connect()) {
throw FailedToConnectException("connect() returned false") throw FailedToConnectException("connect() returned false")

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session
import info.nightscout.androidaps.extensions.toHex import info.nightscout.androidaps.extensions.toHex
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.MessageIOException import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.exceptions.MessageIOException
import java.util.* import java.util.*

View file

@ -11,7 +11,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.StringLengthPrefixEncoding.Companion.parseKeys import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.StringLengthPrefixEncoding.Companion.parseKeys
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.base.Command
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.Response import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.Response
import kotlin.reflect.KClass
sealed class CommandSendResult sealed class CommandSendResult
object CommandSendSuccess : CommandSendResult() object CommandSendSuccess : CommandSendResult()
@ -113,10 +112,10 @@ class Session(
// TODO verify length // TODO verify length
//val uniqueId = data.copyOfRange(0, 4) // val uniqueId = data.copyOfRange(0, 4)
//val lenghtAndSequenceNumber = data.copyOfRange(4, 6) // val lenghtAndSequenceNumber = data.copyOfRange(4, 6)
val payload = data.copyOfRange(6, data.size - 2) val payload = data.copyOfRange(6, data.size - 2)
//val crc = data.copyOfRange(data.size - 2, data.size) // val crc = data.copyOfRange(data.size - 2, data.size)
// TODO validate uniqueId, sequenceNumber and crc // TODO validate uniqueId, sequenceNumber and crc

View file

@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.state
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair.PairResult import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair.PairResult
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEvent
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.* import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.*
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.AlarmStatusResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.AlarmStatusResponse
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.DefaultStatusResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.DefaultStatusResponse
@ -11,10 +10,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.VersionResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.VersionResponse
import io.reactivex.Completable import io.reactivex.Completable
import io.reactivex.Maybe import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.Single import io.reactivex.Single
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.joda.time.Duration import org.joda.time.Duration
import java.io.Serializable import java.io.Serializable
import java.util.* import java.util.*

View file

@ -11,7 +11,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.R
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair.PairResult import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.pair.PairResult
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session.EapSqn import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session.EapSqn
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.event.PodEvent
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.* import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.*
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.AlarmStatusResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.AlarmStatusResponse
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.DefaultStatusResponse import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.DefaultStatusResponse
@ -20,10 +19,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.Completable import io.reactivex.Completable
import io.reactivex.Maybe import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.Single import io.reactivex.Single
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.joda.time.Duration import org.joda.time.Duration
import java.io.Serializable import java.io.Serializable
import java.util.* import java.util.*
@ -283,29 +280,29 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
requestedBolus: Double? requestedBolus: Double?
): ):
Single<OmnipodDashPodStateManager.ActiveCommand> { Single<OmnipodDashPodStateManager.ActiveCommand> {
return Single.create { source -> return Single.create { source ->
if (activeCommand == null) { if (activeCommand == null) {
val command = OmnipodDashPodStateManager.ActiveCommand( val command = OmnipodDashPodStateManager.ActiveCommand(
podState.messageSequenceNumber, podState.messageSequenceNumber,
createdRealtime = SystemClock.elapsedRealtime(), createdRealtime = SystemClock.elapsedRealtime(),
historyId = historyId, historyId = historyId,
sendError = null, sendError = null,
basalProgram = basalProgram, basalProgram = basalProgram,
tempBasal = tempBasal, tempBasal = tempBasal,
requestedBolus = requestedBolus requestedBolus = requestedBolus
)
podState.activeCommand = command
source.onSuccess(command)
} else {
source.onError(
java.lang.IllegalStateException(
"Trying to send a command " +
"and the last command was not confirmed"
) )
podState.activeCommand = command )
source.onSuccess(command)
} else {
source.onError(
java.lang.IllegalStateException(
"Trying to send a command " +
"and the last command was not confirmed"
)
)
}
} }
} }
}
@Synchronized @Synchronized
override fun observeNoActiveCommand(): Completable { override fun observeNoActiveCommand(): Completable {

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.ui package info.nightscout.androidaps.plugins.pump.omnipod.dash.ui
import android.content.Intent import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
@ -286,12 +285,13 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
// Update Pod expiry time // Update Pod expiry time
val expiresAt = podStateManager.expiry val expiresAt = podStateManager.expiry
podInfoBinding.podExpiryDate.text = expiresAt?.let { podInfoBinding.podExpiryDate.text = expiresAt?.let {
readableZonedTime(it) } readableZonedTime(it)
}
?: PLACEHOLDER ?: PLACEHOLDER
podInfoBinding.podExpiryDate.setTextColor( podInfoBinding.podExpiryDate.setTextColor(
if (expiresAt != null && DateTime.now().isAfter(expiresAt)) if (expiresAt != null && DateTime.now().isAfter(expiresAt))
Color.RED Color.RED
else else
Color.WHITE Color.WHITE
) )