10
10
import android .widget .ArrayAdapter ;
11
11
import android .widget .ListView ;
12
12
import android .widget .TextView ;
13
- import butterknife .Bind ;
14
- import butterknife .ButterKnife ;
15
- import butterknife .OnClick ;
13
+
16
14
import com .morihacky .android .rxjava .R ;
17
15
import com .morihacky .android .rxjava .retrofit .Contributor ;
18
16
import com .morihacky .android .rxjava .retrofit .GithubApi ;
19
17
import com .morihacky .android .rxjava .retrofit .GithubService ;
18
+
20
19
import java .util .ArrayList ;
21
20
import java .util .HashMap ;
22
21
import java .util .List ;
23
22
import java .util .Map ;
24
23
import java .util .concurrent .TimeUnit ;
25
- import rx .Observable ;
26
- import rx .Subscriber ;
27
- import rx .android .schedulers .AndroidSchedulers ;
28
- import rx .schedulers .Schedulers ;
24
+
25
+ import butterknife .Bind ;
26
+ import butterknife .ButterKnife ;
27
+ import butterknife .OnClick ;
28
+ import io .reactivex .Observable ;
29
+ import io .reactivex .android .schedulers .AndroidSchedulers ;
30
+ import io .reactivex .observers .DisposableObserver ;
31
+ import io .reactivex .schedulers .Schedulers ;
29
32
import timber .log .Timber ;
30
33
31
34
public class PseudoCacheFragment
@@ -61,9 +64,9 @@ public void onConcatBtnClicked() {
61
64
Observable .concat (getSlowCachedDiskData (), getFreshNetworkData ())
62
65
.subscribeOn (Schedulers .io ()) // we want to add a list item at time of subscription
63
66
.observeOn (AndroidSchedulers .mainThread ())
64
- .subscribe (new Subscriber <Contributor >() {
67
+ .subscribe (new DisposableObserver <Contributor >() {
65
68
@ Override
66
- public void onCompleted () {
69
+ public void onComplete () {
67
70
Timber .d ("done loading all data" );
68
71
}
69
72
@@ -86,12 +89,16 @@ public void onConcatEagerBtnClicked() {
86
89
infoText .setText (R .string .msg_pseudoCache_demoInfo_concatEager );
87
90
wireupDemo ();
88
91
89
- Observable .concatEager (getSlowCachedDiskData (), getFreshNetworkData ())
92
+ List <Observable <Contributor >> observables = new ArrayList <>(2 );
93
+ observables .add (getSlowCachedDiskData ());
94
+ observables .add (getFreshNetworkData ());
95
+
96
+ Observable .concatEager (observables )
90
97
.subscribeOn (Schedulers .io ()) // we want to add a list item at time of subscription
91
98
.observeOn (AndroidSchedulers .mainThread ())
92
- .subscribe (new Subscriber <Contributor >() {
99
+ .subscribe (new DisposableObserver <Contributor >() {
93
100
@ Override
94
- public void onCompleted () {
101
+ public void onComplete () {
95
102
Timber .d ("done loading all data" );
96
103
}
97
104
@@ -118,9 +125,9 @@ public void onMergeBtnClicked() {
118
125
Observable .merge (getCachedDiskData (), getFreshNetworkData ())
119
126
.subscribeOn (Schedulers .io ()) // we want to add a list item at time of subscription
120
127
.observeOn (AndroidSchedulers .mainThread ())
121
- .subscribe (new Subscriber <Contributor >() {
128
+ .subscribe (new DisposableObserver <Contributor >() {
122
129
@ Override
123
- public void onCompleted () {
130
+ public void onComplete () {
124
131
Timber .d ("done loading all data" );
125
132
}
126
133
@@ -146,9 +153,9 @@ public void onMergeSlowBtnClicked() {
146
153
Observable .merge (getSlowCachedDiskData (), getFreshNetworkData ())
147
154
.subscribeOn (Schedulers .io ()) // we want to add a list item at time of subscription
148
155
.observeOn (AndroidSchedulers .mainThread ())
149
- .subscribe (new Subscriber <Contributor >() {
156
+ .subscribe (new DisposableObserver <Contributor >() {
150
157
@ Override
151
- public void onCompleted () {
158
+ public void onComplete () {
152
159
Timber .d ("done loading all data" );
153
160
}
154
161
@@ -177,9 +184,9 @@ public void onMergeOptimizedBtnClicked() {
177
184
getCachedDiskData ().takeUntil (network )))
178
185
.subscribeOn (Schedulers .io ()) // we want to add a list item at time of subscription
179
186
.observeOn (AndroidSchedulers .mainThread ())
180
- .subscribe (new Subscriber <Contributor >() {
187
+ .subscribe (new DisposableObserver <Contributor >() {
181
188
@ Override
182
- public void onCompleted () {
189
+ public void onComplete () {
183
190
Timber .d ("done loading all data" );
184
191
}
185
192
@@ -208,9 +215,9 @@ public void onMergeOptimizedWithSlowDiskBtnClicked() {
208
215
getSlowCachedDiskData ().takeUntil (network )))
209
216
.subscribeOn (Schedulers .io ()) // we want to add a list item at time of subscription
210
217
.observeOn (AndroidSchedulers .mainThread ())
211
- .subscribe (new Subscriber <Contributor >() {
218
+ .subscribe (new DisposableObserver <Contributor >() {
212
219
@ Override
213
- public void onCompleted () {
220
+ public void onComplete () {
214
221
Timber .d ("done loading all data" );
215
222
}
216
223
@@ -259,10 +266,10 @@ private Observable<Contributor> getCachedDiskData() {
259
266
list .add (c );
260
267
}
261
268
262
- return Observable .from (list )//
263
- .doOnSubscribe (() -> new Handler (Looper .getMainLooper ())//
269
+ return Observable .fromIterable (list )//
270
+ .doOnSubscribe ((data ) -> new Handler (Looper .getMainLooper ())//
264
271
.post (() -> adapterSubscriptionInfo .add ("(disk) cache subscribed" )))//
265
- .doOnCompleted (() -> new Handler (Looper .getMainLooper ())//
272
+ .doOnComplete (() -> new Handler (Looper .getMainLooper ())//
266
273
.post (() -> adapterSubscriptionInfo .add ("(disk) cache completed" )));
267
274
}
268
275
@@ -271,10 +278,10 @@ private Observable<Contributor> getFreshNetworkData() {
271
278
GithubApi githubService = GithubService .createGithubService (githubToken );
272
279
273
280
return githubService .contributors ("square" , "retrofit" )
274
- .flatMap (Observable ::from )
275
- .doOnSubscribe (() -> new Handler (Looper .getMainLooper ())//
281
+ .flatMap (Observable ::fromIterable )
282
+ .doOnSubscribe ((data ) -> new Handler (Looper .getMainLooper ())//
276
283
.post (() -> adapterSubscriptionInfo .add ("(network) subscribed" )))//
277
- .doOnCompleted (() -> new Handler (Looper .getMainLooper ())//
284
+ .doOnComplete (() -> new Handler (Looper .getMainLooper ())//
278
285
.post (() -> adapterSubscriptionInfo .add ("(network) completed" )));
279
286
}
280
287
0 commit comments