rx-android

RxJava Pagination

六眼飞鱼酱① 提交于 2019-12-03 11:21:49
问题 I am fairly new to rxJava. in my api response, I get information about total number of pages and current page number like: "pages": 22, "page": 1, i am using Retrofit to do api calls in data layer, my api service is like: @GET("/story") Observable <StoryCollectionEntity> storyCollection( @Query("feed_ids") String feed_items, @Query("page") int page); then: public Observable<StoryCollectionEntity> storyCollection() { return mUserApi.storyCollection(items,page); } i did the subscription in

RxJava + Retrofit -> BaseObservable for API calls for centralized response handling

做~自己de王妃 提交于 2019-12-03 11:16:55
问题 I am new to RxJava so please forgive me if this sounds too newbie :-). As of now I have an abstract CallbackClass that implements the Retofit Callback. There I catch the Callback's "onResponse" and "onError" methods and handle various error types before finally forwarding to the custom implemented methods. I also use this centralized class to for request/response app logging and other stuff. For example: for specific error codes from my sever I receive a new Auth token in the response body,

Retrofit “IllegalStateException: Already executed”

南笙酒味 提交于 2019-12-03 09:41:59
I have a Retrofit network call that id like to run every 5 seconds. My current code: Handler h = new Handler(); int delay = 5000; //milliseconds h.postDelayed(new Runnable() { public void run() { call.enqueue(new Callback<ApiResponse>() { @Override public void onResponse(Response<ApiResponse> response) { Log.d("api", "response: " + response.body().getPosition().getLatitude().toString()); } @Override public void onFailure(Throwable t) { } }); h.postDelayed(this, delay); } }, delay); This runs once, but then throws the following: java.lang.IllegalStateException: Already executed. at retrofit2

Convert AsyncTask to RxAndroid

百般思念 提交于 2019-12-03 08:42:30
问题 I have the following method to post response to UI using otto and AsyncTask . private static void onGetLatestStoryCollectionSuccess(final StoryCollection storyCollection, final Bus bus) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { bus.post(new LatestStoryCollectionResponse(storyCollection)); return null; } }.execute(); } I need help to convert this AsyncTask to RxJava using RxAndroid library . 回答1: Don't use .create() but use .defer()

InterruptedIOException while using Retrofit2 with rx when retryOn

↘锁芯ラ 提交于 2019-12-03 07:24:19
I'm using retrofit 2 with rx-android I have quite complex retry logic, which partially works . I cut off irrelevant code to simplify it. Here it is: public class RetryWithDelay implements Func1<Observable<? extends Throwable>, Observable<?>>, Constants { @Override public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts.flatMap(new Func1<Throwable, Observable<?>>() { @Override public Observable<?> call(Throwable throwable) { int statusCode = 500; if (throwable instanceof HttpException) { HttpException httpException = (HttpException) throwable; statusCode =

How to handle Item clicks for a recycler view using RxJava

99封情书 提交于 2019-12-03 07:22:45
问题 I was interested to find out what is the best way to respond to a item click of a recycler view. Normally I would add a onclick() listener to the ViewHolder and pass back results to the activity/fragment through a interface. I thought about adding a Observable in the onBindViewHolder but i do not want to create a new Observable for every item binding. 回答1: You can use RxBinding and then create a subject inside of your adapter, then redirect all the events to that subject and just create a

Rxandroid What's the difference between SubscribeOn and ObserveOn

杀马特。学长 韩版系。学妹 提交于 2019-12-03 04:45:50
问题 I am just learning Rx-java and Rxandroid2 and I am just confused what is the major difference between in SubscribeOn and ObserveOn. 回答1: SubscribeOn specify the Scheduler on which an Observable will operate. ObserveOn specify the Scheduler on which an observer will observe this Observable. So basically SubscribeOn is mostly subscribed (executed) on a background thread ( you do not want to block the UI thread while waiting for the observable) and also in ObserveOn you want to observe the

RxJava + Retrofit -> BaseObservable for API calls for centralized response handling

て烟熏妆下的殇ゞ 提交于 2019-12-03 02:49:55
I am new to RxJava so please forgive me if this sounds too newbie :-). As of now I have an abstract CallbackClass that implements the Retofit Callback. There I catch the Callback's "onResponse" and "onError" methods and handle various error types before finally forwarding to the custom implemented methods. I also use this centralized class to for request/response app logging and other stuff. For example: for specific error codes from my sever I receive a new Auth token in the response body, refresh the token and then clone.enqueue the call. There are of course several other global behaviors to

Convert AsyncTask to RxAndroid

瘦欲@ 提交于 2019-12-02 22:29:43
I have the following method to post response to UI using otto and AsyncTask . private static void onGetLatestStoryCollectionSuccess(final StoryCollection storyCollection, final Bus bus) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { bus.post(new LatestStoryCollectionResponse(storyCollection)); return null; } }.execute(); } I need help to convert this AsyncTask to RxJava using RxAndroid library . Don't use .create() but use .defer() Observable<File> observable = Observable.defer(new Func0<Observable<File>>() { @Override public Observable<File>

How to handle Item clicks for a recycler view using RxJava

左心房为你撑大大i 提交于 2019-12-02 20:54:13
I was interested to find out what is the best way to respond to a item click of a recycler view. Normally I would add a onclick() listener to the ViewHolder and pass back results to the activity/fragment through a interface. I thought about adding a Observable in the onBindViewHolder but i do not want to create a new Observable for every item binding. You can use RxBinding and then create a subject inside of your adapter, then redirect all the events to that subject and just create a getter of the subject to act as an observable and finally just subscribe you on that observable. private