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 isNew;
|
||||||
public final boolean isFromActiveBgSource;
|
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) {
|
public EventNewBG(@Nullable BgReading bgReading, boolean isNew, boolean isFromActiveBgSource) {
|
||||||
this.bgReading = bgReading;
|
this.bgReading = bgReading;
|
||||||
this.isNew = isNew;
|
this.isNew = isNew;
|
||||||
|
|
|
@ -164,9 +164,7 @@ public class LoopPlugin implements PluginBase {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EventNewBG bgEv = (EventNewBG) ev.cause;
|
EventNewBG bgEv = (EventNewBG) ev.cause;
|
||||||
BgReading bg = bgEv.bgReading;
|
if (bgEv.isNew && bgEv.isFromActiveBgSource && bgEv.isCurrent()) {
|
||||||
if (bgEv.isNew && bgEv.isFromActiveBgSource
|
|
||||||
&& bg != null && bg.date + 9 * 60 * 1000 > System.currentTimeMillis()) {
|
|
||||||
invoke("New BG", true);
|
invoke("New BG", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,8 +142,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG e) {
|
public void onStatusEvent(final EventNewBG e) {
|
||||||
if (!e.isFromActiveBgSource || !e.isNew)
|
if (e.isFromActiveBgSource && e.isNew && e.isCurrent()) {
|
||||||
return;
|
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null)
|
if (activity != null)
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
@ -153,6 +152,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventAutosensCalculationFinished e) {
|
public void onStatusEvent(final EventAutosensCalculationFinished e) {
|
||||||
|
|
|
@ -255,7 +255,7 @@ public class PersistentNotificationPlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG ev) {
|
public void onStatusEvent(final EventNewBG ev) {
|
||||||
if (ev.isFromActiveBgSource && ev.isNew)
|
if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent())
|
||||||
updateNotification();
|
updateNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewBG ev) {
|
public void onStatusEvent(final EventNewBG ev) {
|
||||||
if (ev.isFromActiveBgSource && ev.isNew)
|
if (ev.isFromActiveBgSource && ev.isNew && ev.isCurrent())
|
||||||
sendStatus();
|
sendStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue