Extract EventNewBg.isCurrent() and use when relevant for decision making.

This commit is contained in:
Johannes Mockenhaupt 2018-03-18 11:26:15 +01:00
parent 17d5945a91
commit c5ebb696a4
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
5 changed files with 18 additions and 15 deletions

View file

@ -13,6 +13,11 @@ public class EventNewBG extends EventLoop {
public final boolean isNew;
public final boolean isFromActiveBgSource;
/** Whether the BgReading is current (enough to use for treatment decisions). */
public boolean isCurrent() {
return bgReading != null && bgReading.date + 9 * 60 * 1000 > System.currentTimeMillis();
}
public EventNewBG(@Nullable BgReading bgReading, boolean isNew, boolean isFromActiveBgSource) {
this.bgReading = bgReading;
this.isNew = isNew;

View file

@ -164,9 +164,7 @@ public class LoopPlugin implements PluginBase {
return;
EventNewBG bgEv = (EventNewBG) ev.cause;
BgReading bg = bgEv.bgReading;
if (bgEv.isNew && bgEv.isFromActiveBgSource
&& bg != null && bg.date + 9 * 60 * 1000 > System.currentTimeMillis()) {
if (bgEv.isNew && bgEv.isFromActiveBgSource && bgEv.isCurrent()) {
invoke("New BG", true);
}
}

View file

@ -142,8 +142,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
@Subscribe
public void onStatusEvent(final EventNewBG e) {
if (!e.isFromActiveBgSource || !e.isNew)
return;
if (e.isFromActiveBgSource && e.isNew && e.isCurrent()) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@ -153,6 +152,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
}
});
}
}
@Subscribe
public void onStatusEvent(final EventAutosensCalculationFinished e) {

View file

@ -255,7 +255,7 @@ public class PersistentNotificationPlugin implements PluginBase {
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
if (ev.isFromActiveBgSource && ev.isNew)
if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent())
updateNotification();
}

View file

@ -235,7 +235,7 @@ public class StatuslinePlugin implements PluginBase {
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
if (ev.isFromActiveBgSource && ev.isNew)
if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent())
sendStatus();
}