Merge pull request #51 from vanelsberg/tvelsberg
Updating DASH Overview for "Time On Pod" and "Pod Expires"
This commit is contained in:
commit
a1d5b9eba6
1 changed files with 51 additions and 12 deletions
|
@ -44,6 +44,8 @@ import info.nightscout.androidaps.utils.ui.UIRunnable
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
import org.joda.time.DateTimeZone
|
||||||
import org.joda.time.Duration
|
import org.joda.time.Duration
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -234,6 +236,29 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get time on pos 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())
|
||||||
|
}
|
||||||
|
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) and (minutesSinceActivation != null)) {
|
||||||
|
val expiresInMinutes = (podLifeInHours!! * 60) - minutesSinceActivation!!
|
||||||
|
expiresAt = DateTime().plusMinutes(expiresInMinutes)
|
||||||
|
}
|
||||||
|
return expiresAt
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateOmnipodStatus() {
|
private fun updateOmnipodStatus() {
|
||||||
updateLastConnection()
|
updateLastConnection()
|
||||||
updateLastBolus()
|
updateLastBolus()
|
||||||
|
@ -264,7 +289,16 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
podStateManager.firmwareVersion.toString(),
|
podStateManager.firmwareVersion.toString(),
|
||||||
podStateManager.bluetoothVersion.toString()
|
podStateManager.bluetoothVersion.toString()
|
||||||
)
|
)
|
||||||
podInfoBinding.timeOnPod.text = podStateManager.minutesSinceActivation.toString() + " minutes"
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
/*
|
/*
|
||||||
podInfoBinding.timeOnPod.setTextColor(if (podStateManager.timeDeviatesMoreThan(OmnipodConstants.TIME_DEVIATION_THRESHOLD)) {
|
podInfoBinding.timeOnPod.setTextColor(if (podStateManager.timeDeviatesMoreThan(OmnipodConstants.TIME_DEVIATION_THRESHOLD)) {
|
||||||
|
@ -274,7 +308,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO
|
// TODO: Active command
|
||||||
if (podStateManager.activeCommand != null) {
|
if (podStateManager.activeCommand != null) {
|
||||||
podInfoBinding.podExpiryDate.setTextColor(Color.RED)
|
podInfoBinding.podExpiryDate.setTextColor(Color.RED)
|
||||||
podInfoBinding.podExpiryDate.text = "Active command"
|
podInfoBinding.podExpiryDate.text = "Active command"
|
||||||
|
@ -282,21 +316,20 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
podInfoBinding.podExpiryDate.text = PLACEHOLDER
|
podInfoBinding.podExpiryDate.text = PLACEHOLDER
|
||||||
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
|
podInfoBinding.podExpiryDate.setTextColor(Color.WHITE)
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
val expiresAt = podStateManager.expiresAt
|
|
||||||
|
|
||||||
if (expiresAt == null) {
|
// Update Pod expiry time
|
||||||
|
val expiresAt = getExpiryAt()
|
||||||
|
if (expiresAt is Nothing) {
|
||||||
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 {
|
||||||
Color.WHITE
|
Color.WHITE
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
if (podStateManager.isPodFaulted) {
|
if (podStateManager.isPodFaulted) {
|
||||||
|
@ -610,20 +643,26 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
private fun getTimeZone(): DateTimeZone {
|
||||||
|
// TODO: Get timezone as configured/podState
|
||||||
|
// return getSafe(() -> podState.getTimeZone());
|
||||||
|
return DateTimeZone.getDefault()
|
||||||
|
}
|
||||||
|
|
||||||
private fun readableZonedTime(time: DateTime): String {
|
private fun readableZonedTime(time: DateTime): String {
|
||||||
val timeAsJavaData = time.toLocalDateTime().toDate()
|
val timeAsJavaData = time.toLocalDateTime().toDate()
|
||||||
val timeZone = podStateManager.timeZone.toTimeZone()
|
|
||||||
|
val timeZone = getTimeZone().toTimeZone()
|
||||||
if (timeZone == TimeZone.getDefault()) {
|
if (timeZone == TimeZone.getDefault()) {
|
||||||
return dateUtil.dateAndTimeString(timeAsJavaData)
|
return dateUtil.dateAndTimeString(timeAsJavaData.time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get full timezoned time
|
||||||
val isDaylightTime = timeZone.inDaylightTime(timeAsJavaData)
|
val isDaylightTime = timeZone.inDaylightTime(timeAsJavaData)
|
||||||
val locale = resources.configuration.locales.get(0)
|
val locale = resources.configuration.locales.get(0)
|
||||||
val timeZoneDisplayName = timeZone.getDisplayName(isDaylightTime, TimeZone.SHORT, locale) + " " + timeZone.getDisplayName(isDaylightTime, TimeZone.LONG, locale)
|
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), timeZoneDisplayName)
|
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 {
|
||||||
val hours = duration.standardHours.toInt()
|
val hours = duration.standardHours.toInt()
|
||||||
|
|
Loading…
Reference in a new issue