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
| public class HomePresenterImpl implements HomePresenter { | |
| private static final String TAG = HomePresenterImpl.class.getSimpleName(); | |
| private final HomeScreen screen; | |
| private final DataProvider provider; | |
| private Subscription subscription1; | |
| public HomePresenterImpl(HomeScreenImpl screen, DataProvider dataProvider) { | |
| this.screen = screen; | |
| this.provider = dataProvider; | |
| } |
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
| public class GcmRegistrationIntentService extends IntentService { | |
| private static final String TAG = "RegIntentService"; | |
| private static final String[] TOPICS = {"global"}; | |
| private PushNotificationManager pushNotificationManager; | |
| private GcmRequestManager gcmRequestManager; | |
| private InstanceID instanceID; | |
| public GcmRegistrationIntentService() { |
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
| final Scheduler.Worker worker = Schedulers.newThread().createWorker(); | |
| worker.schedule(new Action0() { | |
| @Override | |
| public void call() { | |
| if (!mAnimationSet.isStarted()) { | |
| removeViewAt(0); | |
| worker.unsubscribe(); | |
| } else { | |
| worker.schedule(this, 500, TimeUnit.MILLISECONDS); | |
| } |
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
| #build.gradle | |
| # | |
| # compile 'io.reactivex:rxandroid:1.0.1' | |
| # compile 'io.reactivex:rxjava:1.0.14' | |
| # compile 'io.reactivex:rxjava-math:1.0.0' | |
| # compile 'com.jakewharton.rxbinding:rxbinding:0.2.0' | |
| # rxjava | |
| -keep class rx.schedulers.Schedulers { | |
| public static <methods>; |
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
| // slide 75 of this: http://www.slideshare.net/Couchbase/reactive-programmingrxjavaefficientdata-benchristensenmichaelnitschinger | |
| Observable. | |
| .defer(() -> bucket.get("id")) //create new | |
| .retryWhen(attempts -> attempts | |
| .zipWith(Observable.range(1,3), (n, i) -> i) // retry maximum of 3 times | |
| .flatMap(i -> { | |
| System.out.println("Delaying retry by " + i + " second(s)"); | |
| return Observable.timer(i, TimeUnit.SECONDS); //delay the resubscribe | |
| }) |
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
| import rx.Observable | |
| interface RxPermission { | |
| val isGranted: Boolean | |
| fun request(): Observable<Boolean> | |
| } |
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
| // sample 3 UI event | |
| mButton = (Button) findViewById(R.id.button); | |
| Observable<View> clickEventObservable = Observable.create(new Observable.OnSubscribe<View>() { | |
| @Override | |
| public void call(final Subscriber<? super View> subscriber) { | |
| mButton.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| subscriber.onNext(v); | |
| } |
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
| package com.company; | |
| import retrofit.RestAdapter; | |
| import retrofit.http.GET; | |
| import retrofit.http.Path; | |
| import rx.Observable; | |
| import rx.Subscriber; | |
| import rx.functions.Action1; | |
| import rx.functions.Func1; | |
| import rx.functions.Func2; |
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
| public abstract class CachedRefreshable<P, T> extends Refreshable<P, T> { | |
| protected abstract Observable<T> getSourceObservable(P parameters); | |
| /** | |
| * Return the Observable that gets data from a cached source. | |
| * | |
| * @return Observable from cache item, or null if the cache misses. | |
| */ | |
| protected abstract Observable<T> getCachedObservable(P parameters); |
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
| package rx.concurrency; | |
| import android.os.Handler; | |
| import android.os.Looper; | |
| import rx.Scheduler; | |
| import rx.Subscription; | |
| import rx.concurrency.ExecutorScheduler; | |
| import rx.util.AtomicObservableSubscription; | |
| import rx.util.functions.Func2; |