rx-kotlin

How to add Body in Url in Volley request in Kotlin?

浪尽此生 提交于 2021-02-09 11:32:16
问题 Here is my Code that for Volley Request:- val searchRequest = object : JsonArrayRequest(Request.Method.GET,url, Response.Listener { response -> val result = response.toString() }, Response.ErrorListener { error -> Toast.makeText(activity, "Error!",Toast.LENGTH_LONG) .show() Log.d("ERROR",error.toString()) }) { override fun getBody(): ByteArray { // TODO add Body, Header section works ////////// return super.getBody() } override fun getBodyContentType(): String { return "application/json" }

Multiple retrofit2 requests using Flowable in Kotlin

左心房为你撑大大i 提交于 2021-01-28 10:47:26
问题 In order to improve my skills in kotlin, Rx, Retrofit2 I've decided to do a demo project. The demo project consist to display posts in a recycler view then display details of the post in a detail activity. I've encountered difficulties displaying data coming from different api call: the user name, the title, the body of the post and the number of comments of the post. My problem is that I would like to do multiple request and then have all the data needed in order to display them in the

Multiple retrofit2 requests using Flowable in Kotlin

孤街浪徒 提交于 2021-01-28 10:42:12
问题 In order to improve my skills in kotlin, Rx, Retrofit2 I've decided to do a demo project. The demo project consist to display posts in a recycler view then display details of the post in a detail activity. I've encountered difficulties displaying data coming from different api call: the user name, the title, the body of the post and the number of comments of the post. My problem is that I would like to do multiple request and then have all the data needed in order to display them in the

How to read JSON from Url using kotlin Android?

痴心易碎 提交于 2020-01-15 01:52:26
问题 Am using kotlin for developing the application.Now i want to get JSON data from server. In java am implemented Asyntask as well as Rxjava for read JSON from Url . Am also search in google but i cant get proper details for my requirement. How can i read JSON from Url using kotlin? 回答1: I guess you're trying to read the response from a server API, which you expect to be a string with JSON. To do so, you can use: val apiResponse = URL("yourUrl").readText() From the docs: Reads the entire content

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

RxJava 2 equivalent to isUnsubscribed

眉间皱痕 提交于 2019-12-19 09:09:34
问题 I've been working through the examples in the book Reactive Programming with RxJava, which is targeted at version 1 not 2. An introduction to infinite streams has the following example (and notes there are better ways to deal with the concurrency): Observable<BigInteger> naturalNumbers = Observable.create(subscriber -> { Runnabler = () -> { BigInteger i = ZERO; while (!subscriber.isUnsubscribed()) { subscriber.onNext(i); i = i.add(ONE); } }; new Thread(r).start(); }); ... Subscription

How to zip few observables in Kotlin language with RxAndroid

自古美人都是妖i 提交于 2019-12-10 02:28:46
问题 I have some problem. I'm a beginer in RxJava/RxKotlin/RxAndroid, and dont understand some features. For Example: import rus.pifpaf.client.data.catalog.models.Category import rus.pifpaf.client.data.main.MainRepository import rus.pifpaf.client.data.main.models.FrontDataModel import rus.pifpaf.client.data.product.models.Product import rx.Observable import rx.Single import rx.lang.kotlin.observable import java.util.* class MainInteractor { private var repository: MainRepository = MainRepository()

RxAndroid - retry observable on click

纵然是瞬间 提交于 2019-12-09 17:53:43
问题 I'm using rxAndroid and rxKotlin in my Android app to handle network requests asynchronously. Now I would like to retry a failed network request only after click on Snackbar button. My code now: val citiesService = ApiFactory.citiesService citiesService.cities() .subscribeOn(Schedulers.newThread()) // fetch List<String> .flatMap { Observable.from(it) } // convert to sequence of String .flatMap { city -> citiesService.coordinates(city) // fetch DoubleArray .map { City(city, it) } // convert to

RxJava: Combining hot and cold observable to wait for each other

只愿长相守 提交于 2019-12-08 03:39:57
问题 I have my observables defined like this val initLoading = Observable.fromCallable { println("${System.currentTimeMillis()}") } .subscribeOn(Schedulers.computation()) .delay(WAIT_TIME, TimeUnit.SECONDS) .map { "loading ${System.currentTimeMillis()}" } .observeOn(AndroidSchedulers.mainThread()) val click = RxView.clicks(button).map { "click ${System.currentTimeMillis()}" } initLoading.concatWith(click) .subscribeBy( onNext = { println("result $it") }, onError = { throw it } ) initialLoading

AndThen executes before completable finished

坚强是说给别人听的谎言 提交于 2019-12-04 04:55:10
问题 Let's take two methods written with Rx: Maybe<Foo> getFooFromLocal Single<Foo> getFooFromNetwork I want to write a chain when we check our local storage for Foo . If we don't have any Foo we should get it from the network then save it to the local storage and again get it from local storage and pass it to our subscriber. storage .getFooFromLocal() .switchIfEmpty(network.getFooFromNetwork().map { it[0] } .flatMapCompletable { storage.saveFoo(it) } .andThen(storage.getFooFromLocal()))