update overview
This commit is contained in:
parent
2aeff0e92d
commit
e1337f0fb8
|
@ -12,6 +12,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
|||
import io.reactivex.Maybe
|
||||
import io.reactivex.Observable
|
||||
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.util.*
|
||||
|
||||
|
@ -32,8 +35,11 @@ interface OmnipodDashPodStateManager {
|
|||
val isPodKaput: Boolean
|
||||
var bluetoothConnectionState: BluetoothConnectionState
|
||||
|
||||
var timeZone: DateTimeZone
|
||||
val lastUpdatedSystem: Long // System.currentTimeMillis()
|
||||
val lastStatusResponseReceived: Long
|
||||
val time: DateTime?
|
||||
val timeBehind: Duration?
|
||||
|
||||
val messageSequenceNumber: Short
|
||||
val sequenceNumberOfLastProgrammingCommand: Short?
|
||||
|
|
|
@ -21,6 +21,9 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP
|
|||
import io.reactivex.Maybe
|
||||
import io.reactivex.Observable
|
||||
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.util.*
|
||||
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?
|
||||
get() = podState.bleVersion
|
||||
|
||||
|
@ -172,6 +182,23 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
override val lastStatusResponseReceived: Long
|
||||
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
|
||||
get() = podState.bluetoothConnectionState
|
||||
set(bluetoothConnectionState) {
|
||||
|
@ -513,6 +540,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
var ltk: ByteArray? = null
|
||||
var eapAkaSequenceNumber: Long = 1
|
||||
var bolusPulsesRemaining: Short = 0
|
||||
var timeZone = DateTimeZone.getDefault()
|
||||
|
||||
var bleVersion: 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 PLACEHOLDER = "-"
|
||||
private const val MAX_TIME_DEVIATION_MINUTES = 15
|
||||
}
|
||||
|
||||
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? {
|
||||
var timeOnPod: DateTime? = null
|
||||
val minutesSinceActivation = podStateManager.minutesSinceActivation
|
||||
val activationTime = podStateManager.activationTime
|
||||
if ((activationTime != null) and (minutesSinceActivation != null)) {
|
||||
timeOnPod = DateTime(activationTime!!).plusMinutes(minutesSinceActivation!!.toInt())
|
||||
if ((activationTime != null) && (minutesSinceActivation != null)) {
|
||||
timeOnPod = DateTime(activationTime)
|
||||
.plusMinutes(minutesSinceActivation.toInt())
|
||||
.plus(Duration(podStateManager.lastStatusResponseReceived, System.currentTimeMillis()))
|
||||
}
|
||||
return timeOnPod
|
||||
}
|
||||
|
@ -252,8 +255,8 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
var expiresAt: DateTime? = null
|
||||
val podLifeInHours = podStateManager.podLifeInHours
|
||||
val minutesSinceActivation = podStateManager.minutesSinceActivation
|
||||
if ((podLifeInHours != null) and (minutesSinceActivation != null)) {
|
||||
val expiresInMinutes = (podLifeInHours!! * 60) - minutesSinceActivation!!
|
||||
if (podLifeInHours != null && minutesSinceActivation != null) {
|
||||
val expiresInMinutes = podLifeInHours * 60 - minutesSinceActivation
|
||||
expiresAt = DateTime().plusMinutes(expiresInMinutes)
|
||||
}
|
||||
return expiresAt
|
||||
|
@ -293,28 +296,28 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
// Update time on Pod
|
||||
// TODO: For now: derive from podStateManager.minutesSinceActivation
|
||||
val timeOnPod = getTimeOnPod()
|
||||
if (timeOnPod == null) {
|
||||
podInfoBinding.timeOnPod.text = "???"
|
||||
} else {
|
||||
podInfoBinding.timeOnPod.text = readableZonedTime(timeOnPod)
|
||||
}
|
||||
podInfoBinding.timeOnPod.text = podStateManager.time?.let{
|
||||
readableZonedTime(it)
|
||||
} ?: PLACEHOLDER
|
||||
|
||||
podInfoBinding.timeOnPod.setTextColor(
|
||||
podStateManager.timeBehind?.let {
|
||||
if (it.abs().toStandardMinutes() > MAX_TIME_DEVIATION_MINUTES) {
|
||||
Color.RED
|
||||
}else {
|
||||
Color.WHITE
|
||||
}
|
||||
} ?: Color.WHITE
|
||||
)
|
||||
|
||||
// TODO
|
||||
/*
|
||||
podInfoBinding.timeOnPod.setTextColor(if (podStateManager.timeDeviatesMoreThan(OmnipodConstants.TIME_DEVIATION_THRESHOLD)) {
|
||||
Color.RED
|
||||
} else {
|
||||
Color.WHITE
|
||||
})
|
||||
*/
|
||||
|
||||
// Update Pod expiry time
|
||||
val expiresAt = getExpiryAt()
|
||||
if (expiresAt is Nothing) {
|
||||
if (expiresAt == null) {
|
||||
podInfoBinding.podExpiryDate.text = PLACEHOLDER
|
||||
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
|
||||
} else {
|
||||
podInfoBinding.podExpiryDate.text = readableZonedTime(expiresAt!!)
|
||||
podInfoBinding.podExpiryDate.text = readableZonedTime(expiresAt)
|
||||
podInfoBinding.podExpiryDate.setTextColor(if (DateTime.now().isAfter(expiresAt)) {
|
||||
Color.RED
|
||||
} 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 {
|
||||
errors.add(
|
||||
resourceHelper.gs(
|
||||
|
|
Loading…
Reference in a new issue