1212import butterknife .InjectView ;
1313import com .morihacky .android .rxjava .MainActivity ;
1414import com .morihacky .android .rxjava .app .R ;
15+ import java .util .concurrent .TimeUnit ;
1516import rx .Subscription ;
1617import rx .android .observables .AndroidObservable ;
1718import rx .functions .Action1 ;
19+ import rx .schedulers .Schedulers ;
1820
1921import static com .morihacky .android .rxjava .rxbus .RxBusFrag1 .TapEvent ;
2022
2123public class RxBusFrag2
2224 extends Fragment {
2325
2426 private RxBus _rxBus ;
25- private Subscription _subscription ;
27+ private Subscription _subscription1_tapListen ;
2628
2729 @ InjectView (R .id .demo_rxbus_tap_txt ) TextView _tapEventTxtShow ;
2830
@@ -44,14 +46,19 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
4446 @ Override
4547 public void onStart () {
4648 super .onStart ();
47- AndroidObservable .bindFragment (this , _rxBus .toObserverable ()).subscribe (new Action1 <Object >() {
48- @ Override
49- public void call (Object event ) {
50- if (event instanceof TapEvent ) {
51- _showTapText ();
52- }
53- }
54- });
49+
50+ _subscription1_tapListen = AndroidObservable .bindFragment (this , _rxBus .toObserverable ())
51+ .subscribe (new Action1 <Object >() {
52+ @ Override
53+ public void call (Object event ) {
54+ if (event instanceof TapEvent ) {
55+ _showTapText ();
56+ }
57+ }
58+ });
59+
60+ _rxBus .toObserverable ().debounce (400 , TimeUnit .MILLISECONDS , Schedulers .io ()).subscribe ();
61+
5562 }
5663
5764 private void _showTapText () {
@@ -63,6 +70,6 @@ private void _showTapText() {
6370 @ Override
6471 public void onStop () {
6572 super .onStop ();
66- _subscription .unsubscribe ();
73+ _subscription1_tapListen .unsubscribe ();
6774 }
6875}
0 commit comments