update overview
This commit is contained in:
parent
2aeff0e92d
commit
e1337f0fb8
3 changed files with 57 additions and 26 deletions
|
@ -12,6 +12,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
||||||
import io.reactivex.Maybe
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.DateTimeZone
|
||||||
|
import org.joda.time.Duration
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -32,8 +35,11 @@ interface OmnipodDashPodStateManager {
|
||||||
val isPodKaput: Boolean
|
val isPodKaput: Boolean
|
||||||
var bluetoothConnectionState: BluetoothConnectionState
|
var bluetoothConnectionState: BluetoothConnectionState
|
||||||
|
|
||||||
|
var timeZone: DateTimeZone
|
||||||
val lastUpdatedSystem: Long // System.currentTimeMillis()
|
val lastUpdatedSystem: Long // System.currentTimeMillis()
|
||||||
val lastStatusResponseReceived: Long
|
val lastStatusResponseReceived: Long
|
||||||
|
val time: DateTime?
|
||||||
|
val timeBehind: Duration?
|
||||||
|
|
||||||
val messageSequenceNumber: Short
|
val messageSequenceNumber: Short
|
||||||
val sequenceNumberOfLastProgrammingCommand: Short?
|
val sequenceNumberOfLastProgrammingCommand: Short?
|
||||||
|
|
|
@ -21,6 +21,9 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import io.reactivex.Maybe
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.DateTimeZone
|
||||||
|
import org.joda.time.Duration
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -96,6 +99,13 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override var timeZone: DateTimeZone
|
||||||
|
get() = podState.timeZone
|
||||||
|
set(tz) {
|
||||||
|
podState.timeZone = tz
|
||||||
|
store()
|
||||||
|
}
|
||||||
|
|
||||||
override val bluetoothVersion: SoftwareVersion?
|
override val bluetoothVersion: SoftwareVersion?
|
||||||
get() = podState.bleVersion
|
get() = podState.bleVersion
|
||||||
|
|
||||||
|
@ -172,6 +182,23 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
override val lastStatusResponseReceived: Long
|
override val lastStatusResponseReceived: Long
|
||||||
get() = podState.lastStatusResponseReceived
|
get() = podState.lastStatusResponseReceived
|
||||||
|
|
||||||
|
override val time: DateTime?
|
||||||
|
get() {
|
||||||
|
val minutesSinceActivation = podState.minutesSinceActivation
|
||||||
|
val activationTime = podState.activationTime
|
||||||
|
if ((activationTime != null) && (minutesSinceActivation != null)) {
|
||||||
|
return DateTime(activationTime)
|
||||||
|
.plusMinutes(minutesSinceActivation.toInt())
|
||||||
|
.plus(Duration(podState.lastStatusResponseReceived, System.currentTimeMillis()))
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override val timeBehind: Duration?
|
||||||
|
get() {
|
||||||
|
return Duration(DateTime.now(), time)
|
||||||
|
}
|
||||||
|
|
||||||
override var bluetoothConnectionState: OmnipodDashPodStateManager.BluetoothConnectionState
|
override var bluetoothConnectionState: OmnipodDashPodStateManager.BluetoothConnectionState
|
||||||
get() = podState.bluetoothConnectionState
|
get() = podState.bluetoothConnectionState
|
||||||
set(bluetoothConnectionState) {
|
set(bluetoothConnectionState) {
|
||||||
|
@ -513,6 +540,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
var ltk: ByteArray? = null
|
var ltk: ByteArray? = null
|
||||||
var eapAkaSequenceNumber: Long = 1
|
var eapAkaSequenceNumber: Long = 1
|
||||||
var bolusPulsesRemaining: Short = 0
|
var bolusPulsesRemaining: Short = 0
|
||||||
|
var timeZone = DateTimeZone.getDefault()
|
||||||
|
|
||||||
var bleVersion: SoftwareVersion? = null
|
var bleVersion: SoftwareVersion? = null
|
||||||
var firmwareVersion: SoftwareVersion? = null
|
var firmwareVersion: SoftwareVersion? = null
|
||||||
|
|
|
@ -69,6 +69,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
|
|
||||||
private const val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds
|
private const val REFRESH_INTERVAL_MILLIS = 15 * 1000L // 15 seconds
|
||||||
private const val PLACEHOLDER = "-"
|
private const val PLACEHOLDER = "-"
|
||||||
|
private const val MAX_TIME_DEVIATION_MINUTES = 15
|
||||||
}
|
}
|
||||||
|
|
||||||
private var disposables: CompositeDisposable = CompositeDisposable()
|
private var disposables: CompositeDisposable = CompositeDisposable()
|
||||||
|
@ -236,13 +237,15 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get time on pos from activation time and minutes since activation
|
// Get time on pod from activation time and minutes since activation
|
||||||
private fun getTimeOnPod(): DateTime? {
|
private fun getTimeOnPod(): DateTime? {
|
||||||
var timeOnPod: DateTime? = null
|
var timeOnPod: DateTime? = null
|
||||||
val minutesSinceActivation = podStateManager.minutesSinceActivation
|
val minutesSinceActivation = podStateManager.minutesSinceActivation
|
||||||
val activationTime = podStateManager.activationTime
|
val activationTime = podStateManager.activationTime
|
||||||
if ((activationTime != null) and (minutesSinceActivation != null)) {
|
if ((activationTime != null) && (minutesSinceActivation != null)) {
|
||||||
timeOnPod = DateTime(activationTime!!).plusMinutes(minutesSinceActivation!!.toInt())
|
timeOnPod = DateTime(activationTime)
|
||||||
|
.plusMinutes(minutesSinceActivation.toInt())
|
||||||
|
.plus(Duration(podStateManager.lastStatusResponseReceived, System.currentTimeMillis()))
|
||||||
}
|
}
|
||||||
return timeOnPod
|
return timeOnPod
|
||||||
}
|
}
|
||||||
|
@ -252,8 +255,8 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
var expiresAt: DateTime? = null
|
var expiresAt: DateTime? = null
|
||||||
val podLifeInHours = podStateManager.podLifeInHours
|
val podLifeInHours = podStateManager.podLifeInHours
|
||||||
val minutesSinceActivation = podStateManager.minutesSinceActivation
|
val minutesSinceActivation = podStateManager.minutesSinceActivation
|
||||||
if ((podLifeInHours != null) and (minutesSinceActivation != null)) {
|
if (podLifeInHours != null && minutesSinceActivation != null) {
|
||||||
val expiresInMinutes = (podLifeInHours!! * 60) - minutesSinceActivation!!
|
val expiresInMinutes = podLifeInHours * 60 - minutesSinceActivation
|
||||||
expiresAt = DateTime().plusMinutes(expiresInMinutes)
|
expiresAt = DateTime().plusMinutes(expiresInMinutes)
|
||||||
}
|
}
|
||||||
return expiresAt
|
return expiresAt
|
||||||
|
@ -293,28 +296,28 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
// Update time on Pod
|
// Update time on Pod
|
||||||
// TODO: For now: derive from podStateManager.minutesSinceActivation
|
// TODO: For now: derive from podStateManager.minutesSinceActivation
|
||||||
val timeOnPod = getTimeOnPod()
|
val timeOnPod = getTimeOnPod()
|
||||||
if (timeOnPod == null) {
|
podInfoBinding.timeOnPod.text = podStateManager.time?.let{
|
||||||
podInfoBinding.timeOnPod.text = "???"
|
readableZonedTime(it)
|
||||||
} else {
|
} ?: PLACEHOLDER
|
||||||
podInfoBinding.timeOnPod.text = readableZonedTime(timeOnPod)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO
|
podInfoBinding.timeOnPod.setTextColor(
|
||||||
/*
|
podStateManager.timeBehind?.let {
|
||||||
podInfoBinding.timeOnPod.setTextColor(if (podStateManager.timeDeviatesMoreThan(OmnipodConstants.TIME_DEVIATION_THRESHOLD)) {
|
if (it.abs().toStandardMinutes() > MAX_TIME_DEVIATION_MINUTES) {
|
||||||
Color.RED
|
Color.RED
|
||||||
} else {
|
}else {
|
||||||
Color.WHITE
|
Color.WHITE
|
||||||
})
|
}
|
||||||
*/
|
} ?: Color.WHITE
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
// Update Pod expiry time
|
// Update Pod expiry time
|
||||||
val expiresAt = getExpiryAt()
|
val expiresAt = getExpiryAt()
|
||||||
if (expiresAt is Nothing) {
|
if (expiresAt == null) {
|
||||||
podInfoBinding.podExpiryDate.text = PLACEHOLDER
|
podInfoBinding.podExpiryDate.text = PLACEHOLDER
|
||||||
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
|
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
|
||||||
} else {
|
} else {
|
||||||
podInfoBinding.podExpiryDate.text = readableZonedTime(expiresAt!!)
|
podInfoBinding.podExpiryDate.text = readableZonedTime(expiresAt)
|
||||||
podInfoBinding.podExpiryDate.setTextColor(if (DateTime.now().isAfter(expiresAt)) {
|
podInfoBinding.podExpiryDate.setTextColor(if (DateTime.now().isAfter(expiresAt)) {
|
||||||
Color.RED
|
Color.RED
|
||||||
} else {
|
} else {
|
||||||
|
@ -322,12 +325,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
|
||||||
if (podStateManager.isPodFaulted) {
|
|
||||||
val faultEventCode = podStateManager.faultEventCode
|
|
||||||
errors.add(resourceHelper.gs(R.string.omnipod_common_pod_status_pod_fault_description, faultEventCode.value, faultEventCode.name))
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
podStateManager.alarmType?.let {
|
podStateManager.alarmType?.let {
|
||||||
errors.add(
|
errors.add(
|
||||||
resourceHelper.gs(
|
resourceHelper.gs(
|
||||||
|
|
Loading…
Reference in a new issue