1717
1818import  android .content .Context ;
1919import  android .content .Intent ;
20+ import  android .content .res .ColorStateList ;
21+ import  android .graphics .Color ;
2022import  android .os .Bundle ;
2123import  android .view .Window ;
2224import  android .widget .TextView ;
3032import  com .fernandocejas .android10 .rx .sample .data .StringGenerator ;
3133import  com .fernandocejas .android10 .rx .sample .executor .JobExecutor ;
3234import  com .fernandocejas .arrow .strings .Strings ;
35+ import  java .util .concurrent .TimeUnit ;
3336import  rx .Subscription ;
3437import  rx .android .schedulers .AndroidSchedulers ;
3538import  rx .schedulers .Schedulers ;
@@ -115,7 +118,15 @@ private void toggleProgressBar(boolean visible) {
115118 .toList ()
116119 .observeOn (AndroidSchedulers .mainThread ())
117120 .subscribeOn (Schedulers .computation ())
118-  .subscribe (new  BackpressureSubscriber <>(this , getString (R .string .btn_text_backpressure_tolist ), 1000 ));
121+  .subscribe (new  BackpressureSubscriber <>(this , getString (R .string .btn_text_backpressure_toList ), 1000 ));
122+  }
123+ 
124+  @ OnClick (R .id .btn_backpressureThrottleLast ) void  onBackpressureThrottleLast () {
125+  dataManager .milliseconds (10000 )
126+  .throttleLast (10 , TimeUnit .MILLISECONDS )
127+  .observeOn (AndroidSchedulers .mainThread ())
128+  .subscribeOn (Schedulers .computation ())
129+  .subscribe (new  BackpressureSubscriber <>(this , getString (R .string .btn_text_backpressure_throttleLast ), 10000 ));
119130 }
120131
121132 @ Override 
@@ -133,21 +144,25 @@ public void onOperationStart(String name, long itemsRequested) {
133144 @ Override 
134145 public  void  onOperationResult (long  itemsEmitted , OperationResult  operation ) {
135146 tv_itemsEmitted .setText (String .valueOf (itemsEmitted ));
136-  String  resultMessage  = Strings .EMPTY ;
137147 switch  (operation .result ()) {
138148 case  SUCCESS :
139-  resultMessage  = getString (R .string .string_success );
149+  tv_result .setText (getString (R .string .string_success ));
150+  tv_result .setTextColor (ColorStateList .valueOf (Color .BLUE ));
140151 break ;
141152 case  FAILURE :
153+  String  failureMessage ;
142154 if  (operation .throwable ().isPresent ()) {
143-  resultMessage  = String .format (getString (R .string .string_failure ),
155+  failureMessage  = String .format (getString (R .string .string_failure ),
144156 operation .throwable ().get ().toString ());
145157 } else  {
146-  resultMessage  = getString (R .string .string_failure );
158+  failureMessage  = getString (R .string .string_failure );
147159 }
160+  tv_result .setText (failureMessage );
161+  tv_result .setTextColor (ColorStateList .valueOf (Color .RED ));
148162 break ;
163+  default :
164+  tv_result .setText (Strings .EMPTY );
149165 }
150-  tv_result .setText (resultMessage );
151166 toggleProgressBar (false );
152167 }
153168}
0 commit comments