Created
October 26, 2017 12:07
-
-
Save msdx/3a80a2a7fe3048d626a117918392c5fb to your computer and use it in GitHub Desktop.
rxjava countdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Subscription subscription = Observable.interval(0, 1, TimeUnit.SECONDS) | |
.take(seconds + 1) | |
.map(new Func1<Long, Long>() { | |
@Override | |
public Long call(Long past) { | |
return seconds - past - 1; | |
} | |
}) | |
.filter(new Func1<Long, Boolean>() { | |
@Override | |
public Boolean call(Long aLong) { | |
return aLong >= 0; | |
} | |
}) | |
.subscribe(new RxAction<Long>() { | |
@Override | |
public void onNext(Long time) { | |
Log.e("xxxxxx", "onNext" + time); | |
} | |
@Override | |
public void onStart() { | |
Log.e("xxxxxx", "onStart"); | |
} | |
@Override | |
public void onCompleted() { | |
Log.e("xxxxxx", "onCompleted"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
9.8.7.6.5.4.3.2.1.0.complete