Merge pull request #52 from vanelsberg/tvelsberg-fixes-v2
Fixing Podstate loading, expiry calculation, and Pos times on overview
This commit is contained in:
commit
26de3376d2
3 changed files with 46 additions and 45 deletions
|
@ -35,11 +35,12 @@ interface OmnipodDashPodStateManager {
|
|||
val isPodKaput: Boolean
|
||||
var bluetoothConnectionState: BluetoothConnectionState
|
||||
|
||||
var timeZone: DateTimeZone
|
||||
var timeZone: String
|
||||
val lastUpdatedSystem: Long // System.currentTimeMillis()
|
||||
val lastStatusResponseReceived: Long
|
||||
val time: DateTime?
|
||||
val timeBehind: Duration?
|
||||
val expiry: DateTime?
|
||||
|
||||
val messageSequenceNumber: Short
|
||||
val sequenceNumberOfLastProgrammingCommand: Short?
|
||||
|
|
|
@ -99,7 +99,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override var timeZone: DateTimeZone
|
||||
override var timeZone: String
|
||||
get() = podState.timeZone
|
||||
set(tz) {
|
||||
podState.timeZone = tz
|
||||
|
@ -199,6 +199,17 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
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
|
||||
get() = podState.bluetoothConnectionState
|
||||
set(bluetoothConnectionState) {
|
||||
|
@ -589,7 +600,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
var ltk: ByteArray? = null
|
||||
var eapAkaSequenceNumber: Long = 1
|
||||
var bolusPulsesRemaining: Short = 0
|
||||
var timeZone = DateTimeZone.getDefault()
|
||||
var timeZone: String = "" // TimeZone ID (e.g. "Europe/Amsterdam")
|
||||
|
||||
var bleVersion: SoftwareVersion? = null
|
||||
var firmwareVersion: SoftwareVersion? = null
|
||||
|
|
|
@ -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() {
|
||||
updateLastConnection()
|
||||
updateLastBolus()
|
||||
|
@ -294,8 +269,6 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
)
|
||||
|
||||
// Update time on Pod
|
||||
// TODO: For now: derive from podStateManager.minutesSinceActivation
|
||||
val timeOnPod = getTimeOnPod()
|
||||
podInfoBinding.timeOnPod.text = podStateManager.time?.let {
|
||||
readableZonedTime(it)
|
||||
} ?: PLACEHOLDER
|
||||
|
@ -311,7 +284,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
)
|
||||
|
||||
// Update Pod expiry time
|
||||
val expiresAt = getExpiryAt()
|
||||
val expiresAt = podStateManager.expiry
|
||||
if (expiresAt == null) {
|
||||
podInfoBinding.podExpiryDate.text = PLACEHOLDER
|
||||
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
|
||||
|
@ -631,25 +604,41 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getTimeZone(): DateTimeZone {
|
||||
// TODO: Get timezone as configured/podState
|
||||
// return getSafe(() -> podState.getTimeZone());
|
||||
return DateTimeZone.getDefault()
|
||||
// private fun getTimeZone(): DateTimeZone {
|
||||
// // return getSafe(() -> podState.getTimeZone());
|
||||
// return podStateManager.timeZone
|
||||
// }
|
||||
private fun getTimeZone(): String {
|
||||
// Return timezone ID (e.g "Europe/Amsterdam")
|
||||
return podStateManager.timeZone
|
||||
}
|
||||
|
||||
private fun readableZonedTime(time: DateTime): String {
|
||||
val timeAsJavaData = time.toLocalDateTime().toDate()
|
||||
return dateUtil.dateAndTimeString(timeAsJavaData.time)
|
||||
|
||||
val timeZone = getTimeZone().toTimeZone()
|
||||
if (timeZone == TimeZone.getDefault()) {
|
||||
return dateUtil.dateAndTimeString(timeAsJavaData.time)
|
||||
}
|
||||
|
||||
// Get full timezoned time
|
||||
val isDaylightTime = timeZone.inDaylightTime(timeAsJavaData)
|
||||
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)
|
||||
// // TODO: Handle timeZone ID
|
||||
// val timeZone = getTimeZone()
|
||||
// if (timeZone == "") {
|
||||
// // No timezone defined, use local time (default)
|
||||
// return dateUtil.dateAndTimeString(timeAsJavaData.time)
|
||||
// }
|
||||
// else {
|
||||
// // Get full timezoned time
|
||||
// val isDaylightTime = timeZone.inDaylightTime(timeAsJavaData)
|
||||
// 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 {
|
||||
|
|
Loading…
Reference in a new issue