io.reactivex.Observer Java Examples
The following examples show how to use
io.reactivex.Observer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggerTest.java From java-unified-sdk with Apache License 2.0 | 6 votes |
public void testFindObject() { AVQuery query = new AVQuery("Student"); query.limit(4); query.orderByDescending(AVObject.KEY_CREATED_AT); query.findInBackground().subscribe(new Observer<List<AVObject>>() { public void onSubscribe(Disposable disposable) { } public void onNext(List<AVObject> o) { for(AVObject obj: o) { System.out.println("Query of Student is: " + obj.toString()); } } public void onError(Throwable throwable) { fail(); } public void onComplete() { } }); }
Example #2
Source File: UpWalletTickerService.java From Upchain-wallet with GNU Affero General Public License v3.0 | 6 votes |
@Override public Observer<? super Response<T>> apply(Observer<? super T> observer) throws Exception { return new DisposableObserver<Response<T>>() { @Override public void onNext(Response<T> response) { observer.onNext(response.body()); observer.onComplete(); } @Override public void onError(Throwable e) { observer.onError(e); } @Override public void onComplete() { observer.onComplete(); } }; }
Example #3
Source File: SocialFragment.java From SmallGdufe-Android with GNU General Public License v3.0 | 6 votes |
private void goFindMoreData() { mPageNo ++; socialApiFactory.getImFeedList(mPageNo,PAGE_NUM, new Observer<List<Feed>>() { @Override public void onSubscribe(Disposable disposable) { } @Override public void onNext(List<Feed> feeds) { mFeeds.addAll(feeds); mFeedAdapter.setData(mFeeds); mRefreshLayout.endLoadingMore(); } @Override public void onError(Throwable throwable) { } @Override public void onComplete() { } }); }
Example #4
Source File: DBPresenter.java From AndroidBase with Apache License 2.0 | 6 votes |
public void query() { getModel().queryForAllSync().subscribe(new Observer<List<City>>() { @Override public void onSubscribe(Disposable d) { getRxManager().add(d); } @Override public void onNext(List<City> data) { queryFinish(data); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); }
Example #5
Source File: ContentGankData.java From GankLock with GNU General Public License v3.0 | 6 votes |
public void getDailyGankDataFromServer(String date, Observer observer) { service.getGankData(date) .map(new Function<GankContent, GankContent.Result>() { @Override public GankContent.Result apply(GankContent gankContent) throws Exception { return gankContent.results; } }).map(new Function<GankContent.Result, List<Gank>>() { @Override public List<Gank> apply(GankContent.Result result) throws Exception { return addAllResult(result); } }).subscribeOn(Schedulers.io()) //在io线程进行数据的读取 放在任何地方都可以 .observeOn(AndroidSchedulers.mainThread()) //在主线程处理数据 指定的是它之后的操作的线程,因此如果需要多次切换线程,可指定多次 .subscribe(observer); /*service.getGankData(date).flatMap(new Func1<GankContent, Observable<Gank>>() { @Override public Observable<Gank> call(GankContent gankContent) { return Observable.from(gankContent.results); } }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()).subscribe(subscriber);*/ }
Example #6
Source File: MaybeConsumers.java From science-journal with Apache License 2.0 | 6 votes |
/** * Allows a function that takes a MaybeConsumer to pipe a single success value to the given * Observer (which may also be accepting values from other places) * * @return a {@link MaybeConsumer<T>} that pipes {@link MaybeConsumer#success(Object)} to {@link * Observer#onNext(Object)}, and {@link MaybeConsumer#fail(Exception)} to {@link * Observer#onError(Throwable)} */ public static <T> MaybeConsumer<T> fromObserver(Observer<T> o) { return new MaybeConsumer<T>() { @Override public void success(T value) { // if value is null, just report empty if (value != null) { o.onNext(value); } o.onComplete(); } @Override public void fail(Exception e) { o.onError(e); } }; }
Example #7
Source File: AVQueryTest.java From java-unified-sdk with Apache License 2.0 | 6 votes |
public void testFirstQuery() throws Exception { AVQuery query = new AVQuery("Student"); query.orderByDescending(AVObject.KEY_CREATED_AT); query.getFirstInBackground().subscribe(new Observer<AVObject>() { public void onSubscribe(Disposable disposable) { } public void onNext(AVObject o) { System.out.println(o.toString()); testSucceed = true; latch.countDown(); } public void onError(Throwable throwable) { latch.countDown(); } public void onComplete() { System.out.println("completed."); latch.countDown(); } }); latch.await(); assertTrue(testSucceed); }
Example #8
Source File: AVCloudTest.java From java-unified-sdk with Apache License 2.0 | 6 votes |
public void testCloudFunction() { String name = "hallo"; Map<String, Object> param = new HashMap<String, Object>(); Observable<JSONObject> res = AVCloud.callFunctionInBackground(name, param); res.subscribe(new Observer<JSONObject>() { @Override public void onSubscribe(Disposable disposable) { } @Override public void onNext(JSONObject jsonObject) { System.out.println("结果 = " + jsonObject); } @Override public void onError(Throwable throwable) { System.out.println("error occurred! " + throwable); } @Override public void onComplete() { } }); }
Example #9
Source File: SearchResultPresenter.java From playa with MIT License | 5 votes |
@Override public void search(final int page, String keyword) { Observable<BaseResponse<ArticleListResponse>> observable = dataManager.searchArticles(page, keyword); observable.observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .map(new Function<BaseResponse<ArticleListResponse>, List<Article>>() { @Override public List<Article> apply(@NonNull BaseResponse<ArticleListResponse> response) throws Exception { return response.getData().getDatas(); } }).subscribeWith(new Observer<List<Article>>() { @Override public void onSubscribe(@NonNull Disposable d) { disposable = d; } @Override public void onNext(@NonNull List<Article> articles) { getView().showSearchResult(page, articles); } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); }
Example #10
Source File: SocialApiFactory.java From SmallGdufe-Android with GNU General Public License v3.0 | 5 votes |
public void getImFeedList(int pageNo,int pageNum, Observer< List<Feed> > sub ) { ApiUtils.getApi(AppConfig.idsPwd).create(SocialApi.class).getImFeedList(pageNo, pageNum ) .map(new HttpResultFunc<List<Feed>>()) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(sub); }
Example #11
Source File: ViewClickObservable.java From Tangram-Android with MIT License | 5 votes |
@Override protected void subscribeActual(Observer<? super Object> observer) { if (!checkMainThread(observer)) { return; } Listener listener = new Listener(view, observer); observer.onSubscribe(listener); view.setOnClickListener(listener); }
Example #12
Source File: NavigationPresenter.java From playa with MIT License | 5 votes |
@Override public void getNavCategories() { Observable<BaseResponse<List<NavCategory>>> observable = dataManager.getNavCategories(); observable.observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .map(new Function<BaseResponse<List<NavCategory>>, List<NavCategory>>() { @Override public List<NavCategory> apply(@NonNull BaseResponse<List<NavCategory>> response) throws Exception { return response.getData(); } }).subscribeWith(new Observer<List<NavCategory>>() { @Override public void onSubscribe(@NonNull Disposable d) { disposable = d; } @Override public void onNext(@NonNull List<NavCategory> categories) { getView().showNavCategories(categories); } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); }
Example #13
Source File: MapExampleActivity.java From RxJava2-Android-Samples with Apache License 2.0 | 5 votes |
private Observer<List<User>> getObserver() { return new Observer<List<User>>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, " onSubscribe : " + d.isDisposed()); } @Override public void onNext(List<User> userList) { textView.append(" onNext"); textView.append(AppConstant.LINE_SEPARATOR); for (User user : userList) { textView.append(" firstname : " + user.firstname); textView.append(AppConstant.LINE_SEPARATOR); } Log.d(TAG, " onNext : " + userList.size()); } @Override public void onError(Throwable e) { textView.append(" onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onError : " + e.getMessage()); } @Override public void onComplete() { textView.append(" onComplete"); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onComplete"); } }; }
Example #14
Source File: PageLoaderNet.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
@Override public void updateChapter() { mPageView.getActivity().toast("目录更新中"); WebBookModel.getInstance().getChapterList(book) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<List<BookChapterBean>>() { @Override public void onSubscribe(Disposable d) { compositeDisposable.add(d); } @Override public void onNext(List<BookChapterBean> chapterBeanList) { isChapterListPrepare = true; if (chapterBeanList.size() > callback.getChapterList().size()) { mPageView.getActivity().toast("更新完成,有新章节"); callback.onCategoryFinish(chapterBeanList); } else { mPageView.getActivity().toast("更新完成,无新章节"); } // 加载并显示当前章节 skipToChapter(book.getDurChapter(), book.getDurChapterPage()); } @Override public void onError(Throwable e) { durDhapterError(e.getMessage()); } @Override public void onComplete() { } }); }
Example #15
Source File: ObserverUtil.java From Learning-Resources with MIT License | 5 votes |
/** * @return Observer with which observable will subscribe */ public static <T> Observer<T> getObserver(final CompositeDisposable compositeDisposable, final WebserviceBuilder.ApiNames apiNames, final ListCallback callback) { return new Observer<T>() { @Override public void onSubscribe(Disposable d) { if (compositeDisposable != null) compositeDisposable.add(d); } @Override public void onNext(T value) { if (callback != null) callback.onListNext(value, apiNames); } @Override public void onError(Throwable e) { if (callback != null) callback.onFailure(e, apiNames); } @Override public void onComplete() { if (callback != null) callback.onListComplete(apiNames); } }; }
Example #16
Source File: AVFile.java From java-unified-sdk with Apache License 2.0 | 5 votes |
/** * save to cloud backend. * @param keepFileName whether keep file name in url or not. * @param progressCallback progress callback. */ public synchronized void saveInBackground(boolean keepFileName, final ProgressCallback progressCallback) { saveWithProgressCallback(keepFileName, progressCallback).subscribe(new Observer<AVFile>() { @Override public void onSubscribe(Disposable disposable) { } @Override public void onNext(AVFile avFile) { if (null != progressCallback) { progressCallback.internalDone(100, null); } } @Override public void onError(Throwable throwable) { if (null != progressCallback) { progressCallback.internalDone(90, new AVException(throwable)); } } @Override public void onComplete() { } }); }
Example #17
Source File: AVUser.java From java-unified-sdk with Apache License 2.0 | 5 votes |
public void getFollowersAndFolloweesInBackground(final FollowersAndFolloweesCallback callback) { if (null == callback) { return; } if (!checkUserAuthentication(callback)) { return; } PaasClient.getStorageClient().getFollowersAndFollowees(getObjectId()).subscribe(new Observer<JSONObject>() { @Override public void onSubscribe(Disposable disposable) { } @Override public void onNext(JSONObject jsonObject) { if (null == jsonObject) { callback.done(null, null); } else { Map<String, List<AVUser>> result = parseFollowerAndFollowee(jsonObject); callback.done(result, null); } } @Override public void onError(Throwable throwable) { callback.done(null, new AVException(throwable)); } @Override public void onComplete() { } }); }
Example #18
Source File: CardApiFactory.java From SmallGdufe-Android with GNU General Public License v3.0 | 5 votes |
public void getCurrentCash(Observer<CardBasic> sub) { ApiUtils.getApi(AppConfig.idsPwd).create(CardApi.class).getCurrentCash() .map(new HttpResultFunc<CardBasic>()) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(sub); }
Example #19
Source File: EngineDemoActivity.java From java-unified-sdk with Apache License 2.0 | 5 votes |
public void testErrorCode() throws AVException { AVCloud.callFunctionInBackground("errorCode", null).subscribe(new Observer<Object>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(Object o) { } @Override public void onError(Throwable e) { if (e instanceof AVException) { AVException ave = (AVException) e; if (ave.getCode() == 211) { log("云引擎返回的 Error, code:" + ave.getCode() + " message:" + ave.getMessage()); return; } } } @Override public void onComplete() { } }); }
Example #20
Source File: QueryObserverTest.java From ObjectBoxRxJava with Apache License 2.0 | 5 votes |
@Test public void testObservable() { Observable observable = RxQuery.observable(mockQuery.getQuery()); observable.subscribe((Observer) this); assertLatchCountedDown(latch, 2); assertEquals(1, receivedChanges.size()); assertEquals(0, receivedChanges.get(0).size()); assertNull(error); latch = new CountDownLatch(1); receivedChanges.clear(); publisher.setQueryResult(listResult); publisher.publish(); assertLatchCountedDown(latch, 5); assertEquals(1, receivedChanges.size()); assertEquals(2, receivedChanges.get(0).size()); assertEquals(0, completedCount.get()); //Unsubscribe? // receivedChanges.clear(); // latch = new CountDownLatch(1); // assertLatchCountedDown(latch, 5); // // assertEquals(1, receivedChanges.size()); // assertEquals(3, receivedChanges.get(0).size()); }
Example #21
Source File: TestEmployeeRxJavaService.java From Spring-5.0-Cookbook with MIT License | 5 votes |
@Test public void testEmployeeData(){ Observer<Employee> mySubscription = new Observer<Employee>() { @Override public void onComplete() { System.out.println("subscription completed"); } @Override public void onError(Throwable ex) { System.out.println("problems encountered" + ex.getMessage()); } @Override public void onNext(Employee emp) { System.out.format("Employee: %s \n", emp.getEmpId()); } @Override public void onSubscribe(Disposable arg0) { System.out.println("subscription started"); } }; employeeRxJavaServiceImpl.getEmployeesRx().subscribe(mySubscription); }
Example #22
Source File: RxJavaCustomObserverDemo.java From Spring-5.0-Projects with MIT License | 5 votes |
public static void main(String[] args) { Observable<String> months = Observable.just("January", "February", "March", "April", "May","June","July","August"); Observer<String> customObserver = new Observer<String>() { @Override public void onSubscribe(Disposable d) { System.out.println("Subscription initiated ..."); } @Override public void onNext(String value) { System.out.println("The value " + value +" is received from Observable"); } @Override public void onError(Throwable e) { e.printStackTrace(); } @Override public void onComplete() { System.out.println("Receive all the Data !"); } }; months.filter(month -> month.endsWith("y")) .subscribe(customObserver); }
Example #23
Source File: AVObjectComposeTest.java From java-unified-sdk with Apache License 2.0 | 5 votes |
public void testGeoPointAttr() throws Exception { AVObject course = new AVObject("Course"); course.put("name", "Math"); course.put("location", new AVGeoPoint(45.9, 76.3)); course.saveInBackground().subscribe(new Observer<AVObject>() { @Override public void onSubscribe(Disposable disposable) { } @Override public void onNext(AVObject avObject) { avObject.delete(); testSucceed = true; latch.countDown(); } @Override public void onError(Throwable throwable) { latch.countDown(); } @Override public void onComplete() { } }); latch.await(); assertTrue(testSucceed); }
Example #24
Source File: ListPresenter.java From Pixiv-Shaft with MIT License | 5 votes |
@Override public Observer<T> processFirst() { return new NullCtrl<T>() { @Override public void success(T listUser) { nextUrl = listUser.getNextUrl(); view.loadFirst(listUser); } }; }
Example #25
Source File: AVObjectTest.java From java-unified-sdk with Apache License 2.0 | 5 votes |
public void testBatchSaveOperation() throws Exception { AVObject object = new AVObject("Student"); object.put("name", "Automatic Tester"); object.put("age", 19); object.add("course", "Art"); object.removeAll("course", Arrays.asList("Math")); object.setFetchWhenSave(true); object.saveInBackground().subscribe(new Observer<AVObject>() { public void onSubscribe(Disposable disposable) { } public void onNext(AVObject avObject) { testSucceed = true; latch.countDown(); } public void onError(Throwable throwable) { latch.countDown(); } public void onComplete() { } }); latch.await(); assertTrue(testSucceed); }
Example #26
Source File: UserApi.java From AppServiceRestFul with GNU General Public License v3.0 | 5 votes |
public void userinfo(String phone, Observer<UserBean> subscriber) { Observable observable = userService.userinfo(phone) .map(new HttpResultFunc<UserBean>()); toSubscribe(observable, subscriber); }
Example #27
Source File: CellClickObservable.java From Tangram-Android with MIT License | 5 votes |
@Override protected void subscribeActual(Observer<? super ClickExposureCellOp> observer) { if (!Preconditions.checkMainThread(observer)) { return; } if (mListener == null) { mListener = new RxClickListener(mRxClickExposureEvent, observer); } else { mListener.setRxClickExposureEvent(mRxClickExposureEvent); mListener.setObserver(observer); } observer.onSubscribe(mListener); mRxClickExposureEvent.getArg1().setOnClickListener(mListener); }
Example #28
Source File: ExampleUnitTest.java From RxAndroid-Sample with Apache License 2.0 | 5 votes |
@Test public void testIntervalObservable() throws InterruptedException { Observable.interval(1, TimeUnit.SECONDS) .subscribe(new Observer<Long>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(Long value) { System.out.println("onNext: " + value); } @Override public void onError(Throwable e) { System.out.println("onError: " + e.getMessage()); } @Override public void onComplete() { } }); Thread.sleep(10000); }
Example #29
Source File: ImportBookPresenter.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void importBooks(List<File> books) { Observable.fromIterable(books) .flatMap(file -> ImportBookModel.getInstance().importBook(file)) .compose(RxUtils::toSimpleSingle) .subscribe(new Observer<LocBookShelfBean>() { @Override public void onSubscribe(Disposable d) { compositeDisposable.add(d); } @Override public void onNext(LocBookShelfBean value) { if (value.getNew()) { RxBus.get().post(RxBusTag.HAD_ADD_BOOK, value.getBookShelfBean()); } } @Override public void onError(Throwable e) { e.printStackTrace(); mView.addError(e.getMessage()); } @Override public void onComplete() { mView.addSuccess(); } }); }
Example #30
Source File: ExampleUnitTest.java From RxAndroid-Sample with Apache License 2.0 | 5 votes |
@Test public void testSkipObservable() throws InterruptedException { Observable.just("A", "B", "C", "D", "E", "F", "G", "H", "I", "J") .skip(4) .subscribe(new Observer<String>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(String s) { System.out.println("onNext: " + s); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } }); }