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
|
* @return
|
||||||
*/
|
*/
|
||||||
private fun constructName(): String {
|
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>) {
|
private fun zip(zipFile: File?, files: List<File>) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class EventNSClientNewLog(var action: String, var logText: String) : Event() {
|
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())
|
private var timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
rh: ResourceHelper,
|
rh: ResourceHelper,
|
||||||
commandQueue: CommandQueue
|
commandQueue: CommandQueue
|
||||||
) : PumpPluginBase(pluginDescription, injector, aapsLogger, rh, commandQueue), Pump {
|
) : PumpPluginBase(pluginDescription, injector, aapsLogger, rh, commandQueue), Pump {
|
||||||
|
|
||||||
@Volatile var bolusCanceled = false
|
@Volatile var bolusCanceled = false
|
||||||
@Volatile var bolusDeliveryInProgress = false
|
@Volatile var bolusDeliveryInProgress = false
|
||||||
|
|
||||||
|
@ -95,6 +96,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
private var disposables: CompositeDisposable = CompositeDisposable()
|
private var disposables: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val BOLUS_RETRY_INTERVAL_MS = 2000.toLong()
|
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 BOLUS_RETRIES = 5 // number of retries for cancel/get bolus status
|
||||||
private const val STATUS_CHECK_INTERVAL_MS = (60L * 1000)
|
private const val STATUS_CHECK_INTERVAL_MS = (60L * 1000)
|
||||||
|
@ -460,22 +462,10 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
.observeOn(aapsSchedulers.main)
|
.observeOn(aapsSchedulers.main)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
{
|
{
|
||||||
if (it.isChanged(
|
if (it.isChanged(rh, R.string.key_omnipod_common_expiration_reminder_enabled) ||
|
||||||
rh,
|
it.isChanged(rh, R.string.key_omnipod_common_expiration_reminder_hours_before_shutdown) ||
|
||||||
R.string.key_omnipod_common_expiration_reminder_enabled
|
it.isChanged(rh, R.string.key_omnipod_common_low_reservoir_alert_enabled) ||
|
||||||
) ||
|
it.isChanged(rh, R.string.key_omnipod_common_low_reservoir_alert_units)
|
||||||
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)
|
commandQueue.customCommand(CommandUpdateAlertConfiguration(), null)
|
||||||
}
|
}
|
||||||
|
@ -519,7 +509,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
|
|
||||||
override val baseBasalRate: Double
|
override val baseBasalRate: Double
|
||||||
get() {
|
get() {
|
||||||
val date = Date()
|
val date = System.currentTimeMillis()
|
||||||
val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0
|
val ret = podStateManager.basalProgram?.rateAt(date) ?: 0.0
|
||||||
aapsLogger.info(LTag.PUMP, "baseBasalRate: $ret at $date}")
|
aapsLogger.info(LTag.PUMP, "baseBasalRate: $ret at $date}")
|
||||||
return if (podStateManager.alarmType != null) {
|
return if (podStateManager.alarmType != null) {
|
||||||
|
@ -626,20 +616,15 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if (podStateManager.activeCommand != null) {
|
if (podStateManager.activeCommand != null) {
|
||||||
val sound = if (sp.getBoolean(
|
val sound =
|
||||||
|
if (sp.getBoolean(
|
||||||
R.string
|
R.string
|
||||||
.key_omnipod_common_notification_uncertain_bolus_sound_enabled,
|
.key_omnipod_common_notification_uncertain_bolus_sound_enabled, true
|
||||||
true
|
|
||||||
)
|
)
|
||||||
)
|
) R.raw.boluserror
|
||||||
R.raw.boluserror
|
else 0
|
||||||
else
|
|
||||||
0
|
|
||||||
|
|
||||||
showErrorDialog(
|
showErrorDialog("Bolus delivery status uncertain. Refresh pod status to confirm or deny.", sound)
|
||||||
"Bolus delivery status uncertain. Refresh pod status to confirm or deny.",
|
|
||||||
sound
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.toSingle {
|
}.toSingle {
|
||||||
|
@ -1000,12 +985,9 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
val extended = JSONObject()
|
val extended = JSONObject()
|
||||||
try {
|
try {
|
||||||
val podStatus = when {
|
val podStatus = when {
|
||||||
podStateManager.isPodRunning && podStateManager.isSuspended ->
|
podStateManager.isPodRunning && podStateManager.isSuspended -> "suspended"
|
||||||
"suspended"
|
podStateManager.isPodRunning -> "normal"
|
||||||
podStateManager.isPodRunning ->
|
else -> "no active Pod"
|
||||||
"normal"
|
|
||||||
else ->
|
|
||||||
"no active Pod"
|
|
||||||
}
|
}
|
||||||
status.put("status", podStatus)
|
status.put("status", podStatus)
|
||||||
status.put("timestamp", dateUtil.toISOString(podStateManager.lastUpdatedSystem))
|
status.put("timestamp", dateUtil.toISOString(podStateManager.lastUpdatedSystem))
|
||||||
|
@ -1122,6 +1104,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
playTestBeep()
|
playTestBeep()
|
||||||
is CommandDisableSuspendAlerts ->
|
is CommandDisableSuspendAlerts ->
|
||||||
disableSuspendAlerts()
|
disableSuspendAlerts()
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
aapsLogger.warn(LTag.PUMP, "Unsupported custom command: " + customCommand.javaClass.name)
|
aapsLogger.warn(LTag.PUMP, "Unsupported custom command: " + customCommand.javaClass.name)
|
||||||
PumpEnactResult(injector).success(false).enacted(false).comment(
|
PumpEnactResult(injector).success(false).enacted(false).comment(
|
||||||
|
@ -1235,6 +1218,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
aapsLogger.debug(LTag.PUMP, "Ignoring updateAlertConfiguration because the settings did not change")
|
aapsLogger.debug(LTag.PUMP, "Ignoring updateAlertConfiguration because the settings did not change")
|
||||||
return PumpEnactResult(injector).success(true).enacted(false)
|
return PumpEnactResult(injector).success(true).enacted(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
!podStateManager.isPodRunning -> {
|
!podStateManager.isPodRunning -> {
|
||||||
aapsLogger.debug(LTag.PUMP, "Ignoring updateAlertConfiguration because there is no active pod")
|
aapsLogger.debug(LTag.PUMP, "Ignoring updateAlertConfiguration because there is no active pod")
|
||||||
return PumpEnactResult(injector).success(true).enacted(false)
|
return PumpEnactResult(injector).success(true).enacted(false)
|
||||||
|
@ -1356,6 +1340,7 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TBR_ALERTS))
|
rxBus.send(EventDismissNotification(Notification.OMNIPOD_TBR_ALERTS))
|
||||||
}
|
}
|
||||||
|
|
||||||
OmnipodCommandType.RESUME_DELIVERY -> {
|
OmnipodCommandType.RESUME_DELIVERY -> {
|
||||||
// We can't invalidate this command,
|
// We can't invalidate this command,
|
||||||
// and this is why it is pumpSync-ed at this point
|
// and this is why it is pumpSync-ed at this point
|
||||||
|
|
|
@ -15,9 +15,9 @@ class BasalProgram(
|
||||||
|
|
||||||
fun hasZeroUnitSegments() = segments.any { it.basalRateInHundredthUnitsPerHour == 0 }
|
fun hasZeroUnitSegments() = segments.any { it.basalRateInHundredthUnitsPerHour == 0 }
|
||||||
|
|
||||||
fun rateAt(date: Date): Double {
|
fun rateAt(date: Long): Double {
|
||||||
val instance = Calendar.getInstance()
|
val instance = Calendar.getInstance()
|
||||||
instance.time = date
|
instance.timeInMillis = date
|
||||||
val hourOfDay = instance[Calendar.HOUR_OF_DAY]
|
val hourOfDay = instance[Calendar.HOUR_OF_DAY]
|
||||||
val minuteOfHour = instance[Calendar.MINUTE]
|
val minuteOfHour = instance[Calendar.MINUTE]
|
||||||
val slotIndex = hourOfDay * 2 + minuteOfHour.div(30)
|
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.activities.ErrorHelperActivity
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
||||||
|
import info.nightscout.androidaps.interfaces.BuildHelper
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueue
|
import info.nightscout.androidaps.interfaces.CommandQueue
|
||||||
import info.nightscout.androidaps.interfaces.PumpSync
|
import info.nightscout.androidaps.interfaces.PumpSync
|
||||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
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.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
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.protection.ProtectionCheck
|
||||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||||
import info.nightscout.androidaps.utils.ui.UIRunnable
|
import info.nightscout.androidaps.utils.ui.UIRunnable
|
||||||
|
@ -52,7 +52,6 @@ import java.time.ZonedDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
|
|
||||||
// TODO generify; see OmnipodErosOverviewFragment
|
// TODO generify; see OmnipodErosOverviewFragment
|
||||||
class OmnipodDashOverviewFragment : DaggerFragment() {
|
class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
|
@ -387,7 +386,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
||||||
rh.gs(
|
rh.gs(
|
||||||
R.string.pump_basebasalrate,
|
R.string.pump_basebasalrate,
|
||||||
omnipodDashPumpPlugin.model()
|
omnipodDashPumpPlugin.model()
|
||||||
.determineCorrectBasalSize(podStateManager.basalProgram!!.rateAt(Date()))
|
.determineCorrectBasalSize(podStateManager.basalProgram!!.rateAt(System.currentTimeMillis()))
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
PLACEHOLDER
|
PLACEHOLDER
|
||||||
|
|
|
@ -247,12 +247,12 @@ class OpenHumansUploader @Inject internal constructor(
|
||||||
tags.add("DisplayInfo")
|
tags.add("DisplayInfo")
|
||||||
|
|
||||||
val uploadNumber = this.uploadCounter++
|
val uploadNumber = this.uploadCounter++
|
||||||
val uploadDate = Date()
|
val uploadDate = System.currentTimeMillis()
|
||||||
val uploadInfo = JSONObject()
|
val uploadInfo = JSONObject()
|
||||||
uploadInfo.put("fileVersion", 2)
|
uploadInfo.put("fileVersion", 2)
|
||||||
uploadInfo.put("counter", uploadNumber)
|
uploadInfo.put("counter", uploadNumber)
|
||||||
uploadInfo.put("timestamp", until)
|
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())
|
zos.writeFile("UploadInfo.json", uploadInfo.toString().toByteArray())
|
||||||
tags.add("UploadInfo")
|
tags.add("UploadInfo")
|
||||||
|
|
||||||
|
@ -521,7 +521,7 @@ class OpenHumansUploader @Inject internal constructor(
|
||||||
tags = tags,
|
tags = tags,
|
||||||
description = "AndroidAPS Database Upload",
|
description = "AndroidAPS Database Upload",
|
||||||
md5 = MessageDigest.getInstance("MD5").digest(bytes).toHexString(),
|
md5 = MessageDigest.getInstance("MD5").digest(bytes).toHexString(),
|
||||||
creationDate = uploadDate.time
|
creationDate = uploadDate
|
||||||
)
|
)
|
||||||
|
|
||||||
refreshAccessTokenIfNeeded()
|
refreshAccessTokenIfNeeded()
|
||||||
|
|
Loading…
Reference in a new issue