version checker plugin logic
This commit is contained in:
parent
84573cc0cc
commit
4bde759a50
|
@ -50,6 +50,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.receivers.DBAccessRec
|
|||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
|
||||
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
|
||||
|
@ -179,6 +180,7 @@ public class MainApp extends Application {
|
|||
if (Config.OTHERPROFILES) pluginsList.add(LocalProfilePlugin.getPlugin());
|
||||
pluginsList.add(TreatmentsPlugin.getPlugin());
|
||||
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
||||
if (Config.SAFETY) pluginsList.add(VersionCheckerPlugin.INSTANCE);
|
||||
if (Config.SAFETY) pluginsList.add(StorageConstraintPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
||||
pluginsList.add(SourceXdripPlugin.getPlugin());
|
||||
|
|
|
@ -74,6 +74,7 @@ public class Notification {
|
|||
public static final int DST_LOOP_DISABLED = 49;
|
||||
public static final int DST_IN_24H = 50;
|
||||
public static final int DISKFULL = 51;
|
||||
public static final int OLDVERSION = 52;
|
||||
|
||||
|
||||
public int id;
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.general.versionChecker
|
||||
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
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
|
||||
|
||||
/**
|
||||
* Usually we would have a class here.
|
||||
|
@ -17,25 +22,43 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
|||
.pluginName(R.string.versionChecker)), ConstraintsInterface {
|
||||
|
||||
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||
return if (isVeryOldVersion())
|
||||
Constraint(false)
|
||||
checkWarning()
|
||||
return if (isOldVersion(GRACE_PERIOD_VERY_OLD))
|
||||
value.set(false, MainApp.gs(R.string.very_old_version), this)
|
||||
else
|
||||
value
|
||||
}
|
||||
|
||||
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
|
||||
return if (isOldVersion())
|
||||
Constraint(0.toDouble())
|
||||
else
|
||||
maxIob
|
||||
private fun checkWarning() {
|
||||
val now = System.currentTimeMillis()
|
||||
if (isOldVersion(GRACE_PERIOD_WARNING) && shouldWarnAgain(now)) {
|
||||
// store last notification time
|
||||
SP.putLong(R.string.key_last_versionchecker_waring, now)
|
||||
|
||||
//notify
|
||||
val message = MainApp.gs(R.string.new_version_warning, Math.round(now / TimeUnit.DAYS.toMillis(1).toDouble()))
|
||||
val notification = Notification(Notification.OLDVERSION, message, Notification.NORMAL)
|
||||
MainApp.bus().post(EventNewNotification(notification))
|
||||
}
|
||||
}
|
||||
|
||||
private fun isOldVersion(): Boolean {
|
||||
return true
|
||||
private fun shouldWarnAgain(now: Long) =
|
||||
now > SP.getLong(R.string.key_last_versionchecker_waring, 0) + WARN_EVERY
|
||||
|
||||
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> =
|
||||
if (isOldVersion(GRACE_PERIOD_OLD))
|
||||
maxIob.set(0.toDouble(), MainApp.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_new_version_available_since, 0) + gracePeriod
|
||||
}
|
||||
|
||||
private fun isVeryOldVersion(): Boolean {
|
||||
return true
|
||||
}
|
||||
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)
|
||||
|
||||
}
|
||||
|
|
|
@ -1328,6 +1328,11 @@
|
|||
<string name="profileswitchcreated">Profile switch created</string>
|
||||
<string name="versionChecker">Version Checker</string>
|
||||
<string name="key_new_version_available_since" translatable="false">new_version_available_since</string>
|
||||
<string name="key_last_versionchecker_waring" translatable="false">last_versionchecker_waring</string>
|
||||
<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>
|
||||
|
||||
<plurals name="objective_days">
|
||||
<item quantity="one">%1$d day</item>
|
||||
<item quantity="other">%1$d days</item>
|
||||
|
|
Loading…
Reference in a new issue