commit
ebe4eecaa5
3 changed files with 43 additions and 22 deletions
|
@ -1,13 +1,19 @@
|
|||
package info.nightscout.androidaps.plugins.constraints.versionChecker
|
||||
|
||||
import info.nightscout.androidaps.BuildConfig
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.interfaces.Constraint
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
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.SP
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Usually we would have a class here.
|
||||
|
@ -22,10 +28,17 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
|||
.showInList(false)
|
||||
.pluginName(R.string.versionChecker)), ConstraintsInterface {
|
||||
|
||||
private val gracePeriod: GracePeriod
|
||||
get() = if ((BuildConfig.VERSION_NAME.contains("RC", ignoreCase = true))) {
|
||||
GracePeriod.RC
|
||||
} else {
|
||||
GracePeriod.RELEASE
|
||||
}
|
||||
|
||||
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
checkWarning()
|
||||
triggerCheckVersion()
|
||||
return if (isOldVersion(GRACE_PERIOD_VERY_OLD))
|
||||
return if (isOldVersion(gracePeriod.veryOld.daysToMillis()))
|
||||
value.set(false, MainApp.gs(R.string.very_old_version), this)
|
||||
else
|
||||
value
|
||||
|
@ -40,12 +53,16 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
|||
}
|
||||
|
||||
|
||||
if (isOldVersion(GRACE_PERIOD_WARNING) && shouldWarnAgain(now)) {
|
||||
if (isOldVersion(gracePeriod.warning.daysToMillis()) && shouldWarnAgain(now)) {
|
||||
// store last notification time
|
||||
SP.putLong(R.string.key_last_versionchecker_plugin_warning, now)
|
||||
|
||||
//notify
|
||||
val message = MainApp.gs(R.string.new_version_warning, Math.round((now - SP.getLong(R.string.key_last_time_this_version_detected, now)) / TimeUnit.DAYS.toMillis(1).toDouble()))
|
||||
val message = MainApp.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.OLDVERSION, message, Notification.NORMAL)
|
||||
RxBus.send(EventNewNotification(notification))
|
||||
}
|
||||
|
@ -55,7 +72,7 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
|||
now > SP.getLong(R.string.key_last_versionchecker_plugin_warning, 0) + WARN_EVERY
|
||||
|
||||
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> =
|
||||
if (isOldVersion(GRACE_PERIOD_OLD))
|
||||
if (isOldVersion(gracePeriod.old.daysToMillis()))
|
||||
maxIob.set(0.toDouble(), MainApp.gs(R.string.old_version), this)
|
||||
else
|
||||
maxIob
|
||||
|
@ -65,9 +82,13 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
|||
return now > SP.getLong(R.string.key_last_time_this_version_detected, 0) + gracePeriod
|
||||
}
|
||||
|
||||
val WARN_EVERY = TimeUnit.DAYS.toMillis(1)
|
||||
val GRACE_PERIOD_WARNING = TimeUnit.DAYS.toMillis(30)
|
||||
val GRACE_PERIOD_OLD = TimeUnit.DAYS.toMillis(60)
|
||||
val GRACE_PERIOD_VERY_OLD = TimeUnit.DAYS.toMillis(90)
|
||||
private val WARN_EVERY = TimeUnit.DAYS.toMillis(1)
|
||||
|
||||
}
|
||||
|
||||
enum class GracePeriod(val warning: Long, val old: Long, val veryOld: Long) {
|
||||
RELEASE(30, 60, 90),
|
||||
RC(0, 7, 14)
|
||||
}
|
||||
|
||||
private fun Long.daysToMillis() = TimeUnit.DAYS.toMillis(this)
|
|
@ -1380,7 +1380,7 @@
|
|||
|
||||
<string name="old_version">old version</string>
|
||||
<string name="very_old_version">very old version</string>
|
||||
<string name="new_version_warning">New version for at least %1$d days available! Fallback to LGS after 60 days, loop will be disabled after 90 days</string>
|
||||
<string name="new_version_warning">New version for at least %1$d days available! Fallback to LGS after %2$d days, loop will be disabled after %3$d days</string>
|
||||
<string name="twohours">2h</string>
|
||||
<string name="formatinsulinunits">%1$.2fU</string>
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ buildscript {
|
|||
maven { url 'https://maven.fabric.io/public' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.2'
|
||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||
classpath 'com.google.gms:google-services:4.3.3'
|
||||
classpath 'io.fabric.tools:gradle:1.31.2'
|
||||
|
||||
|
|
Loading…
Reference in a new issue