rx-java2

RxJava: concatArrayEager not emitting result from repository for offline case when concatArray is

£可爱£侵袭症+ 提交于 2019-12-11 15:07:20
问题 I have an app with offline functionality that requests data from a repository for getting data from a local database and an api request. The api call updates the local database so that in case the app is offline data is stored in the db is still displayed. My ProjectRepository class has a function getAllProjectByUserId which returns an Observable which combines output from two sources (the database and api call) fun getAllProjectByUserId(userId: Int): Observable<Projects> { // concatArray

RxJava 2 Nested Network Requests

我与影子孤独终老i 提交于 2019-12-11 14:58:44
问题 in the app I am currently working on I use retrofit to create an Observable <ArrayList<Party>> . Party has a hostId field as well as a field of type User which is null at the point of creation by Retrofits GsonConverter. I now want to use hostId to make a second request getting the user from id and adding the User to the initial Party . I have been looking into flatmap but I haven't found an example in which the first observable's results are not only kept but also modified. Currently, to get

ConnectableObservable not emitting values

允我心安 提交于 2019-12-11 14:49:33
问题 I am trying to understand hotObservables and have written this example but it doesn't seem to emitting anything. ConnectableObservable<Long> cold = Observable.intervalRange(1, 20, 100, 100, TimeUnit.MICROSECONDS).publish(); cold.subscribe(i -> System.out.println("First: " + i)); cold.connect(); Moving the cold.connect() to just after creating the ConnectableObservable doesn't changes anything. 来源: https://stackoverflow.com/questions/46991778/connectableobservable-not-emitting-values

How do I pass a bodyparameter for Rx2AndroidNetworking for get requests?

强颜欢笑 提交于 2019-12-11 12:44:05
问题 I am working on retrieving some endpoints in a helper class with Rx2AndroidNetworking. However, there is no way I can pass "addBodyParameter" with get requests (only works for post and put requests". I was wondering if there's a way around it? My postman query looks like this (which does return proper results once i add the "my_session_token" in the body as shown below: However, I am not sure how that pans out with my code. My code for retrieving it is as follows: @Override public Single

Rxjava chain more than one request

梦想与她 提交于 2019-12-11 07:28:13
问题 I am new in concept of RxJava. I would like to chain some calls: Observable<RoomList> listRoomsCall = mRoomServiceApi.listRooms(); //This call will get me RoomIds Next step is to call for all RoomIds - request after request mMeetingServiceApi.listMeetings(roomID, startsAtString, endsAtString, free)) How should I chain first call with next calls? I thinkt that I should use flatMap and loop to call all requets but how to connect all responses on the end? listRoomsCall.flatMap(v -> { for

Caching network calls using RxJava for some duration

不羁岁月 提交于 2019-12-11 07:06:27
问题 I am making a network using Retorfit + RxJava2 and I want to cache the response for 30 seconds. Any calls made after 30 seconds interval should get the latest results from server. I tried doing this using Replay operator but it still makes a network call every time I call subscribe. I am not an expert in RxJava so maybe my understanding of using Replay for caching like that is wrong. public Observable<Name> getName() { return retrofitBuilder.getName() .subscribeOn(Schedulers.io()) .replay(30,

Request in Android always giving socket timeout exception

梦想与她 提交于 2019-12-11 06:35:02
问题 I'm trying to make two requests when user clicks on a button. However, the request might take a little while. When the user is on battery save mode and screens lock his device while the request is still being done, the request will not complete and will give a socket timeout exception. I made a sample project to try this out and you can find it here. I'm using retrofit and RxJava to make my requests like this: networkFactory.request() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers

How to use switchIfEmpty?

我只是一个虾纸丫 提交于 2019-12-11 06:26:11
问题 I need to fetch data from DB. If it's empty, get data from server and insert it into database. Here is my code, public Flowable<List<Data>> test() { return dataDao.allDatas() .switchIfEmpty(datas()) .doOnNext(datas -> userStoreDao.insert(datas)) ); } public Flowable<List<Data>> datas() { return Flowable.zip(userFavoriteDatas(), userOtherDatas(), (favoriteDatas, otherDatas) -> { favoriteDatas.addAll(otherDatas); return favoriteDatas; }); } public Flowable<List<Data>> userFavoriteDatas() {

Implement Room with RxJava and Retrofit

白昼怎懂夜的黑 提交于 2019-12-11 06:19:21
问题 I am trying to use Room with RxJava and Retrofit, Before You recommend use a component arch (In this opportunity is not possible, the project is in and 50% and Just need to continue with the arch clean). So the problem is this. I have a web service that returns a POJO . Something like this: { "success":"true", "message":"message", "data":{[ "id":"id", "name":"name", "lname":"lname", ]} } POJO is more complex but for the example is ok with this. I need to do that since my view make query to

Querying single database row using rxjava2

徘徊边缘 提交于 2019-12-11 05:51:56
问题 I am using rxjava2 for the first time on an Android project, and am doing SQL queries on a background thread. However I am having trouble figuring out the best way to do a simple SQL query, and being able to handle the case where the record may or may not exist. Here is the code I am using: public Observable<Record> createRecordObservable(int id) { Callable<Record> callback = new Callable<Record>() { @Override public Record call() throws Exception { // do the actual sql stuff, e.g. // select