rx-android

Retrofit 2 + RxAndroid: Handle Errors (4xx and some 200)

人走茶凉 提交于 2020-01-13 14:56:13
问题 I saw a lot of articles and questions about error handling using retrofit combined with RxAndroid, but i am not able to set my configuration right. What do I want to accomplish: when receiving a 4xx code: handle it on onError() when receiving a 2xx code: -> try to parse to expected response and deliver it onNext() -> If not possible try to convert the JSON answer to MyAPIError class (simple POJO with errorNum and message) and deliver it on onError. So either 2xx or 4xx http codes might end up

How to make RxErrorHandlingCallAdapterFactory?

帅比萌擦擦* 提交于 2020-01-12 05:30:10
问题 I found this. But in new ver compile 'com.squareup.retrofit2:adapter-rxjava:2.2.0' at CallAdapter it has two params CallAdapter<?,?> How to modify RxCallAdapterWrapper to implement if from CallAdapter<?,?> 回答1: Disclaimer: I'm the author of the blog post you referenced The original post was meant as a proof of concept and for RxJava 2 so it's easier for me to explain with that version too, but I'll try and cover more ground. I'm guessing you're using version 1, since you talk about adapter

How to transform a nested list of double values into a Java class using RxJava?

眉间皱痕 提交于 2020-01-11 12:23:14
问题 In my Android client I receive this JSON data from a backend: [ [ 1427378400000, 553 ], [ 1427382000000, 553 ] ] Here is the routine which actually loads the data. I am using RxAndroid and Retrofit here. private void getProductLevels() { Observable<List<List<Double>>> responseObservable = mProductService.readProductLevels(); AppObservable.bindFragment(this, responseObservable) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) // TODO: Transform List<List<Double>> into

how to use worker thread in RxAndroid

非 Y 不嫁゛ 提交于 2020-01-07 06:26:43
问题 I am trying to use RxAndroid as shown in the below posted code. firstly, I know that to use .delay() I have to have it work on a worker thread through "Schedulers.io" but Schedulers class does not provide or have ".io" thread.How to use it lib compile 'io.reactivex.rxjava2:rxjava:2.0.1' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' code : Observable observable1 = Observable.just("2"); Observable observable2 = Observable.just("7"); Observable observable = Observable.zip(observable1,

How to bind Radio Buttons using RxJava

拥有回忆 提交于 2020-01-06 20:01:48
问题 I'm following the code of the Qiitanium app (See the highlighted lines in link) and I have trouble figuring out how I can bind RadioButtons Say I have a RadioGroup with R.id.rgMyButtons as Id and it contains 3 RadioButtons "Dead", "Alive", "Body Missing" with Ids are R.id.rbDead, R.id.rbAlive, R.id.rbMissing I set the RadioGroup field as Rx<RadioGroup> radioGroup; I get the view set in onViewCreated as rdGroup = RxView.findById(this, R.id.rgMyButtons); rdGroup.get().setOnCheckedChangeListener

RxAndroid response of one call to make another request

别来无恙 提交于 2020-01-06 08:22:12
问题 I'm new to RxAndroid and trying to chain responses. I'm using this github API to retrieve data. Along with each issue there are comments link and events link associated with it which I want to fetch and update existing object with list of comments and events to form something like this. [ issue: { comments: [ { . . }, { . . } ] events : [ { . . }, { . . } ] ] ] I could retrieve initial response with following code GitHubService gitHubService = ServiceFactory.createServiceFrom(GitHubService

RxAndroid response of one call to make another request

拟墨画扇 提交于 2020-01-06 08:21:12
问题 I'm new to RxAndroid and trying to chain responses. I'm using this github API to retrieve data. Along with each issue there are comments link and events link associated with it which I want to fetch and update existing object with list of comments and events to form something like this. [ issue: { comments: [ { . . }, { . . } ] events : [ { . . }, { . . } ] ] ] I could retrieve initial response with following code GitHubService gitHubService = ServiceFactory.createServiceFrom(GitHubService

mapping custom data RxAndroid with Kotlin

百般思念 提交于 2020-01-06 05:08:11
问题 I am trying to convert examples from this article from Java to Kotlin. I get error from picture at Exmaple 5: And I noticed, that without map() function I don't get this error So, what the point of this error and how to write it right? 回答1: The return value of a lambda in Kotlin is always the last expression in the block. So in this case the result of .map { it.note = it.note.toUpperCase() } is not returning a meaningful value. What you should do instead is this .map { it.note = it.note

android rxjava2/retrofit2 chaining calls with pagination token

瘦欲@ 提交于 2020-01-05 04:54:30
问题 I'm using a REST API to query for a list of Person objects. Max limit is 100 people in response. I need to fetch all people, and the total amount is unknown. There is a field in the first response called "next", containing url for the next page. I need to chain these calls using RxJava/RxAndroid and Retrofit until the last response has an empty "next" field. Since the "next" field contains a pagination url, all subsequent calls will have different url from the first one. What is the most

How to make Observable that emit character after 1 second of time interval

旧巷老猫 提交于 2020-01-04 18:31:20
问题 I have just started with RxJava/android and for practice and getting started I want to make observable that emits character in string every 1 second, how can I do this? Here is what I have tried so far, its just emit string at once: Observable<String> myObservable = Observable.interval(5000L, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .just("Hello"); I want hello like this first emit H after 1 second emit E and so on 回答1: Split String "hello" into letters "h", "e", ...