Merge pull request #2251 from MilosKozak/adrian/rc2
rc version refactor
This commit is contained in:
commit
c4cf00cc97
|
@ -3,7 +3,11 @@ package info.nightscout.androidaps.plugins.constraints.versionChecker
|
||||||
import info.nightscout.androidaps.BuildConfig
|
import info.nightscout.androidaps.BuildConfig
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
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.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||||
|
@ -24,19 +28,17 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
||||||
.showInList(false)
|
.showInList(false)
|
||||||
.pluginName(R.string.versionChecker)), ConstraintsInterface {
|
.pluginName(R.string.versionChecker)), ConstraintsInterface {
|
||||||
|
|
||||||
override fun onStart() {
|
private val gracePeriod: GracePeriod
|
||||||
super.onStart()
|
get() = if ((BuildConfig.VERSION_NAME.contains("RC", ignoreCase = true))) {
|
||||||
if (BuildConfig.VERSION_NAME.contains("RC", ignoreCase = true)) {
|
GracePeriod.RC
|
||||||
GRACE_PERIOD_WARNING = TimeUnit.DAYS.toMillis(0)
|
} else {
|
||||||
GRACE_PERIOD_OLD = TimeUnit.DAYS.toMillis(7)
|
GracePeriod.RELEASE
|
||||||
GRACE_PERIOD_VERY_OLD = TimeUnit.DAYS.toMillis(14)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
checkWarning()
|
checkWarning()
|
||||||
triggerCheckVersion()
|
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)
|
value.set(false, MainApp.gs(R.string.very_old_version), this)
|
||||||
else
|
else
|
||||||
value
|
value
|
||||||
|
@ -51,15 +53,15 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isOldVersion(GRACE_PERIOD_WARNING) && shouldWarnAgain(now)) {
|
if (isOldVersion(gracePeriod.warning.daysToMillis()) && shouldWarnAgain(now)) {
|
||||||
// store last notification time
|
// store last notification time
|
||||||
SP.putLong(R.string.key_last_versionchecker_plugin_warning, now)
|
SP.putLong(R.string.key_last_versionchecker_plugin_warning, now)
|
||||||
|
|
||||||
//notify
|
//notify
|
||||||
val message = MainApp.gs(R.string.new_version_warning,
|
val message = MainApp.gs(R.string.new_version_warning,
|
||||||
((now - SP.getLong(R.string.key_last_time_this_version_detected, now)) / TimeUnit.DAYS.toMillis(1).toDouble()).roundToInt(),
|
((now - SP.getLong(R.string.key_last_time_this_version_detected, now)) / 1L.daysToMillis().toDouble()).roundToInt(),
|
||||||
(GRACE_PERIOD_OLD / TimeUnit.DAYS.toMillis(1).toDouble()).roundToInt(),
|
gracePeriod.old,
|
||||||
(GRACE_PERIOD_VERY_OLD / TimeUnit.DAYS.toMillis(1).toDouble()).roundToInt()
|
gracePeriod.veryOld
|
||||||
)
|
)
|
||||||
val notification = Notification(Notification.OLDVERSION, message, Notification.NORMAL)
|
val notification = Notification(Notification.OLDVERSION, message, Notification.NORMAL)
|
||||||
RxBus.send(EventNewNotification(notification))
|
RxBus.send(EventNewNotification(notification))
|
||||||
|
@ -70,7 +72,7 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
||||||
now > SP.getLong(R.string.key_last_versionchecker_plugin_warning, 0) + WARN_EVERY
|
now > SP.getLong(R.string.key_last_versionchecker_plugin_warning, 0) + WARN_EVERY
|
||||||
|
|
||||||
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> =
|
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)
|
maxIob.set(0.toDouble(), MainApp.gs(R.string.old_version), this)
|
||||||
else
|
else
|
||||||
maxIob
|
maxIob
|
||||||
|
@ -81,8 +83,12 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val WARN_EVERY = TimeUnit.DAYS.toMillis(1)
|
private val WARN_EVERY = TimeUnit.DAYS.toMillis(1)
|
||||||
private var GRACE_PERIOD_WARNING = TimeUnit.DAYS.toMillis(30)
|
|
||||||
private var GRACE_PERIOD_OLD = TimeUnit.DAYS.toMillis(60)
|
|
||||||
private var GRACE_PERIOD_VERY_OLD = TimeUnit.DAYS.toMillis(90)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
|
@ -8,7 +8,7 @@ buildscript {
|
||||||
maven { url 'https://maven.fabric.io/public' }
|
maven { url 'https://maven.fabric.io/public' }
|
||||||
}
|
}
|
||||||
dependencies {
|
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 'com.google.gms:google-services:4.3.3'
|
||||||
classpath 'io.fabric.tools:gradle:1.31.2'
|
classpath 'io.fabric.tools:gradle:1.31.2'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue