Extract EventNewBg.isCurrent() and use when relevant for decision making.
This commit is contained in:
parent
17d5945a91
commit
c5ebb696a4
5 changed files with 18 additions and 15 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue