Author: Michael Zeng
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<MyStuff> myStuffRepository = Observable | |
.merge(savedJobPostingRepository.onErrorReturn(error -> null), | |
appliedJobPostingRepository.retry(1)) | |
.reduce(new MyStuff(), (accumulated, item) -> { | |
switch (item.getEntityType()) { | |
case SavedJobs: | |
accumulated.savedJobPostings = item; | |
break; | |
case AppliedJobs: | |
accumulated.appliedJobPostings = item; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface MyStuffEntity { | |
EntityType getEntityType(); | |
} | |
public class MyStuff { | |
MyStuffEntity savedJobPostings; | |
MyStuffEntity appliedJobPostings; | |
} | |
Observable<MyStuff> myStuffRepository = Observable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<String> powerfulTextViewChangedTextRepository = | |
textViewChangedTextRepository.debounce(200, TimeUnit.MILLISECONDS).distinctUntilChanged(); | |
Observable<List<Location>> powerfulLocationTypeAheadOnChangedTextRepository = powerfulTextViewChangedTextRepository | |
.switchMap(s -> Observable.just(s).map(text ->RestClientProvider.newLocationTypeAheadClient(text).query())); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<List<Location>> locationTypeAheadOnChangedTextRepository = textViewChangedTextRepository | |
.flatMap(s -> Observable.just(s).map(text -> RestClientProvider.newLocationTypeAheadClient(text).query())) | |
locationTypeAheadOnChangedTextRepository.subscribe(suggestions -> render(suggestions)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
textViewChangedTextRepository.observeOn(Schedulers.io()).subscribe(s -> System.out.println(s)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TextView textView = aTextView; | |
Observable<String> textViewChangedTextRepository = Observable.fromEmitter(emitter -> { | |
textView.addTextChangedListener(new TextWatcher() { | |
public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { | |
emitter.onNext(s.toString()); | |
} | |
public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<JobPosting> jobPostingRepository = Observable.just(jobId).observeOn(Schedulers.io()) | |
.map(jobId -> RestClientProvider.newJobPostingClient(jobId).fetch()); | |
jobPostingRepository.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(jobPosting -> render(jobPosting)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jobPostingRepository.subscribe(jobPosting -> render(jobPosting)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable<JobPosting> jobPostingRepository = | |
Observable.just(jobId).map(jobId -> RestClientProvider.newJobPostingClient(jobId).fetch()); |