Commit 2f166836 authored by Christophe Beyls's avatar Christophe Beyls

Delay IntervalLiveData refresh to allow the previous result to be dispatched...

Delay IntervalLiveData refresh to allow the previous result to be dispatched on active even when it's already expired
parent aae57bd3
......@@ -27,11 +27,15 @@ public class LiveDataFactory {
@Override
protected void onActive() {
final long now = SystemClock.elapsedRealtime();
if (now >= updateTime) {
update(now);
if (version == 0L) {
run();
} else {
handler.postDelayed(this, updateTime - now);
final long now = SystemClock.elapsedRealtime();
if (now >= updateTime) {
handler.post(this);
} else {
handler.postDelayed(this, updateTime - now);
}
}
}
......@@ -40,15 +44,11 @@ public class LiveDataFactory {
handler.removeCallbacks(this);
}
private void update(long now) {
setValue(version++);
updateTime = now + periodInMillis;
handler.postDelayed(this, periodInMillis);
}
@Override
public void run() {
update(SystemClock.elapsedRealtime());
setValue(version++);
updateTime = SystemClock.elapsedRealtime() + periodInMillis;
handler.postDelayed(this, periodInMillis);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment