Merge pull request #52 from vanelsberg/tvelsberg-fixes-v2

Fixing Podstate loading, expiry calculation, and Pos times on overview
This commit is contained in:
Andrei Vereha 2021-06-25 19:20:03 +02:00 committed by GitHub
commit 26de3376d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 45 deletions

View file

@ -35,11 +35,12 @@ interface OmnipodDashPodStateManager {
val isPodKaput: Boolean val isPodKaput: Boolean
var bluetoothConnectionState: BluetoothConnectionState var bluetoothConnectionState: BluetoothConnectionState
var timeZone: DateTimeZone var timeZone: String
val lastUpdatedSystem: Long // System.currentTimeMillis() val lastUpdatedSystem: Long // System.currentTimeMillis()
val lastStatusResponseReceived: Long val lastStatusResponseReceived: Long
val time: DateTime? val time: DateTime?
val timeBehind: Duration? val timeBehind: Duration?
val expiry: DateTime?
val messageSequenceNumber: Short val messageSequenceNumber: Short
val sequenceNumberOfLastProgrammingCommand: Short? val sequenceNumberOfLastProgrammingCommand: Short?

View file

@ -99,7 +99,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
} }
} }
override var timeZone: DateTimeZone override var timeZone: String
get() = podState.timeZone get() = podState.timeZone
set(tz) { set(tz) {
podState.timeZone = tz podState.timeZone = tz
@ -199,6 +199,17 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
return Duration(DateTime.now(), time) return Duration(DateTime.now(), time)
} }
override val expiry: DateTime?
// TODO: Consider storing expiry datetime in pod state saving continuesly recalculating to the same value
get() {
val podLifeInHours = podLifeInHours
val activationTime = podState.activationTime
if (podLifeInHours != null && activationTime != null) {
return DateTime(podState.activationTime).plusHours(podLifeInHours.toInt())
}
return null
}
override var bluetoothConnectionState: OmnipodDashPodStateManager.BluetoothConnectionState override var bluetoothConnectionState: OmnipodDashPodStateManager.BluetoothConnectionState
get() = podState.bluetoothConnectionState get() = podState.bluetoothConnectionState
set(bluetoothConnectionState) { set(bluetoothConnectionState) {
@ -589,7 +600,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 timeZone: String = "" // TimeZone ID (e.g. "Europe/Amsterdam")
var bleVersion: SoftwareVersion? = null var bleVersion: SoftwareVersion? = null
var firmwareVersion: SoftwareVersion? = null var firmwareVersion: SoftwareVersion? = null

View file

@ -237,31 +237,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
} }
} }
// 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) && (minutesSinceActivation != null)) {
timeOnPod = DateTime(activationTime)
.plusMinutes(minutesSinceActivation.toInt())
.plus(Duration(podStateManager.lastStatusResponseReceived, System.currentTimeMillis()))
}
return timeOnPod
}
// TODO: Consider storing expiry datetime in pod state saving continuesly recalculating to the same value
private fun getExpiryAt(): DateTime? {
var expiresAt: DateTime? = null
val podLifeInHours = podStateManager.podLifeInHours
val minutesSinceActivation = podStateManager.minutesSinceActivation
if (podLifeInHours != null && minutesSinceActivation != null) {
val expiresInMinutes = podLifeInHours * 60 - minutesSinceActivation
expiresAt = DateTime().plusMinutes(expiresInMinutes)
}
return expiresAt
}
private fun updateOmnipodStatus() { private fun updateOmnipodStatus() {
updateLastConnection() updateLastConnection()
updateLastBolus() updateLastBolus()
@ -294,8 +269,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
) )
// Update time on Pod // Update time on Pod
// TODO: For now: derive from podStateManager.minutesSinceActivation
val timeOnPod = getTimeOnPod()
podInfoBinding.timeOnPod.text = podStateManager.time?.let { podInfoBinding.timeOnPod.text = podStateManager.time?.let {
readableZonedTime(it) readableZonedTime(it)
} ?: PLACEHOLDER } ?: PLACEHOLDER
@ -311,7 +284,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
) )
// Update Pod expiry time // Update Pod expiry time
val expiresAt = getExpiryAt() val expiresAt = podStateManager.expiry
if (expiresAt == null) { if (expiresAt == null) {
podInfoBinding.podExpiryDate.text = PLACEHOLDER podInfoBinding.podExpiryDate.text = PLACEHOLDER
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE) podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
@ -631,25 +604,41 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
} }
} }
private fun getTimeZone(): DateTimeZone { // private fun getTimeZone(): DateTimeZone {
// TODO: Get timezone as configured/podState // // return getSafe(() -> podState.getTimeZone());
// return getSafe(() -> podState.getTimeZone()); // return podStateManager.timeZone
return DateTimeZone.getDefault() // }
private fun getTimeZone(): String {
// Return timezone ID (e.g "Europe/Amsterdam")
return podStateManager.timeZone
} }
private fun readableZonedTime(time: DateTime): String { private fun readableZonedTime(time: DateTime): String {
val timeAsJavaData = time.toLocalDateTime().toDate() val timeAsJavaData = time.toLocalDateTime().toDate()
return dateUtil.dateAndTimeString(timeAsJavaData.time)
val timeZone = getTimeZone().toTimeZone() // // TODO: Handle timeZone ID
if (timeZone == TimeZone.getDefault()) { // val timeZone = getTimeZone()
return dateUtil.dateAndTimeString(timeAsJavaData.time) // if (timeZone == "") {
} // // No timezone defined, use local time (default)
// return dateUtil.dateAndTimeString(timeAsJavaData.time)
// Get full timezoned time // }
val isDaylightTime = timeZone.inDaylightTime(timeAsJavaData) // else {
val locale = resources.configuration.locales.get(0) // // Get full timezoned time
val timeZoneDisplayName = timeZone.getDisplayName(isDaylightTime, TimeZone.SHORT, locale) + " " + timeZone.getDisplayName(isDaylightTime, TimeZone.LONG, locale) // val isDaylightTime = timeZone.inDaylightTime(timeAsJavaData)
return resourceHelper.gs(R.string.omnipod_common_time_with_timezone, dateUtil.dateAndTimeString(timeAsJavaData.time), timeZoneDisplayName) // val locale = resources.configuration.locales.get(0)
// val timeZoneDisplayName =
// timeZone.getDisplayName(isDaylightTime, TimeZone.SHORT, locale) + " " + timeZone.getDisplayName(
// isDaylightTime,
// TimeZone.LONG,
// locale
// )
// return resourceHelper.gs(
// R.string.omnipod_common_time_with_timezone,
// dateUtil.dateAndTimeString(timeAsJavaData.time),
// timeZoneDisplayName
// )
// }
} }
private fun readableDuration(duration: Duration): String { private fun readableDuration(duration: Duration): String {