cleanup
This commit is contained in:
parent
f440394121
commit
d7b822a436
6 changed files with 67 additions and 88 deletions
|
@ -201,7 +201,7 @@ class OpenAPSSMBPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
override fun isSuperBolusEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
value[aapsLogger] = false
|
||||
value.set(aapsLogger, false)
|
||||
return value
|
||||
}
|
||||
}
|
|
@ -57,52 +57,52 @@ class SafetyPlugin @Inject constructor(
|
|||
* Constraints interface
|
||||
*/
|
||||
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
if (!activePlugin.activePump.pumpDescription.isTempBasalCapable) value[aapsLogger, false, rh.gs(R.string.pumpisnottempbasalcapable)] = this
|
||||
if (!activePlugin.activePump.pumpDescription.isTempBasalCapable) value.set(aapsLogger, false, rh.gs(R.string.pumpisnottempbasalcapable), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
val mode = sp.getString(R.string.key_aps_mode, "open")
|
||||
if (mode == "open") value[aapsLogger, false, rh.gs(R.string.closedmodedisabledinpreferences)] = this
|
||||
if (mode == "open") value.set(aapsLogger, false, rh.gs(R.string.closedmodedisabledinpreferences), this)
|
||||
if (!buildHelper.isEngineeringModeOrRelease()) {
|
||||
if (value.value()) {
|
||||
val n = Notification(Notification.TOAST_ALARM, rh.gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL)
|
||||
rxBus.send(EventNewNotification(n))
|
||||
}
|
||||
value[aapsLogger, false, rh.gs(R.string.closed_loop_disabled_on_dev_branch)] = this
|
||||
value.set(aapsLogger, false, rh.gs(R.string.closed_loop_disabled_on_dev_branch), this)
|
||||
}
|
||||
val pump = activePlugin.activePump
|
||||
if (!pump.isFakingTempsByExtendedBoluses && iobCobCalculator.getExtendedBolus(dateUtil.now()) != null) {
|
||||
value[aapsLogger, false, rh.gs(R.string.closed_loop_disabled_with_eb)] = this
|
||||
value.set(aapsLogger, false, rh.gs(R.string.closed_loop_disabled_with_eb), this)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
val enabled = sp.getBoolean(R.string.key_openapsama_useautosens, false)
|
||||
if (!enabled) value[aapsLogger, false, rh.gs(R.string.autosensdisabledinpreferences)] = this
|
||||
if (!enabled) value.set(aapsLogger, false, rh.gs(R.string.autosensdisabledinpreferences), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
val enabled = sp.getBoolean(R.string.key_use_smb, false)
|
||||
if (!enabled) value[aapsLogger, false, rh.gs(R.string.smbdisabledinpreferences)] = this
|
||||
if (!enabled) value.set(aapsLogger, false, rh.gs(R.string.smbdisabledinpreferences), this)
|
||||
val closedLoop = constraintChecker.isClosedLoopAllowed()
|
||||
if (!closedLoop.value()) value[aapsLogger, false, rh.gs(R.string.smbnotallowedinopenloopmode)] = this
|
||||
if (!closedLoop.value()) value.set(aapsLogger, false, rh.gs(R.string.smbnotallowedinopenloopmode), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isUAMEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
val enabled = sp.getBoolean(R.string.key_use_uam, false)
|
||||
if (!enabled) value[aapsLogger, false, rh.gs(R.string.uamdisabledinpreferences)] = this
|
||||
if (!enabled) value.set(aapsLogger, false, rh.gs(R.string.uamdisabledinpreferences), this)
|
||||
val oref1Enabled = sensitivityOref1Plugin.isEnabled()
|
||||
if (!oref1Enabled) value[aapsLogger, false, rh.gs(R.string.uamdisabledoref1notselected)] = this
|
||||
if (!oref1Enabled) value.set(aapsLogger, false, rh.gs(R.string.uamdisabledoref1notselected), this)
|
||||
return value
|
||||
}
|
||||
|
||||
override fun isAdvancedFilteringEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
val bgSource = activePlugin.activeBgSource
|
||||
if (!bgSource.advancedFilteringSupported()) value[aapsLogger, false, rh.gs(R.string.smbalwaysdisabled)] = this
|
||||
if (!bgSource.advancedFilteringSupported()) value.set(aapsLogger, false, rh.gs(R.string.smbalwaysdisabled), this)
|
||||
return value
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ class SafetyPlugin @Inject constructor(
|
|||
|
||||
// do rounding
|
||||
if (pump.pumpDescription.tempBasalStyle == PumpDescription.ABSOLUTE) {
|
||||
absoluteRate[aapsLogger] = Round.roundTo(absoluteRate.value(), pump.pumpDescription.tempAbsoluteStep)
|
||||
absoluteRate.set(aapsLogger, Round.roundTo(absoluteRate.value(), pump.pumpDescription.tempAbsoluteStep))
|
||||
}
|
||||
return absoluteRate
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ class SafetyPlugin @Inject constructor(
|
|||
val pump = activePlugin.activePump
|
||||
var percentRateAfterConst = java.lang.Double.valueOf(absoluteConstraint.value() / currentBasal * 100).toInt()
|
||||
percentRateAfterConst = if (percentRateAfterConst < 100) Round.ceilTo(percentRateAfterConst.toDouble(), pump.pumpDescription.tempPercentStep.toDouble()).toInt() else Round.floorTo(percentRateAfterConst.toDouble(), pump.pumpDescription.tempPercentStep.toDouble()).toInt()
|
||||
percentRate[aapsLogger, percentRateAfterConst, String.format(rh.gs(R.string.limitingpercentrate), percentRateAfterConst, rh.gs(R.string.pumplimit))] = this
|
||||
percentRate.set(aapsLogger, percentRateAfterConst, String.format(rh.gs(R.string.limitingpercentrate), percentRateAfterConst, rh.gs(R.string.pumplimit)), this)
|
||||
if (pump.pumpDescription.tempBasalStyle == PumpDescription.PERCENT) {
|
||||
val pumpLimit = pump.pumpDescription.pumpType.tbrSettings?.maxDose ?: 0.0
|
||||
percentRate.setIfSmaller(aapsLogger, pumpLimit.toInt(), String.format(rh.gs(R.string.limitingbasalratio), pumpLimit, rh.gs(R.string.pumplimit)), this)
|
||||
|
|
|
@ -4,13 +4,13 @@ import dagger.android.HasAndroidInjector
|
|||
import info.nightscout.androidaps.BuildConfig
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.extensions.daysToMillis
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
@ -59,59 +59,55 @@ class VersionCheckerPlugin @Inject constructor(
|
|||
checkWarning()
|
||||
versionCheckerUtils.triggerCheckVersion()
|
||||
if (isOldVersion(gracePeriod.veryOld.daysToMillis()))
|
||||
value[aapsLogger, false, rh.gs(R.string.very_old_version)] = this
|
||||
val endDate = sp.getLong(rh.gs(info.nightscout.androidaps.core.R.string.key_app_expiration) + "_" + config.VERSION_NAME, 0)
|
||||
value.set(aapsLogger, false, rh.gs(R.string.very_old_version), this)
|
||||
val endDate = sp.getLong(rh.gs(R.string.key_app_expiration) + "_" + config.VERSION_NAME, 0)
|
||||
if (endDate != 0L && dateUtil.now() > endDate)
|
||||
value[aapsLogger, false, rh.gs(R.string.application_expired)] = this
|
||||
value.set(aapsLogger, false, rh.gs(R.string.application_expired), this)
|
||||
return value
|
||||
}
|
||||
|
||||
private fun checkWarning() {
|
||||
val now = System.currentTimeMillis()
|
||||
|
||||
if (!sp.contains(R.string.key_last_versionchecker_plugin_warning)) {
|
||||
sp.putLong(R.string.key_last_versionchecker_plugin_warning, now)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (isOldVersion(gracePeriod.warning.daysToMillis()) && shouldWarnAgain(now)) {
|
||||
// store last notification time
|
||||
sp.putLong(R.string.key_last_versionchecker_plugin_warning, now)
|
||||
|
||||
//notify
|
||||
val message = rh.gs(
|
||||
R.string.new_version_warning,
|
||||
((now - sp.getLong(R.string.key_last_time_this_version_detected, now)) / 1L.daysToMillis().toDouble()).roundToInt(),
|
||||
gracePeriod.old,
|
||||
gracePeriod.veryOld
|
||||
)
|
||||
val notification = Notification(Notification.OLD_VERSION, message, Notification.NORMAL)
|
||||
rxBus.send(EventNewNotification(notification))
|
||||
}
|
||||
|
||||
val endDate = sp.getLong(rh.gs(info.nightscout.androidaps.core.R.string.key_app_expiration) + "_" + config.VERSION_NAME, 0)
|
||||
if (endDate != 0L && dateUtil.now() > endDate && shouldWarnAgain(now)) {
|
||||
// store last notification time
|
||||
sp.putLong(R.string.key_last_versionchecker_plugin_warning, now)
|
||||
|
||||
//notify
|
||||
val notification = Notification(Notification.VERSION_EXPIRE, rh.gs(R.string.application_expired), Notification.URGENT)
|
||||
rxBus.send(EventNewNotification(notification))
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldWarnAgain(now: Long) =
|
||||
now > sp.getLong(R.string.key_last_versionchecker_plugin_warning, 0) + WARN_EVERY
|
||||
|
||||
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> =
|
||||
if (isOldVersion(gracePeriod.old.daysToMillis()))
|
||||
maxIob.set(aapsLogger, 0.0, rh.gs(R.string.old_version), this)
|
||||
else
|
||||
maxIob
|
||||
|
||||
private fun isOldVersion(gracePeriod: Long): Boolean {
|
||||
val now = System.currentTimeMillis()
|
||||
return now > sp.getLong(R.string.key_last_time_this_version_detected, 0) + gracePeriod
|
||||
private fun checkWarning() {
|
||||
val now = dateUtil.now()
|
||||
|
||||
if (!sp.contains(R.string.key_last_versionchecker_plugin_warning)) {
|
||||
sp.putLong(R.string.key_last_versionchecker_plugin_warning, now)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (isOldVersion(gracePeriod.warning.daysToMillis()) && shouldWarnAgain()) {
|
||||
// store last notification time
|
||||
sp.putLong(R.string.key_last_versionchecker_plugin_warning, now)
|
||||
|
||||
//notify
|
||||
val message = rh.gs(
|
||||
R.string.new_version_warning,
|
||||
((now - sp.getLong(R.string.key_last_time_this_version_detected_as_ok, now)) / 1L.daysToMillis().toDouble()).roundToInt(),
|
||||
gracePeriod.old,
|
||||
gracePeriod.veryOld
|
||||
)
|
||||
rxBus.send(EventNewNotification(Notification(Notification.OLD_VERSION, message, Notification.NORMAL)))
|
||||
}
|
||||
|
||||
val endDate = sp.getLong(rh.gs(R.string.key_app_expiration) + "_" + config.VERSION_NAME, 0)
|
||||
if (endDate != 0L && dateUtil.now() > endDate && shouldWarnAgain()) {
|
||||
// store last notification time
|
||||
sp.putLong(R.string.key_last_versionchecker_plugin_warning, now)
|
||||
|
||||
//notify
|
||||
rxBus.send(EventNewNotification(Notification(Notification.VERSION_EXPIRE, rh.gs(R.string.application_expired), Notification.URGENT)))
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldWarnAgain() =
|
||||
dateUtil.now() > sp.getLong(R.string.key_last_versionchecker_plugin_warning, 0) + WARN_EVERY
|
||||
|
||||
private fun isOldVersion(gracePeriod: Long): Boolean =
|
||||
dateUtil.now() > sp.getLong(R.string.key_last_time_this_version_detected_as_ok, 0) + gracePeriod
|
||||
}
|
||||
|
|
|
@ -17,14 +17,14 @@ class Constraint<T : Comparable<T>>(private var value: T) {
|
|||
return originalValue
|
||||
}
|
||||
|
||||
operator fun set(aapsLogger: AAPSLogger, value: T): Constraint<T> {
|
||||
fun set(aapsLogger: AAPSLogger, value: T): Constraint<T> {
|
||||
this.value = value
|
||||
originalValue = value
|
||||
aapsLogger.debug(LTag.CONSTRAINTS, "Setting value $value")
|
||||
return this
|
||||
}
|
||||
|
||||
operator fun set(aapsLogger: AAPSLogger, value: T, reason: String, from: Any): Constraint<T> {
|
||||
fun set(aapsLogger: AAPSLogger, value: T, reason: String, from: Any): Constraint<T> {
|
||||
aapsLogger.debug(LTag.CONSTRAINTS, "Setting value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]")
|
||||
this.value = value
|
||||
addReason(reason, from)
|
||||
|
|
|
@ -34,20 +34,13 @@ class VersionCheckerUtils @Inject constructor(
|
|||
|
||||
fun triggerCheckVersion() {
|
||||
|
||||
if (!sp.contains(R.string.key_last_time_this_version_detected)) {
|
||||
if (!sp.contains(R.string.key_last_time_this_version_detected_as_ok)) {
|
||||
// On a new installation, set it as 30 days old in order to warn that there is a new version.
|
||||
sp.putLong(
|
||||
R.string.key_last_time_this_version_detected,
|
||||
dateUtil.now() - TimeUnit.DAYS.toMillis(30)
|
||||
)
|
||||
sp.putLong(R.string.key_last_time_this_version_detected_as_ok, dateUtil.now() - TimeUnit.DAYS.toMillis(30))
|
||||
}
|
||||
|
||||
// If we are good, only check once every day.
|
||||
if (dateUtil.now() > sp.getLong(
|
||||
R.string.key_last_time_this_version_detected,
|
||||
0
|
||||
) + CHECK_EVERY
|
||||
) {
|
||||
if (dateUtil.now() > sp.getLong(R.string.key_last_time_this_version_detected_as_ok, 0) + CHECK_EVERY) {
|
||||
checkVersion()
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +61,7 @@ class VersionCheckerUtils @Inject constructor(
|
|||
sp.putLong(rh.gs(R.string.key_app_expiration) + "_" + config.VERSION_NAME, endDate)
|
||||
}
|
||||
}
|
||||
if (endDate != 0L) onExpiredVersionDetected(config.VERSION_NAME, dateUtil.dateString(endDate))
|
||||
if (endDate != 0L) onExpireDateDetected(config.VERSION_NAME, dateUtil.dateString(endDate))
|
||||
|
||||
} catch (e: IOException) {
|
||||
aapsLogger.error(LTag.CORE, "Github master version check error: $e")
|
||||
|
@ -111,11 +104,11 @@ class VersionCheckerUtils @Inject constructor(
|
|||
|
||||
private fun onOlderVersionDetected() {
|
||||
aapsLogger.debug(LTag.CORE, "Version newer than master. Are you developer?")
|
||||
sp.putLong(R.string.key_last_time_this_version_detected, dateUtil.now())
|
||||
sp.putLong(R.string.key_last_time_this_version_detected_as_ok, dateUtil.now())
|
||||
}
|
||||
|
||||
private fun onSameVersionDetected() {
|
||||
sp.putLong(R.string.key_last_time_this_version_detected, dateUtil.now())
|
||||
sp.putLong(R.string.key_last_time_this_version_detected_as_ok, dateUtil.now())
|
||||
}
|
||||
|
||||
private fun onVersionNotDetectable() {
|
||||
|
@ -126,26 +119,16 @@ class VersionCheckerUtils @Inject constructor(
|
|||
val now = dateUtil.now()
|
||||
if (now > sp.getLong(R.string.key_last_versionchecker_warning, 0) + WARN_EVERY) {
|
||||
aapsLogger.debug(LTag.CORE, "Version $currentVersion outdated. Found $newVersion")
|
||||
val notification = Notification(
|
||||
Notification.NEW_VERSION_DETECTED,
|
||||
rh.gs(R.string.versionavailable, newVersion.toString()),
|
||||
Notification.LOW
|
||||
)
|
||||
rxBus.send(EventNewNotification(notification))
|
||||
rxBus.send(EventNewNotification(Notification(Notification.NEW_VERSION_DETECTED, rh.gs(R.string.versionavailable, newVersion.toString()), Notification.LOW)))
|
||||
sp.putLong(R.string.key_last_versionchecker_warning, now)
|
||||
}
|
||||
}
|
||||
|
||||
private fun onExpiredVersionDetected(currentVersion: String, endDate: String?) {
|
||||
private fun onExpireDateDetected(currentVersion: String, endDate: String?) {
|
||||
val now = dateUtil.now()
|
||||
if (now > sp.getLong(R.string.key_last_expired_versionchecker_warning, 0) + WARN_EVERY) {
|
||||
aapsLogger.debug(LTag.CORE, "Version $currentVersion expired.")
|
||||
val notification = Notification(
|
||||
Notification.VERSION_EXPIRE,
|
||||
rh.gs(R.string.version_expire, currentVersion, endDate),
|
||||
Notification.LOW
|
||||
)
|
||||
rxBus.send(EventNewNotification(notification))
|
||||
aapsLogger.debug(LTag.CORE, rh.gs(R.string.version_expire, currentVersion, endDate))
|
||||
rxBus.send(EventNewNotification(Notification(Notification.VERSION_EXPIRE, rh.gs(R.string.version_expire, currentVersion, endDate), Notification.LOW)))
|
||||
sp.putLong(R.string.key_last_expired_versionchecker_warning, now)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -371,7 +371,7 @@
|
|||
<string name="prefdecrypt_issue_wrong_algorithm">Unsupported or not specified encryption algorithm!</string>
|
||||
|
||||
<!-- VersionChecker -->
|
||||
<string name="key_last_time_this_version_detected" translatable="false">last_time_this_version_detected</string>
|
||||
<string name="key_last_time_this_version_detected_as_ok" translatable="false">last_time_this_version_detected</string>
|
||||
<string name="key_last_versionchecker_warning" translatable="false">last_versionchecker_warning</string>
|
||||
<string name="key_last_expired_versionchecker_warning" translatable="false">last_expired_version_checker_warning</string>
|
||||
<string name="key_last_versionchecker_plugin_warning" translatable="false">last_versionchecker_plugin_waring</string>
|
||||
|
|
Loading…
Reference in a new issue