1212import butterknife .InjectView ;
1313import com .morihacky .android .rxjava .MainActivity ;
1414import com .morihacky .android .rxjava .app .R ;
15+ import java .util .List ;
1516import java .util .concurrent .TimeUnit ;
1617import rx .Subscription ;
1718import rx .android .observables .AndroidObservable ;
19+ import rx .android .schedulers .AndroidSchedulers ;
1820import rx .functions .Action1 ;
19- import rx .schedulers . Schedulers ;
21+ import rx .functions . Func1 ;
2022
2123import static com .morihacky .android .rxjava .rxbus .RxBusFrag1 .TapEvent ;
2224
@@ -25,8 +27,10 @@ public class RxBusFrag2
2527
2628 private RxBus _rxBus ;
2729 private Subscription _subscription1_tapListen ;
30+ private Subscription _subscription2_tapCollector ;
2831
2932 @ InjectView (R .id .demo_rxbus_tap_txt ) TextView _tapEventTxtShow ;
33+ @ InjectView (R .id .demo_rxbus_tap_count ) TextView _tapEventCountShow ;
3034
3135 @ Override
3236 public View onCreateView (LayoutInflater inflater ,
@@ -57,8 +61,17 @@ public void call(Object event) {
5761 }
5862 });
5963
60- _rxBus .toObserverable ().debounce (400 , TimeUnit .MILLISECONDS , Schedulers .io ()).subscribe ();
61-
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+ });
6275 }
6376
6477 private void _showTapText () {
@@ -67,6 +80,18 @@ private void _showTapText() {
6780 ViewCompat .animate (_tapEventTxtShow ).alphaBy (-1f ).setDuration (400 );
6881 }
6982
83+ private void _showTapCount (int size ) {
84+ _tapEventCountShow .setText (String .valueOf (size ));
85+ _tapEventCountShow .setVisibility (View .VISIBLE );
86+ _tapEventCountShow .setScaleX (1f );
87+ _tapEventCountShow .setScaleY (1f );
88+ ViewCompat .animate (_tapEventCountShow )
89+ .scaleXBy (-1f )
90+ .scaleYBy (-1f )
91+ .setDuration (400 )
92+ .setStartDelay (100 );
93+ }
94+
7095 @ Override
7196 public void onStop () {
7297 super .onStop ();
0 commit comments