GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: use a debounced Buffer · leodevleo/Android-RxJava@726a60f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main/java/com/morihacky/android/rxjava/rxbus
    • RxBusFrag2.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/java/com/morihacky/android/rxjava/rxbus/RxBusFrag2.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/rxbus/RxBusFrag2.java
+20-19Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
import com.morihacky.android.rxjava.app.R;
1515
import java.util.List;
1616
import java.util.concurrent.TimeUnit;
17+
import rx.Observable;
1718
import rx.Subscription;
1819
import rx.android.observables.AndroidObservable;
1920
import rx.android.schedulers.AndroidSchedulers;
2021
import rx.functions.Action1;
21-
import rx.functions.Func1;
2222

2323
import static com.morihacky.android.rxjava.rxbus.RxBusFrag1.TapEvent;
2424

@@ -51,27 +51,28 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
5151
public void onStart() {
5252
super.onStart();
5353

54-
_subscription1_tapListen = AndroidObservable.bindFragment(this, _rxBus.toObserverable())
55-
.subscribe(new Action1<Object>() {
54+
// .share = publish + refcount
55+
Observable<Object> tapEventEmitter = _rxBus.toObserverable().share();
56+
57+
_subscription1_tapListen = AndroidObservable.bindFragment(this, tapEventEmitter)
58+
.subscribe(new Action1<Object>() {
59+
@Override
60+
public void call(Object event) {
61+
if (event instanceof TapEvent) {
62+
_showTapText();
63+
}
64+
}
65+
});
66+
67+
Observable<Object> debouncedEventEmitter = tapEventEmitter.debounce(1, TimeUnit.SECONDS);
68+
tapEventEmitter.buffer(debouncedEventEmitter)
69+
.observeOn(AndroidSchedulers.mainThread())
70+
.subscribe(new Action1<List<Object>>() {
5671
@Override
57-
public void call(Object event) {
58-
if (event instanceof TapEvent) {
59-
_showTapText();
60-
}
72+
public void call(List<Object> taps) {
73+
_showTapCount(taps.size());
6174
}
6275
});
63-
64-
_rxBus.toObserverable().buffer(1, TimeUnit.SECONDS).filter(new Func1<List<Object>, Boolean>() {
65-
@Override
66-
public Boolean call(List<Object> objects) {
67-
return objects != null && objects.size() > 0;
68-
}
69-
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Object>>() {
70-
@Override
71-
public void call(List<Object> taps) {
72-
_showTapCount(taps.size());
73-
}
74-
});
7576
}
7677

7778
private void _showTapText() {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.