check regularly
This commit is contained in:
parent
4bde759a50
commit
092400f7a0
3 changed files with 28 additions and 5 deletions
|
@ -48,7 +48,9 @@ import info.nightscout.androidaps.events.EventFeatureRunning;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
||||||
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerUtilsKt;
|
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerUtilsKt;
|
||||||
|
@ -115,7 +117,11 @@ public class MainActivity extends AppCompatActivity {
|
||||||
public void onPageScrollStateChanged(int state) {
|
public void onPageScrollStateChanged(int state) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Check here if loop plugin is disabled. Else check via constraints
|
||||||
|
if (!LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))
|
||||||
VersionCheckerUtilsKt.checkVersion();
|
VersionCheckerUtilsKt.checkVersion();
|
||||||
|
|
||||||
FabricPrivacy.setUserStats();
|
FabricPrivacy.setUserStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
||||||
|
|
||||||
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
checkWarning()
|
checkWarning()
|
||||||
|
checkUpdate()
|
||||||
return if (isOldVersion(GRACE_PERIOD_VERY_OLD))
|
return if (isOldVersion(GRACE_PERIOD_VERY_OLD))
|
||||||
value.set(false, MainApp.gs(R.string.very_old_version), this)
|
value.set(false, MainApp.gs(R.string.very_old_version), this)
|
||||||
else
|
else
|
||||||
|
@ -33,7 +34,7 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
if (isOldVersion(GRACE_PERIOD_WARNING) && shouldWarnAgain(now)) {
|
if (isOldVersion(GRACE_PERIOD_WARNING) && shouldWarnAgain(now)) {
|
||||||
// store last notification time
|
// store last notification time
|
||||||
SP.putLong(R.string.key_last_versionchecker_waring, now)
|
SP.putLong(R.string.key_last_versionchecker_warning, now)
|
||||||
|
|
||||||
//notify
|
//notify
|
||||||
val message = MainApp.gs(R.string.new_version_warning, Math.round(now / TimeUnit.DAYS.toMillis(1).toDouble()))
|
val message = MainApp.gs(R.string.new_version_warning, Math.round(now / TimeUnit.DAYS.toMillis(1).toDouble()))
|
||||||
|
@ -42,8 +43,21 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkUpdate() {
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
if (shouldCheckVersionAgain(now)) {
|
||||||
|
// store last notification time
|
||||||
|
SP.putLong(R.string.key_last_versioncheck, now)
|
||||||
|
|
||||||
|
checkVersion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun shouldCheckVersionAgain(now: Long) =
|
||||||
|
now > SP.getLong(R.string.key_last_versioncheck, 0) + CHECK_EVERY
|
||||||
|
|
||||||
private fun shouldWarnAgain(now: Long) =
|
private fun shouldWarnAgain(now: Long) =
|
||||||
now > SP.getLong(R.string.key_last_versionchecker_waring, 0) + WARN_EVERY
|
now > SP.getLong(R.string.key_last_versionchecker_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(GRACE_PERIOD_OLD))
|
||||||
|
@ -56,6 +70,7 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
||||||
return now > SP.getLong(R.string.key_new_version_available_since, 0) + gracePeriod
|
return now > SP.getLong(R.string.key_new_version_available_since, 0) + gracePeriod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val CHECK_EVERY = TimeUnit.DAYS.toMillis(1)
|
||||||
val WARN_EVERY = TimeUnit.DAYS.toMillis(1)
|
val WARN_EVERY = TimeUnit.DAYS.toMillis(1)
|
||||||
val GRACE_PERIOD_WARNING = TimeUnit.DAYS.toMillis(30)
|
val GRACE_PERIOD_WARNING = TimeUnit.DAYS.toMillis(30)
|
||||||
val GRACE_PERIOD_OLD = TimeUnit.DAYS.toMillis(60)
|
val GRACE_PERIOD_OLD = TimeUnit.DAYS.toMillis(60)
|
||||||
|
|
|
@ -1328,7 +1328,9 @@
|
||||||
<string name="profileswitchcreated">Profile switch created</string>
|
<string name="profileswitchcreated">Profile switch created</string>
|
||||||
<string name="versionChecker">Version Checker</string>
|
<string name="versionChecker">Version Checker</string>
|
||||||
<string name="key_new_version_available_since" translatable="false">new_version_available_since</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="key_last_versionchecker_warning" translatable="false">last_versionchecker_waring</string>
|
||||||
|
<string name="key_last_versioncheck" translatable="false">key_last_versioncheck</string>
|
||||||
|
|
||||||
<string name="old_version">old version</string>
|
<string name="old_version">old version</string>
|
||||||
<string name="very_old_version">very 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 60 days, loop will be disabled after 90 days</string>
|
||||||
|
|
Loading…
Reference in a new issue