diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt index 9a7b094846..fd6d1f5aff 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManager.kt @@ -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? diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index a8fcd7844f..b57c8a3eb0 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -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 diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index 64b2a22b70..972bdaa418 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -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 {