Eliminate use of Date()
This commit is contained in:
parent
1b7ae4e704
commit
f0a37d64f3
6 changed files with 65 additions and 81 deletions
|
@ -148,7 +148,7 @@ class MaintenancePlugin @Inject constructor(
|
|||
* @return
|
||||
*/
|
||||
private fun constructName(): String {
|
||||
return "AndroidAPS_LOG_" + Date().time + loggerUtils.suffix
|
||||
return "AndroidAPS_LOG_" + System.currentTimeMillis() + loggerUtils.suffix
|
||||
}
|
||||
|
||||
private fun zip(zipFile: File?, files: List<File>) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.text.SimpleDateFormat
|
|||
import java.util.*
|
||||
|
||||
class EventNSClientNewLog(var action: String, var logText: String) : Event() {
|
||||
var date = Date()
|
||||
var date = System.currentTimeMillis()
|
||||
|
||||
private var timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
rh: ResourceHelper,
|
||||
commandQueue: CommandQueue
|
||||
) : PumpPluginBase(pluginDescription, injector, aapsLogger, rh, commandQueue), Pump {
|
||||
|
||||
@Volatile var bolusCanceled = false
|
||||
@Volatile var bolusDeliveryInProgress = false
|
||||
|
||||
|
@ -95,6 +96,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
private var disposables: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
companion object {
|
||||
|
||||
private const val BOLUS_RETRY_INTERVAL_MS = 2000.toLong()
|
||||
private const val BOLUS_RETRIES = 5 // number of retries for cancel/get bolus status
|
||||
private const val STATUS_CHECK_INTERVAL_MS = (60L * 1000)
|
||||
|
@ -460,22 +462,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe(
|
||||
{
|
||||
if (it.isChanged(
|
||||
rh,
|
||||
R.string.key_omnipod_common_expiration_reminder_enabled
|
||||
) ||
|
||||
it.isChanged(
|
||||
rh,
|
||||
R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown
|
||||
) ||
|
||||
it.isChanged(
|
||||
rh,
|
||||
R.string.key_omnipod_common_low_reservoir_alert_enabled
|
||||
) ||
|
||||
it.isChanged(
|
||||
rh,
|
||||
R.string.key_omnipod_common_low_reservoir_alert_units
|
||||
)
|
||||
if (it.isChanged(rh, R.string.key_omnipod_common_expiration_reminder_enabled) ||
|
||||
it.isChanged(rh, R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown) ||
|
||||
it.isChanged(rh, R.string.key_omnipod_common_low_reservoir_alert_enabled) ||
|
||||
it.isChanged(rh, R.string.key_omnipod_common_low_reservoir_alert_units)
|
||||
) {
|
||||
commandQueue.customCommand(CommandUpdateAlertConfiguration(), null)
|
||||
}
|
||||
|
@ -519,7 +509,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
override val baseBasalRate: Double
|
||||
get() {
|
||||
val date = Date()
|
||||
val date = System.currentTimeMillis()
|
||||
val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0
|
||||
aapsLogger.info(LTag.PUMP, "baseBasalRate: $ret at $date}")
|
||||
return if (podStateManager.alarmType != null) {
|
||||
|
@ -626,20 +616,15 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
)
|
||||
} else {
|
||||
if (podStateManager.activeCommand != null) {
|
||||
val sound = if (sp.getBoolean(
|
||||
R.string
|
||||
.key_omnipod_common_notification_uncertain_bolus_sound_enabled,
|
||||
true
|
||||
)
|
||||
)
|
||||
R.raw.boluserror
|
||||
else
|
||||
0
|
||||
val sound =
|
||||
if (sp.getBoolean(
|
||||
R.string
|
||||
.key_omnipod_common_notification_uncertain_bolus_sound_enabled, true
|
||||
)
|
||||
) R.raw.boluserror
|
||||
else 0
|
||||
|
||||
showErrorDialog(
|
||||
"Bolus delivery status uncertain. Refresh pod status to confirm or deny.",
|
||||
sound
|
||||
)
|
||||
showErrorDialog("Bolus delivery status uncertain. Refresh pod status to confirm or deny.", sound)
|
||||
}
|
||||
}
|
||||
}.toSingle {
|
||||
|
@ -1000,12 +985,9 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
val extended = JSONObject()
|
||||
try {
|
||||
val podStatus = when {
|
||||
podStateManager.isPodRunning && podStateManager.isSuspended ->
|
||||
"suspended"
|
||||
podStateManager.isPodRunning ->
|
||||
"normal"
|
||||
else ->
|
||||
"no active Pod"
|
||||
podStateManager.isPodRunning && podStateManager.isSuspended -> "suspended"
|
||||
podStateManager.isPodRunning -> "normal"
|
||||
else -> "no active Pod"
|
||||
}
|
||||
status.put("status", podStatus)
|
||||
status.put("timestamp", dateUtil.toISOString(podStateManager.lastUpdatedSystem))
|
||||
|
@ -1108,21 +1090,22 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
override fun executeCustomCommand(customCommand: CustomCommand): PumpEnactResult {
|
||||
return when (customCommand) {
|
||||
is CommandSilenceAlerts ->
|
||||
is CommandSilenceAlerts ->
|
||||
silenceAlerts()
|
||||
is CommandResumeDelivery ->
|
||||
is CommandResumeDelivery ->
|
||||
resumeDelivery()
|
||||
is CommandDeactivatePod ->
|
||||
is CommandDeactivatePod ->
|
||||
deactivatePod()
|
||||
is CommandHandleTimeChange ->
|
||||
is CommandHandleTimeChange ->
|
||||
handleTimeChange()
|
||||
is CommandUpdateAlertConfiguration ->
|
||||
updateAlertConfiguration()
|
||||
is CommandPlayTestBeep ->
|
||||
is CommandPlayTestBeep ->
|
||||
playTestBeep()
|
||||
is CommandDisableSuspendAlerts ->
|
||||
is CommandDisableSuspendAlerts ->
|
||||
disableSuspendAlerts()
|
||||
else -> {
|
||||
|
||||
else -> {
|
||||
aapsLogger.warn(LTag.PUMP, "Unsupported custom command: " + customCommand.javaClass.name)
|
||||
PumpEnactResult(injector).success(false).enacted(false).comment(
|
||||
rh.gs(
|
||||
|
@ -1231,10 +1214,11 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
expirationHours,
|
||||
lowReservoirAlertEnabled,
|
||||
lowReservoirAlertUnits
|
||||
) -> {
|
||||
) -> {
|
||||
aapsLogger.debug(LTag.PUMP, "Ignoring updateAlertConfiguration because the settings did not change")
|
||||
return PumpEnactResult(injector).success(true).enacted(false)
|
||||
}
|
||||
|
||||
!podStateManager.isPodRunning -> {
|
||||
aapsLogger.debug(LTag.PUMP, "Ignoring updateAlertConfiguration because there is no active pod")
|
||||
return PumpEnactResult(injector).success(true).enacted(false)
|
||||
|
@ -1356,7 +1340,8 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TBR_ALERTS))
|
||||
}
|
||||
OmnipodCommandType.RESUME_DELIVERY -> {
|
||||
|
||||
OmnipodCommandType.RESUME_DELIVERY -> {
|
||||
// We can't invalidate this command,
|
||||
// and this is why it is pumpSync-ed at this point
|
||||
if (confirmation.success) {
|
||||
|
@ -1375,7 +1360,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
OmnipodCommandType.SET_BASAL_PROFILE -> {
|
||||
OmnipodCommandType.SET_BASAL_PROFILE -> {
|
||||
if (confirmation.success) {
|
||||
podStateManager.basalProgram = command.basalProgram
|
||||
if (podStateManager.basalProgram == null) {
|
||||
|
@ -1399,7 +1384,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
OmnipodCommandType.SET_TEMPORARY_BASAL -> {
|
||||
OmnipodCommandType.SET_TEMPORARY_BASAL -> {
|
||||
// This treatment was synced before sending the command
|
||||
if (!confirmation.success) {
|
||||
aapsLogger.info(LTag.PUMPCOMM, "temporary basal denied. PumpId: ${historyEntry.pumpId()}")
|
||||
|
@ -1414,7 +1399,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TBR_ALERTS))
|
||||
}
|
||||
|
||||
OmnipodCommandType.SUSPEND_DELIVERY -> {
|
||||
OmnipodCommandType.SUSPEND_DELIVERY -> {
|
||||
if (!confirmation.success) {
|
||||
pumpSync.invalidateTemporaryBasalWithPumpId(
|
||||
historyEntry.pumpId(),
|
||||
|
@ -1426,7 +1411,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
OmnipodCommandType.SET_BOLUS -> {
|
||||
OmnipodCommandType.SET_BOLUS -> {
|
||||
if (confirmation.success) {
|
||||
if (command.requestedBolus == null) {
|
||||
aapsLogger.error(LTag.PUMP, "Requested bolus not found: $command")
|
||||
|
@ -1459,7 +1444,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_UNCERTAIN_SMB))
|
||||
}
|
||||
|
||||
OmnipodCommandType.CANCEL_BOLUS -> {
|
||||
OmnipodCommandType.CANCEL_BOLUS -> {
|
||||
if (confirmation.success) {
|
||||
podStateManager.lastBolus?.run {
|
||||
val deliveredUnits = markComplete()
|
||||
|
@ -1481,7 +1466,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
else ->
|
||||
else ->
|
||||
aapsLogger.warn(
|
||||
LTag.PUMP,
|
||||
"Will not sync confirmed command of type: $historyEntry and " +
|
||||
|
@ -1508,13 +1493,13 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
|
||||
private fun soundEnabledForNotificationType(notificationType: Int): Boolean {
|
||||
return when (notificationType) {
|
||||
Notification.OMNIPOD_TBR_ALERTS ->
|
||||
Notification.OMNIPOD_TBR_ALERTS ->
|
||||
sp.getBoolean(R.string.key_omnipod_common_notification_uncertain_tbr_sound_enabled, true)
|
||||
Notification.OMNIPOD_UNCERTAIN_SMB ->
|
||||
sp.getBoolean(R.string.key_omnipod_common_notification_uncertain_smb_sound_enabled, true)
|
||||
Notification.OMNIPOD_POD_SUSPENDED ->
|
||||
sp.getBoolean(R.string.key_omnipod_common_notification_delivery_suspended_sound_enabled, true)
|
||||
else -> true
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ class BasalProgram(
|
|||
|
||||
fun hasZeroUnitSegments() = segments.any { it.basalRateInHundredthUnitsPerHour == 0 }
|
||||
|
||||
fun rateAt(date: Date): Double {
|
||||
fun rateAt(date: Long): Double {
|
||||
val instance = Calendar.getInstance()
|
||||
instance.time = date
|
||||
instance.timeInMillis = date
|
||||
val hourOfDay = instance[Calendar.HOUR_OF_DAY]
|
||||
val minuteOfHour = instance[Calendar.MINUTE]
|
||||
val slotIndex = hourOfDay * 2 + minuteOfHour.div(30)
|
||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.Constants
|
|||
import info.nightscout.androidaps.activities.ErrorHelperActivity
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
||||
import info.nightscout.androidaps.interfaces.BuildHelper
|
||||
import info.nightscout.androidaps.interfaces.CommandQueue
|
||||
import info.nightscout.androidaps.interfaces.PumpSync
|
||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
||||
|
@ -39,7 +40,6 @@ import info.nightscout.androidaps.queue.events.EventQueueChanged
|
|||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.interfaces.BuildHelper
|
||||
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.ui.UIRunnable
|
||||
|
@ -52,7 +52,6 @@ import java.time.ZonedDateTime
|
|||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
// TODO generify; see OmnipodErosOverviewFragment
|
||||
class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||
|
@ -274,7 +273,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
R.attr.warningColor
|
||||
connectionSuccessPercentage < 90 && podStateManager.successfulConnectionAttemptsAfterRetries > 50 ->
|
||||
R.attr.omniYellowColor
|
||||
else ->
|
||||
else ->
|
||||
R.attr.defaultTextColor
|
||||
}
|
||||
)
|
||||
|
@ -343,9 +342,9 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
when {
|
||||
!podStateManager.sameTimeZone ->
|
||||
R.attr.omniMagentaColor
|
||||
timeDeviationTooBig ->
|
||||
timeDeviationTooBig ->
|
||||
R.attr.omniYellowColor
|
||||
else ->
|
||||
else ->
|
||||
R.attr.defaultTextColor
|
||||
}
|
||||
)
|
||||
|
@ -361,11 +360,11 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
rh.gac(
|
||||
context,
|
||||
when {
|
||||
expiresAt != null && ZonedDateTime.now().isAfter(expiresAt) ->
|
||||
expiresAt != null && ZonedDateTime.now().isAfter(expiresAt) ->
|
||||
R.attr.warningColor
|
||||
expiresAt != null && ZonedDateTime.now().isAfter(expiresAt.minusHours(4)) ->
|
||||
R.attr.omniYellowColor
|
||||
else ->
|
||||
else ->
|
||||
R.attr.defaultTextColor
|
||||
}
|
||||
)
|
||||
|
@ -387,7 +386,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
rh.gs(
|
||||
R.string.pump_basebasalrate,
|
||||
omnipodDashPumpPlugin.model()
|
||||
.determineCorrectBasalSize(podStateManager.basalProgram!!.rateAt(Date()))
|
||||
.determineCorrectBasalSize(podStateManager.basalProgram!!.rateAt(System.currentTimeMillis()))
|
||||
)
|
||||
} else {
|
||||
PLACEHOLDER
|
||||
|
@ -447,21 +446,21 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
|
||||
private fun translatedActiveAlert(alert: AlertType): String {
|
||||
val id = when (alert) {
|
||||
AlertType.LOW_RESERVOIR ->
|
||||
AlertType.LOW_RESERVOIR ->
|
||||
R.string.omnipod_common_alert_low_reservoir
|
||||
AlertType.EXPIRATION ->
|
||||
AlertType.EXPIRATION ->
|
||||
R.string.omnipod_common_alert_expiration_advisory
|
||||
AlertType.EXPIRATION_IMMINENT ->
|
||||
R.string.omnipod_common_alert_expiration
|
||||
AlertType.USER_SET_EXPIRATION ->
|
||||
R.string.omnipod_common_alert_expiration_advisory
|
||||
AlertType.AUTO_OFF ->
|
||||
AlertType.AUTO_OFF ->
|
||||
R.string.omnipod_common_alert_shutdown_imminent
|
||||
AlertType.SUSPEND_IN_PROGRESS ->
|
||||
R.string.omnipod_common_alert_delivery_suspended
|
||||
AlertType.SUSPEND_ENDED ->
|
||||
AlertType.SUSPEND_ENDED ->
|
||||
R.string.omnipod_common_alert_delivery_suspended
|
||||
else ->
|
||||
else ->
|
||||
R.string.omnipod_common_alert_unknown_alert
|
||||
}
|
||||
return rh.gs(id)
|
||||
|
@ -474,7 +473,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
System.currentTimeMillis() -
|
||||
podStateManager.lastUpdatedSystem,
|
||||
|
||||
)
|
||||
)
|
||||
)
|
||||
val lastConnectionColor =
|
||||
rh.gac(
|
||||
|
@ -528,9 +527,9 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
when {
|
||||
!podStateManager.isActivationCompleted || podStateManager.isPodKaput || podStateManager.isSuspended ->
|
||||
R.attr.warningColor
|
||||
podStateManager.activeCommand != null ->
|
||||
podStateManager.activeCommand != null ->
|
||||
R.attr.omniYellowColor
|
||||
else ->
|
||||
else ->
|
||||
R.attr.defaultTextColor
|
||||
}
|
||||
)
|
||||
|
@ -628,7 +627,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
private fun updateRefreshStatusButton() {
|
||||
buttonBinding.buttonRefreshStatus.isEnabled =
|
||||
podStateManager.isUniqueIdSet &&
|
||||
isQueueEmpty()
|
||||
isQueueEmpty()
|
||||
}
|
||||
|
||||
private fun updateResumeDeliveryButton() {
|
||||
|
@ -695,15 +694,15 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
val minutes = duration.toMinutes().toInt()
|
||||
val seconds = duration.seconds
|
||||
when {
|
||||
seconds < 10 -> {
|
||||
seconds < 10 -> {
|
||||
return rh.gs(R.string.omnipod_common_moments_ago)
|
||||
}
|
||||
|
||||
seconds < 60 -> {
|
||||
seconds < 60 -> {
|
||||
return rh.gs(R.string.omnipod_common_less_than_a_minute_ago)
|
||||
}
|
||||
|
||||
seconds < 60 * 60 -> { // < 1 hour
|
||||
seconds < 60 * 60 -> { // < 1 hour
|
||||
return rh.gs(
|
||||
R.string.omnipod_common_time_ago,
|
||||
rh.gq(R.plurals.omnipod_common_minutes, minutes, minutes)
|
||||
|
@ -727,7 +726,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
else -> {
|
||||
val days = hours / 24
|
||||
val hoursLeft = hours % 24
|
||||
if (hoursLeft > 0)
|
||||
|
|
|
@ -247,12 +247,12 @@ class OpenHumansUploader @Inject internal constructor(
|
|||
tags.add("DisplayInfo")
|
||||
|
||||
val uploadNumber = this.uploadCounter++
|
||||
val uploadDate = Date()
|
||||
val uploadDate = System.currentTimeMillis()
|
||||
val uploadInfo = JSONObject()
|
||||
uploadInfo.put("fileVersion", 2)
|
||||
uploadInfo.put("counter", uploadNumber)
|
||||
uploadInfo.put("timestamp", until)
|
||||
uploadInfo.put("utcOffset", TimeZone.getDefault().getOffset(uploadDate.time))
|
||||
uploadInfo.put("utcOffset", TimeZone.getDefault().getOffset(uploadDate))
|
||||
zos.writeFile("UploadInfo.json", uploadInfo.toString().toByteArray())
|
||||
tags.add("UploadInfo")
|
||||
|
||||
|
@ -521,7 +521,7 @@ class OpenHumansUploader @Inject internal constructor(
|
|||
tags = tags,
|
||||
description = "AndroidAPS Database Upload",
|
||||
md5 = MessageDigest.getInstance("MD5").digest(bytes).toHexString(),
|
||||
creationDate = uploadDate.time
|
||||
creationDate = uploadDate
|
||||
)
|
||||
|
||||
refreshAccessTokenIfNeeded()
|
||||
|
|
Loading…
Reference in a new issue