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
| /** | |
| * The Observable that emits the items emitted by the [src] Observable when a | |
| * second ObservableSource, [whenSrc], emits an true; It buffers all them items | |
| * emitted by the [src] when [whenSrc] emits an false. | |
| */ | |
| open class TakeWhenObservable<T>(private val src: ObservableSource<T>, | |
| private val whenSrc: ObservableSource<Boolean>, | |
| private val bufferSize: Int = Flowable.bufferSize()) | |
| : Observable<T>() { |
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 final class LambdaObserver<T> | |
| extends AtomicReference<Disposable> | |
| implements Observer<T>, | |
| Disposable, | |
| LambdaConsumerIntrospection { | |
| // ... | |
| @Override | |
| public void onComplete() { |
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
| class BindWidgetWithModel<T>(widget: IWidget<T>, | |
| model: T, | |
| caughtErrorSignal: Observer<Throwable>? = null) | |
| : Observable<Boolean>() { | |
| private val mWidget = widget | |
| private val mModel = model | |
| private val mCaughtErrorSignal = caughtErrorSignal |
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 final class ConsumerSingleObserver<T> | |
| extends AtomicReference<Disposable> | |
| implements SingleObserver<T>, | |
| Disposable, | |
| LambdaConsumerIntrospection { | |
| // ... | |
| @Override | |
| public void onSubscribe(Disposable d) { |
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
| class FooSingle : Single<Boolean>() { | |
| override fun subscribeActual(observer: SingleObserver<in Boolean>) { | |
| val d = FooDisposable(mWidget) | |
| observer.onSubscribe(d) | |
| try { | |
| // Allocate memory or register listeners... | |
| // Tell the observer the sole result |
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 class ViewClickObservable extends Observable<Object> { | |
| private final View view; | |
| ViewClickObservable(View view) { | |
| this.view = view; | |
| } | |
| @Override | |
| protected void subscribeActual(Observer<? super Object> observer) { | |
| Listener listener = new Listener(view); |
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 static Observable<Object> clicks(View view) { | |
| return new ViewClickObservable(view); | |
| } |
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
| // Whatever Activity | |
| private val mDisposables = CompositeDisposable() | |
| private val mBtnFoo by lazy { findViewById<View>(R.id.foo) } | |
| override fun onResume() { | |
| mDisposables.add( | |
| RxView.click(mBtnFoo) | |
| .subscribe { | |
| println("oh click on Foo") |
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
| // Copyright Feb 2018-present [email protected] | |
| // | |
| // Original authors: Robert Sedgewick and Kevin Wayne | |
| // Maintainer author: TAI CHUN WANG | |
| // | |
| // Permission is hereby granted, free of charge, to any person obtaining | |
| // a copy of this software and associated documentation files (the "Software"), | |
| // to deal in the Software without restriction, including without limitation | |
| // the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
| // and/or sell copies of the Software, and to permit persons to whom the |
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
| private val mDisposablesOnCreate = CompositeDisposable() | |
| // Activity onCreate(). | |
| override fun onCreate() { | |
| // Long computation operation. | |
| mDisposablesOnCreate.add( | |
| // Share button. | |
| onClickShare() | |
| .switchMap { _ -> | |
| // First, switchMap convert the click to an action observable. |