Instead of the verbose setOnClickListener:
RxView.clicks(submitButton).subscribe(o -> log("submit button clicked!"));Observable
.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)| apply plugin: 'java' | |
| apply plugin: 'maven-publish' | |
| group = 'com.demo' | |
| version = '1.0.0' | |
| sourceCompatibility = 1.7 | |
| repositories { | |
| mavenCentral() |
| about | |
| account | |
| add | |
| admin | |
| api | |
| app | |
| apps | |
| archive | |
| archives | |
| auth |
| public void readTwice() | |
| { | |
| Observable.fromCallable(() -> { | |
| RedditData inflatedModel = null; | |
| Response response = makeRequest(); | |
| String diskValue = null; | |
| try { | |
| File file = new File(getContext().getCacheDir(), "file"); | |
| BufferedSink cacheBody = Okio.buffer(Okio.sink(file)); |
| // retries up to 3 times while exponentially backing off with each retry | |
| .retryWhen(errors -> | |
| errors | |
| .zipWith( | |
| Observable.range(1, MAX_RETRIES), (n, i) -> i | |
| ) | |
| .flatMap( | |
| retryCount -> Observable.timer((long) Math.pow(4, retryCount), TimeUnit.SECONDS) | |
| ) | |
| ) |
| /** | |
| * @param interval The base interval to start backing off from. The function is: attemptNum^2 * intervalTime | |
| * @param units The units for interval | |
| * @param retryAttempts The max number of attempts to retry this task or -1 to try MAX_INT times, | |
| */ | |
| public static <T> Observable.Transformer<T, T> backoff(final long interval, final TimeUnit units, final int retryAttempts) { | |
| return new Observable.Transformer<T, T>() { | |
| @Override | |
| public Observable<T> call(final Observable<T> observable) { | |
| return observable.retryWhen( |