Skip to content

Commit 9f4f222

Browse files
author
Kaushik Gopal
committed
refactor: .create() -> .just() : create is an overkill
1 parent 605e493 commit 9f4f222

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

app/src/main/java/com/morihacky/android/rxjava/ConcurrencyWithSchedulersDemoFragment.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
import butterknife.ButterKnife;
1515
import butterknife.InjectView;
1616
import butterknife.OnClick;
17-
import com.morihacky.android.rxjava.R;
1817
import java.util.ArrayList;
1918
import java.util.List;
2019
import rx.Observable;
2120
import rx.Observer;
22-
import rx.Subscriber;
2321
import rx.Subscription;
2422
import rx.android.app.AppObservable;
2523
import rx.android.schedulers.AndroidSchedulers;
24+
import rx.functions.Func1;
2625
import rx.schedulers.Schedulers;
2726
import timber.log.Timber;
2827

@@ -72,23 +71,17 @@ public void startLongOperation() {
7271
}
7372

7473
private Observable<Boolean> _getObservable() {
75-
return Observable.create(new Observable.OnSubscribe<Boolean>() {
76-
74+
return Observable.just(true).map(new Func1<Boolean, Boolean>() {
7775
@Override
78-
public void call(Subscriber<? super Boolean> observer) {
79-
80-
_log("Within Observable");
81-
76+
public Boolean call(Boolean aBoolean) {
8277
_doSomeLongOperation_thatBlocksCurrentThread();
83-
observer.onNext(true);
84-
observer.onCompleted();
78+
return aBoolean;
8579
}
8680
});
8781
}
8882

8983
/**
90-
* Observer that handles the result List<Integer> from Observable
91-
* through the 3 important actions:
84+
* Observer that handles the result through the 3 important actions:
9285
*
9386
* 1. onCompleted
9487
* 2. onError
@@ -106,13 +99,13 @@ public void onCompleted() {
10699
@Override
107100
public void onError(Throwable e) {
108101
Timber.e(e, "Error in RxJava Demo concurrency");
109-
_log(String.format("Boo Error %s", e.getMessage()));
102+
_log(String.format("Boo! Error %s", e.getMessage()));
110103
_progress.setVisibility(View.INVISIBLE);
111104
}
112105

113106
@Override
114-
public void onNext(Boolean aBoolean) {
115-
_log(String.format("onNext with return value \"%b\"", aBoolean));
107+
public void onNext(Boolean bool) {
108+
_log(String.format("onNext with return value \"%b\"", bool));
116109
}
117110
};
118111
}

0 commit comments

Comments
 (0)