rx-java

Filter list of objects in RxJava

孤者浪人 提交于 2019-12-22 03:50:27
问题 I am trying to filter the list on the basis of it's property. For example, Sensors class has a property isActive and I want to get all the objects with isActive as true but I am unable to do it. I tried different ways but I didn't find the solution. Can someone help me to do it? Here is my code: mCompositeDisposable.add( fcService.getStationList() .subscribeOn(Schedulers.io()) .flatMap( stations -> { return fcService.getSensorList(stations.get(0).getName().getOriginal()); }) .subscribe(this:

RxJava 2, what happen the resultSelector argument of flatmap?

耗尽温柔 提交于 2019-12-22 00:03:42
问题 In RxJava1 flatmap had a overloaded method that allowed you to retain source values and pass it down the stream. I've gained this knowledge from the following blog post https://medium.com/rxjava-tidbits/rxjava-tidbits-1-use-flatmap-and-retain-original-source-value-4ec6a2de52d4 However, moving to RxJava2, I cannot seem to find it. I checked the changes from Rx1 and Rx2 and it is not listed. I would like to know if it exists still but I am perhaps not looking in the right place. I am using a

RxJava and Retrofit - first steps with Rx

核能气质少年 提交于 2019-12-21 17:32:08
问题 With RxJava (without Retrolambda), I would like to do some API calls and complete my data with it. My incomplete object is a 'TvShow' with a list of object 'Season'. This 'Season' is empty and I need to complete it with episodes. Observable<TvShow> getDataTVShow(long idTvShow) //get TvShow with empty seasons (except season number) Observable<Season> getDataSeason(long idTvShow, int seasonNumber); //get one complete season with episodes So I want to: Get my 'TvShow' object (OK) Iterate over

NetworkOnMainThread RxJava + Retrofit + Lollipop+

我与影子孤独终老i 提交于 2019-12-21 12:17:08
问题 I'm getting reports of a NetworkOnMainThread exception on Lollipop+ when running an https api call using Retrofit and RxAndroid . I have isolated the code and created the following example that still fails. Here's the build.gradle : apply plugin: 'com.android.application' apply plugin: 'me.tatarka.retrolambda' android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.example.bug" minSdkVersion 9 targetSdkVersion 23 versionCode 1 versionName "1.0" }

RxJava2 filter List<Object>

て烟熏妆下的殇ゞ 提交于 2019-12-21 12:11:48
问题 I'm trying to filter a List with RxJava2 such that each item (object) in the list should pass a validation check and I get a resulting List with only items that pass that test. For instance if my Object had the following structure, class MyClassA { int value1; int value2; } I want to only get the list of items where the value2 is 10. I have an API call function that returns an Observable of List, i.e. Observable<List<MyClassA>> as follows, apiService.getListObservable() .subscribeOn

Should I unsubscribe when using rxbinding?

て烟熏妆下的殇ゞ 提交于 2019-12-21 09:09:10
问题 There is how I use RxBinding with Kotlin: override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) reset_password_text_view.clicks().subscribe { presenter.showConfirmSecretQuestionBeforeResetPassword() } password_edit_text.textChanges().skip(1).subscribe { presenter.onPasswordChanged(it.toString()) } password_edit_text.editorActionEvents().subscribe { presenter.done(password_edit_text.text.toString()) } } Observable.subscribe(action)

RxJava as event bus?

孤人 提交于 2019-12-21 07:49:14
问题 I'm start learning RxJava and I like it so far. I have a fragment that communicate with an activity on button click (to replace the current fragment with a new fragment). Google recommends interface for fragments to communicate up to the activity but it's too verbose, I tried to use broadcast receiver which works generally but it had drawbacks. Since I'm learning RxJava I wonder if it's a good option to communicate from fragments to activities (or fragment to fragment)?. If so, whats the best

Why RxJava with Retrofit on Android doOnError() does not work but Subscriber onError does

旧城冷巷雨未停 提交于 2019-12-21 06:51:19
问题 can someone explain me why code like this: networApi.getList() .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .doOnError(throwable -> { throwable.getMessage(); }) .doOnNext(list -> { coursesView.populateRecyclerView(list); courseList = (List<Course>) courses; }).subscribe(); If there is no internet goes into doOnError but throws it further so the app goes down, but code like this: networkApi.getList() .subscribeOn(Schedulers.newThread()) .observeOn

RxJava - Just vs From

人盡茶涼 提交于 2019-12-21 06:50:07
问题 I'm getting the same output when using Observable.just vs Observable.from in the following case: public void myfunc() { //swap out just for from here and i get the same results,why ? Observable.just(1,2,3).subscribe(new Subscriber<Integer>() { @Override public void onCompleted() { Log.d("","all done. oncompleted called"); } @Override public void onError(Throwable e) { } @Override public void onNext(Integer integer) { Log.d("","here is my integer:"+integer.intValue()); } }); } I thought just

How to parse a JSON reply when using retrofit when the reply is sometimes an object and sometimes an array?

Deadly 提交于 2019-12-21 06:09:12
问题 I am using Retrofit to get a JSON reply. Here are parts of my implementation - @GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); and the class Bills is - public static class Bills { @SerializedName("report") public ArrayList<BillItem> billItems; } The BillItem class is as follows - public static class BillItem { @SerializedName("id") Integer entryID; @SerializedName("employee_id") Integer employeeDBID; @SerializedName("type") String type;