remove Joda
This commit is contained in:
parent
f289cd50c5
commit
d1f99bfb71
5 changed files with 60 additions and 80 deletions
|
@ -113,7 +113,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
pumpSync.syncTemporaryBasalWithPumpId(
|
pumpSync.syncTemporaryBasalWithPumpId(
|
||||||
timestamp = System.currentTimeMillis(),
|
timestamp = System.currentTimeMillis(),
|
||||||
rate = 0.0,
|
rate = 0.0,
|
||||||
duration = T.mins(PodConstants.MAX_POD_LIFETIME.standardMinutes).msecs(),
|
duration = T.mins(PodConstants.MAX_POD_LIFETIME.toMinutes()).msecs(),
|
||||||
isAbsolute = true,
|
isAbsolute = true,
|
||||||
type = PumpSync.TemporaryBasalType.PUMP_SUSPEND,
|
type = PumpSync.TemporaryBasalType.PUMP_SUSPEND,
|
||||||
pumpId = Random.Default.nextLong(), // we don't use this, just make sure it's unique
|
pumpId = Random.Default.nextLong(), // we don't use this, just make sure it's unique
|
||||||
|
@ -146,7 +146,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
rxBus.send(EventNewNotification(notification))
|
rxBus.send(EventNewNotification(notification))
|
||||||
} else {
|
} else {
|
||||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED))
|
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED))
|
||||||
if (!TimeZone.getDefault().equals(podStateManager.timeZone)) {
|
if (!podStateManager.sameTimeZone) {
|
||||||
val notification =
|
val notification =
|
||||||
Notification(
|
Notification(
|
||||||
Notification.OMNIPOD_TIME_OUT_OF_SYNC,
|
Notification.OMNIPOD_TIME_OUT_OF_SYNC,
|
||||||
|
@ -277,7 +277,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
pumpSync.syncTemporaryBasalWithPumpId(
|
pumpSync.syncTemporaryBasalWithPumpId(
|
||||||
timestamp = System.currentTimeMillis(),
|
timestamp = System.currentTimeMillis(),
|
||||||
rate = 0.0,
|
rate = 0.0,
|
||||||
duration = T.mins(PodConstants.MAX_POD_LIFETIME.standardMinutes).msecs(),
|
duration = T.mins(PodConstants.MAX_POD_LIFETIME.toMinutes()).msecs(),
|
||||||
isAbsolute = true,
|
isAbsolute = true,
|
||||||
type = PumpSync.TemporaryBasalType.PUMP_SUSPEND,
|
type = PumpSync.TemporaryBasalType.PUMP_SUSPEND,
|
||||||
pumpId = Random.Default.nextLong(), // we don't use this, just make sure it's unique
|
pumpId = Random.Default.nextLong(), // we don't use this, just make sure it's unique
|
||||||
|
@ -371,7 +371,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
.map {
|
.map {
|
||||||
pumpSyncTempBasal(
|
pumpSyncTempBasal(
|
||||||
0.0,
|
0.0,
|
||||||
PodConstants.MAX_POD_LIFETIME.standardMinutes,
|
PodConstants.MAX_POD_LIFETIME.toMinutes(),
|
||||||
PumpSync.TemporaryBasalType.PUMP_SUSPEND
|
PumpSync.TemporaryBasalType.PUMP_SUSPEND
|
||||||
)
|
)
|
||||||
rxBus.send(EventTempBasalChange())
|
rxBus.send(EventTempBasalChange())
|
||||||
|
@ -961,7 +961,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
.map {
|
.map {
|
||||||
pumpSyncTempBasal(
|
pumpSyncTempBasal(
|
||||||
0.0,
|
0.0,
|
||||||
PodConstants.MAX_POD_LIFETIME.standardMinutes,
|
PodConstants.MAX_POD_LIFETIME.toMinutes(),
|
||||||
PumpSync.TemporaryBasalType.PUMP_SUSPEND
|
PumpSync.TemporaryBasalType.PUMP_SUSPEND
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1116,6 +1116,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED))
|
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED))
|
||||||
}
|
}
|
||||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TBR_ALERTS))
|
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TBR_ALERTS))
|
||||||
|
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TIME_OUT_OF_SYNC))
|
||||||
}
|
}
|
||||||
|
|
||||||
OmnipodCommandType.SET_BASAL_PROFILE -> {
|
OmnipodCommandType.SET_BASAL_PROFILE -> {
|
||||||
|
@ -1137,6 +1138,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED))
|
rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED))
|
||||||
rxBus.send(EventDismissNotification(Notification.FAILED_UPDATE_PROFILE))
|
rxBus.send(EventDismissNotification(Notification.FAILED_UPDATE_PROFILE))
|
||||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TBR_ALERTS))
|
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TBR_ALERTS))
|
||||||
|
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TIME_OUT_OF_SYNC))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition
|
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition
|
||||||
|
|
||||||
import org.joda.time.Duration
|
import java.time.Duration
|
||||||
|
|
||||||
class PodConstants {
|
class PodConstants {
|
||||||
companion object {
|
companion object {
|
||||||
val MAX_POD_LIFETIME = Duration.standardHours(80)
|
val MAX_POD_LIFETIME = Duration.ofMinutes(80)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response.
|
||||||
import io.reactivex.Completable
|
import io.reactivex.Completable
|
||||||
import io.reactivex.Maybe
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.joda.time.DateTime
|
|
||||||
import org.joda.time.Duration
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
import java.time.ZonedDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
sealed class CommandConfirmationFromState
|
sealed class CommandConfirmationFromState
|
||||||
|
@ -34,11 +33,12 @@ interface OmnipodDashPodStateManager {
|
||||||
var bluetoothConnectionState: BluetoothConnectionState
|
var bluetoothConnectionState: BluetoothConnectionState
|
||||||
|
|
||||||
var timeZone: TimeZone
|
var timeZone: TimeZone
|
||||||
|
val sameTimeZone: Boolean // The TimeZone is the same on the phone and on the pod
|
||||||
val lastUpdatedSystem: Long // System.currentTimeMillis()
|
val lastUpdatedSystem: Long // System.currentTimeMillis()
|
||||||
val lastStatusResponseReceived: Long
|
val lastStatusResponseReceived: Long
|
||||||
val time: DateTime?
|
val time: ZonedDateTime?
|
||||||
val timeDrift: Duration?
|
val timeDrift: java.time.Duration?
|
||||||
val expiry: DateTime?
|
val expiry: ZonedDateTime?
|
||||||
|
|
||||||
val messageSequenceNumber: Short
|
val messageSequenceNumber: Short
|
||||||
val sequenceNumberOfLastProgrammingCommand: Short?
|
val sequenceNumberOfLastProgrammingCommand: Short?
|
||||||
|
|
|
@ -20,9 +20,10 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import io.reactivex.Completable
|
import io.reactivex.Completable
|
||||||
import io.reactivex.Maybe
|
import io.reactivex.Maybe
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.joda.time.DateTime
|
|
||||||
import org.joda.time.Duration
|
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
import java.time.Duration
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.ZonedDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
@ -104,6 +105,12 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
store()
|
store()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val sameTimeZone: Boolean
|
||||||
|
get() {
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
return TimeZone.getDefault().getOffset(now) == timeZone.getOffset(now)
|
||||||
|
}
|
||||||
|
|
||||||
override val bluetoothVersion: SoftwareVersion?
|
override val bluetoothVersion: SoftwareVersion?
|
||||||
get() = podState.bleVersion
|
get() = podState.bleVersion
|
||||||
|
|
||||||
|
@ -180,30 +187,31 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
||||||
override val lastStatusResponseReceived: Long
|
override val lastStatusResponseReceived: Long
|
||||||
get() = podState.lastStatusResponseReceived
|
get() = podState.lastStatusResponseReceived
|
||||||
|
|
||||||
override val time: DateTime?
|
override val time: ZonedDateTime?
|
||||||
get() {
|
get() {
|
||||||
val minutesSinceActivation = podState.minutesSinceActivation
|
val minutesSinceActivation = podState.minutesSinceActivation
|
||||||
val activationTime = podState.activationTime
|
val activationTime = podState.activationTime
|
||||||
if ((activationTime != null) && (minutesSinceActivation != null)) {
|
if ((activationTime != null) && (minutesSinceActivation != null)) {
|
||||||
return DateTime(activationTime)
|
return ZonedDateTime.from(Instant.ofEpochMilli(activationTime))
|
||||||
.plusMinutes(minutesSinceActivation.toInt())
|
.plusMinutes(minutesSinceActivation.toLong())
|
||||||
.plus(Duration(podState.lastUpdatedSystem, System.currentTimeMillis()))
|
.plus(Duration.ofMillis(System.currentTimeMillis() - lastUpdatedSystem))
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override val timeDrift: Duration?
|
override val timeDrift: Duration?
|
||||||
get() {
|
get() {
|
||||||
return Duration(DateTime.now(), time)
|
return Duration.between(ZonedDateTime.now(), time)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val expiry: DateTime?
|
override val expiry: ZonedDateTime?
|
||||||
// TODO: Consider storing expiry datetime in pod state saving continuously recalculating to the same value
|
// TODO: Consider storing expiry datetime in pod state saving continuously recalculating to the same value
|
||||||
get() {
|
get() {
|
||||||
val podLifeInHours = podLifeInHours
|
val podLifeInHours = podLifeInHours
|
||||||
val activationTime = podState.activationTime
|
val activationTime = podState.activationTime
|
||||||
if (podLifeInHours != null && activationTime != null) {
|
if (podLifeInHours != null && activationTime != null) {
|
||||||
return DateTime(podState.activationTime).plusHours(podLifeInHours.toInt())
|
return return ZonedDateTime.from(Instant.ofEpochMilli(activationTime))
|
||||||
|
.plusHours(podLifeInHours.toLong())
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +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 java.time.Duration
|
||||||
import org.joda.time.Duration
|
import java.time.ZonedDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
@ -269,27 +269,34 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
|
|
||||||
// Update time on Pod
|
// Update time on Pod
|
||||||
podInfoBinding.timeOnPod.text = podStateManager.time?.let {
|
podInfoBinding.timeOnPod.text = podStateManager.time?.let {
|
||||||
readableZonedTime(it)
|
resourceHelper.gs(
|
||||||
|
R.string.omnipod_common_time_with_timezone,
|
||||||
|
dateUtil.dateAndTimeString(it.toEpochSecond()),
|
||||||
|
podStateManager.timeZone.getDisplayName(true, TimeZone.SHORT)
|
||||||
|
)
|
||||||
} ?: PLACEHOLDER
|
} ?: PLACEHOLDER
|
||||||
|
|
||||||
podInfoBinding.timeOnPod.setTextColor(
|
podInfoBinding.timeOnPod.setTextColor(
|
||||||
podStateManager.timeDrift?.let {
|
when {
|
||||||
if (it.abs().isLongerThan(Duration.standardMinutes(MAX_TIME_DEVIATION_MINUTES))) {
|
!podStateManager.sameTimeZone ->
|
||||||
Color.RED
|
Color.MAGENTA
|
||||||
} else {
|
podStateManager.timeDrift?.abs()?.minus(
|
||||||
|
Duration.ofMinutes(MAX_TIME_DEVIATION_MINUTES)
|
||||||
|
)?.isNegative ?: false ->
|
||||||
|
Color.YELLOW
|
||||||
|
else ->
|
||||||
Color.WHITE
|
Color.WHITE
|
||||||
}
|
}
|
||||||
} ?: Color.WHITE
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Update Pod expiry time
|
// Update Pod expiry time
|
||||||
val expiresAt = podStateManager.expiry
|
val expiresAt = podStateManager.expiry
|
||||||
podInfoBinding.podExpiryDate.text = expiresAt?.let {
|
podInfoBinding.podExpiryDate.text = expiresAt?.let {
|
||||||
readableZonedTime(it)
|
dateUtil.dateAndTimeString(it.toEpochSecond())
|
||||||
}
|
}
|
||||||
?: PLACEHOLDER
|
?: PLACEHOLDER
|
||||||
podInfoBinding.podExpiryDate.setTextColor(
|
podInfoBinding.podExpiryDate.setTextColor(
|
||||||
if (expiresAt != null && DateTime.now().isAfter(expiresAt))
|
if (expiresAt != null && ZonedDateTime.now().isAfter(expiresAt))
|
||||||
Color.RED
|
Color.RED
|
||||||
else
|
else
|
||||||
Color.WHITE
|
Color.WHITE
|
||||||
|
@ -368,14 +375,14 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
private fun updateLastConnection() {
|
private fun updateLastConnection() {
|
||||||
if (podStateManager.isUniqueIdSet) {
|
if (podStateManager.isUniqueIdSet) {
|
||||||
podInfoBinding.lastConnection.text = readableDuration(
|
podInfoBinding.lastConnection.text = readableDuration(
|
||||||
Duration(
|
Duration.ofMillis(
|
||||||
podStateManager.lastUpdatedSystem,
|
System.currentTimeMillis() -
|
||||||
System
|
podStateManager.lastUpdatedSystem,
|
||||||
.currentTimeMillis()
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val lastConnectionColor =
|
val lastConnectionColor =
|
||||||
if (omnipodDashPumpPlugin.isUnreachableAlertTimeoutExceeded(getPumpUnreachableTimeout().millis)) {
|
if (omnipodDashPumpPlugin.isUnreachableAlertTimeoutExceeded(getPumpUnreachableTimeout().toMillis())) {
|
||||||
Color.RED
|
Color.RED
|
||||||
} else {
|
} else {
|
||||||
Color.WHITE
|
Color.WHITE
|
||||||
|
@ -441,7 +448,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
R.string.omnipod_common_overview_last_bolus_value,
|
R.string.omnipod_common_overview_last_bolus_value,
|
||||||
omnipodDashPumpPlugin.model().determineCorrectBolusSize(requestedBolus),
|
omnipodDashPumpPlugin.model().determineCorrectBolusSize(requestedBolus),
|
||||||
resourceHelper.gs(R.string.insulin_unit_shortname),
|
resourceHelper.gs(R.string.insulin_unit_shortname),
|
||||||
readableDuration(Duration(it.createdRealtime, SystemClock.elapsedRealtime()))
|
readableDuration(Duration.ofMillis(SystemClock.elapsedRealtime() - it.createdRealtime))
|
||||||
)
|
)
|
||||||
text += " (uncertain) "
|
text += " (uncertain) "
|
||||||
textColor = Color.RED
|
textColor = Color.RED
|
||||||
|
@ -461,7 +468,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
R.string.omnipod_common_overview_last_bolus_value,
|
R.string.omnipod_common_overview_last_bolus_value,
|
||||||
omnipodDashPumpPlugin.model().determineCorrectBolusSize(bolusSize),
|
omnipodDashPumpPlugin.model().determineCorrectBolusSize(bolusSize),
|
||||||
resourceHelper.gs(R.string.insulin_unit_shortname),
|
resourceHelper.gs(R.string.insulin_unit_shortname),
|
||||||
readableDuration(Duration(it.startTime, System.currentTimeMillis()))
|
readableDuration(Duration.ofMillis(System.currentTimeMillis() - it.startTime))
|
||||||
)
|
)
|
||||||
if (!it.deliveryComplete) {
|
if (!it.deliveryComplete) {
|
||||||
textColor = Color.YELLOW
|
textColor = Color.YELLOW
|
||||||
|
@ -597,47 +604,10 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun getTimeZone(): DateTimeZone {
|
|
||||||
// // return getSafe(() -> podState.getTimeZone());
|
|
||||||
// return podStateManager.timeZone
|
|
||||||
// }
|
|
||||||
private fun getTimeZone(): TimeZone {
|
|
||||||
// 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)
|
|
||||||
|
|
||||||
// // 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 {
|
private fun readableDuration(duration: Duration): String {
|
||||||
val hours = duration.standardHours.toInt()
|
val hours = duration.toHours().toInt()
|
||||||
val minutes = duration.standardMinutes.toInt()
|
val minutes = duration.toMinutes().toInt()
|
||||||
val seconds = duration.standardSeconds.toInt()
|
val seconds = duration.seconds
|
||||||
when {
|
when {
|
||||||
seconds < 10 -> {
|
seconds < 10 -> {
|
||||||
return resourceHelper.gs(R.string.omnipod_common_moments_ago)
|
return resourceHelper.gs(R.string.omnipod_common_moments_ago)
|
||||||
|
@ -680,7 +650,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
|
|
||||||
// FIXME ideally we should just have access to LocalAlertUtils here
|
// FIXME ideally we should just have access to LocalAlertUtils here
|
||||||
private fun getPumpUnreachableTimeout(): Duration {
|
private fun getPumpUnreachableTimeout(): Duration {
|
||||||
return Duration.standardMinutes(
|
return Duration.ofMinutes(
|
||||||
sp.getInt(
|
sp.getInt(
|
||||||
R.string.key_pump_unreachable_threshold_minutes,
|
R.string.key_pump_unreachable_threshold_minutes,
|
||||||
Constants.DEFAULT_PUMP_UNREACHABLE_THRESHOLD_MINUTES
|
Constants.DEFAULT_PUMP_UNREACHABLE_THRESHOLD_MINUTES
|
||||||
|
|
Loading…
Add table
Reference in a new issue