From 8124c0ae4dc0d2c58434acb6c0b1e047843b4586 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 7 Dec 2019 19:15:26 +0100 Subject: [PATCH] RC warnings --- .../versionChecker/VersionCheckerPlugin.kt | 25 +++++++++++++++---- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerPlugin.kt index ee267c689e..f63b2b19fa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/versionChecker/VersionCheckerPlugin.kt @@ -1,5 +1,6 @@ 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.* @@ -8,6 +9,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotifi 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,6 +24,15 @@ object VersionCheckerPlugin : PluginBase(PluginDescription() .showInList(false) .pluginName(R.string.versionChecker)), ConstraintsInterface { + override fun onStart() { + super.onStart() + if (BuildConfig.VERSION_NAME.contains("RC", ignoreCase = false)) { + GRACE_PERIOD_WARNING = TimeUnit.DAYS.toMillis(0) + GRACE_PERIOD_OLD = TimeUnit.DAYS.toMillis(7) + GRACE_PERIOD_VERY_OLD = TimeUnit.DAYS.toMillis(14) + } + } + override fun isClosedLoopAllowed(value: Constraint): Constraint { checkWarning() triggerCheckVersion() @@ -45,7 +56,11 @@ object VersionCheckerPlugin : PluginBase(PluginDescription() 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)) / TimeUnit.DAYS.toMillis(1).toDouble()).roundToInt(), + (GRACE_PERIOD_OLD / TimeUnit.DAYS.toMillis(1).toDouble()).roundToInt(), + (GRACE_PERIOD_VERY_OLD / TimeUnit.DAYS.toMillis(1).toDouble()).roundToInt() + ) val notification = Notification(Notification.OLDVERSION, message, Notification.NORMAL) RxBus.send(EventNewNotification(notification)) } @@ -65,9 +80,9 @@ 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) + 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) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0bb46b85fb..69264a5cdf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1380,7 +1380,7 @@ old version very old version - New version for at least %1$d days available! Fallback to LGS after 60 days, loop will be disabled after 90 days + New version for at least %1$d days available! Fallback to LGS after %2$d days, loop will be disabled after %3$d days 2h %1$.2fU