This file contains 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
Observable<Object> tapEventEmitter = _rxBus.toObserverable().share(); | |
Observable<Object> debouncedEventEmitter = tapEventEmitter.debounce(1, TimeUnit.SECONDS); | |
Observable<List<Object>> debouncedBufferEmitter = tapEventEmitter.buffer(debouncedEventEmitter); | |
debouncedBufferEmitter.buffer(debouncedEventEmitter) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(new Action1<List<Object>>() { | |
@Override | |
public void call(List<Object> taps) { | |
_showTapCount(taps.size()); |
This file contains 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
// note that it is important to subscribe to the exact same _rxBus instance that was used to post the events | |
_rxBus.toObserverable() | |
.subscribe(new Action1<Object>() { | |
@Override | |
public void call(Object event) { | |
if(event instanceof TapEvent) { | |
_showTapText(); | |
}else if(event instanceof SomeOtherEvent) { |
This file contains 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
@OnClick(R.id.btn_demo_rxbus_tap) | |
public void onTapButtonClicked() { | |
_rxBus.send(new TapEvent()); | |
} |
This file contains 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
// this is the middleman object | |
public class RxBus { | |
private final Subject<Object, Object> _bus = new SerializedSubject<>(PublishSubject.create()); | |
public void send(Object o) { | |
_bus.onNext(o); | |
} | |
public Observable<Object> toObserverable() { |
This file contains 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 below code is inside a TextWatcher | |
// which implements the onTextChanged method | |
// I've simplified it to only highlight the parts we're | |
// interested in | |
private long lastChange = 0; | |
@Override | |
public void onTextChanged(final CharSequence chars, |
This file contains 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 TestActivity extends Activity { | |
// ... | |
// all standard stuff | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
// ... | |
// all standard stuff |
This file contains 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
// Version 1 | |
public class IAmAThread extends Thread { | |
public IAmAThread() { | |
super("IAmAThread"); | |
} | |
@Override | |
public void run() { | |
// your code (sequence of instructions) |