rx-java2

RxJava alternative of group by in sql

你说的曾经没有我的故事 提交于 2019-12-08 09:07:28
问题 I have a list of Student : Observable<Student> source = Observable.fromIterable(getStudentList()); I would like to group them by postal code, along with how many times they appear, but the problem is that I use java 7 how to do this? 回答1: Use groupBy , flatMap and count on the groups themselves: source.groupBy(s -> s.postalCode) .flatMapSingle(g -> g.count() .map(v -> g.getKey() + ": " + v)) ; Without lambdas it looks more ugly though: source.groupBy(new Function<Student, String>() {

RxJava2 how to update existing subscription when request parameter changes

不羁的心 提交于 2019-12-08 08:14:32
问题 I have an activity on which I make a network request everytime the user input changes. The api definition is as follows: interface Api { @GET("/accounts/check") fun checkUsername(@Query("username") username: String): Observable<UsernameResponse> } Then the services that manages it all: class ApiService { var api: Api init { api = retrofit.create(Api::class.java) } companion object { val baseUrl: String = "https://someapihost" var rxAdapter: RxJava2CallAdapterFactory =

Android room insert with Completable not working? methods annotated with @insert can return either void,long?

主宰稳场 提交于 2019-12-08 07:51:13
问题 The versions i'm using are implementation 'io.reactivex.rxjava2:rxjava:2.2.4' implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'com.jakewharton.rxbinding2:rxbinding:2.0.0' implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' implementation 'android.arch.persistence.room:runtime:2.1.0-alpha04' kapt 'android.arch.persistence.room:compiler:2.1.0-alpha04' implementation 'android.arch.persistence.room:rxjava2:2.1.0-alpha04' and the Dao is @Insert(onConflict

How to subscribe and unsubscribe or cancel an rxjava observable

非 Y 不嫁゛ 提交于 2019-12-08 06:49:48
问题 I am new in RxJava and trying to update my asyncTask works to RxJava. As a first try I have done the following codes: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); doSomeWork(); } private String funcCallServerGet() { //Some code to call a HttpClient Get method & return a response string //this is the method which previously i used to call inside

RxJava -2 Observables that accepts more Observables at any time?

牧云@^-^@ 提交于 2019-12-08 05:23:07
问题 I'm currently using rx-java 2 and have a use case where multiple Observables need to be consumed by single Camel Route subscriber. Using this solution as a reference, I have a partly working solution. RxJava - Merged Observable that accepts more Observables at any time? I'm planning to use a PublishProcessor<T> that will be subscribed to one camel reactive stream subscriber and then maintain a ConcurrentHashSet<Flowable<T>> where I can dynamically add new Observable. I'm currently stuck on

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

How to retry a consumed Observable?

喜你入骨 提交于 2019-12-08 00:07:02
问题 I am trying to re-execute a defined observable that failed. Using Retrofit2 and RxJava2 together i want to retry a specific request with its subscription and behavior when clicking a button. is that possible? service.excecuteLoginService(url, tokenModel, RetrofitManager.apiKey) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(....) 回答1: An option is to create Publisher, which emission is controlled by your button. final PublishSubject<Object>

How to subscribe and unsubscribe or cancel an rxjava observable

对着背影说爱祢 提交于 2019-12-07 18:05:27
I am new in RxJava and trying to update my asyncTask works to RxJava. As a first try I have done the following codes: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); doSomeWork(); } private String funcCallServerGet() { //Some code to call a HttpClient Get method & return a response string //this is the method which previously i used to call inside asynctask doInbackground method } private void doSomeWork() { getSingleObservable() .subscribeOn

RxAndroid Release Apk is not working for build 25.0.2

岁酱吖の 提交于 2019-12-07 17:22:14
问题 I have posted this on rxandroid issue page too but no response its been 4 days but no response , problem is in debug apk rxjava functionalities are working as expected , but in release apk , only functionalities related to rxjava or rxandroid are not working at all build.gradle(project) apply plugin: 'com.android.application' //or apply plugin: 'java' apply plugin: 'me.tatarka.retrolambda' apply plugin: 'com.jakewharton.hugo' apply plugin: 'android-apt' def AAVersion = '4.1.0' android {

RxJava: How to express doOnFirst()?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 15:48:27
问题 I am using RxJava and I have an Observable with multiple items inside. What I would like to do is run function A on the first item, function B on all of them and function C when the Observable is completed: -----1-----2-----3-----|--> | | | | run A | | | | | | | run B run B run B | | run C is there a clever way of expressing this with lambda functions? I have the following solution already, but it looks ugly and I suspect that there is a better way to do this: observable.subscribe( new