rx-java2

Observable.combineLatest type inference in kotlin

为君一笑 提交于 2019-11-30 08:20:58
I'm using RxJava2, Kotlin-1.1 along with RxBindings in my project. I have simple login screen with 'login' button disabled by default, I want to enable the button only when username and password edittext fields are not empty. LoginActivity.java Observable<Boolean> isFormEnabled = Observable.combineLatest(mUserNameObservable, mPasswordObservable, (userName, password) -> userName.length() > 0 && password.length() > 0) .distinctUntilChanged(); I'm unable to translate the above code from Java to Kotlin: LoginActivity.kt class LoginActivity : AppCompatActivity() { val disposable =

RX JAVA + Retrofit sdk generation using Swagger codegen

江枫思渺然 提交于 2019-11-30 04:37:23
问题 I want to generate sdk using swagger codegen which can give me generated sdk with Observable as callback like below : @POST("oauth/token") Observable < TokenResponse> getRepository(@Query("grant_type") String grantType); 回答1: You can generate a Java Retrofit API client with RxJava enabled using the following command as an example: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -l java -i http://petstore.swagger.io/v2/swagger.json \ -c /var/tmp/retrofit2rx/java

What is the difference between Observable, Completable and Single in RxJava

☆樱花仙子☆ 提交于 2019-11-29 18:51:06
Can anyone please explain the difference between Observable, Completable and Single in RxJava with clear examples? In which scenario we use one over the others? yosriz Observable is the generic ReactiveX building block, of event source that emits values over time. (and thus exists in every language ReactiveX extended to) in short Observable events are: onNext* (onCompleted | onError)? /(* zero or more ? - zero or 1) Single and Completable are new types introduced exclusively at RxJava that represent reduced types of Observable , that have more concise API. Single represent Observable that emit

When to call dispose and clear on CompositeDisposable

余生长醉 提交于 2019-11-29 16:14:43
问题 My question can be a duplicate of How to use CompositeDisposable of RxJava 2? But asking to clear one more doubt. According to the accepted answer // Using clear will clear all, but can accept new disposable disposables.clear(); // Using dispose will clear all and set isDisposed = true, so it will not accept any new disposable disposables.dispose(); In my case, I'm using fragments as my views (View layer in MVP) and in some scenarios, I add active fragment to backstack, which actually does

Observable.combineLatest type inference in kotlin

白昼怎懂夜的黑 提交于 2019-11-29 11:03:59
问题 I'm using RxJava2, Kotlin-1.1 along with RxBindings in my project. I have simple login screen with 'login' button disabled by default, I want to enable the button only when username and password edittext fields are not empty. LoginActivity.java Observable<Boolean> isFormEnabled = Observable.combineLatest(mUserNameObservable, mPasswordObservable, (userName, password) -> userName.length() > 0 && password.length() > 0) .distinctUntilChanged(); I'm unable to translate the above code from Java to

RxAndroid and Retrofit: Unable to create call adapter for io.reactivex.Observable<retrofit2.Response<okhttp3.ResponseBody>>

主宰稳场 提交于 2019-11-29 09:24:45
I am trying use rxJava, rxAndroid, Retrofit2, and OkHTTP3 to download a file from a URL endpoint. My code is unable to create the call adapter for an "Observable< retrofit2.Response< okhttp3.ResponseBody>>". These methods are new to me so I believe I'm missing an important concept here. Any direction or points is greatly appreciated. FATAL EXCEPTION: main Process: com.example.khe11e.rxdownloadfile, PID: 14130 java.lang.IllegalArgumentException: Unable to create call adapter for io.reactivex.Observable> for method RetrofitInterface.downloadFileByUrlRx at retrofit2.ServiceMethod$Builder

Synchronous or Asynchronous Rxjava inside the Worker (from WorkManager component) what's the right choice?

早过忘川 提交于 2019-11-29 02:18:16
问题 I'm new to the new architecture component WorkManager, I do my API calls via Retrofit and RxJava. My use case here is to get new posts from the Backend, then show notification, and update a widget. So the code inside doWork() method from the Worker class, may look like something like this. @NonNull @Override public Result doWork() { AppDependencies appDependencies = new AppDependencies((Application) getApplicationContext()); Repository repository = appDependencies.getRepository(); repository

How to chain two Completable in RxJava2

一曲冷凌霜 提交于 2019-11-29 00:58:05
I have two Completable. I would like to do following scenario: If first Completable gets to onComplete , continue with second Completable. The final results would be onComplete of second Completable. This is how I do it when I have Single getUserIdAlreadySavedInDevice() and Completable login() : @Override public Completable loginUserThatIsAlreadySavedInDevice(String password) { return getUserIdAlreadySavedInDevice() .flatMapCompletable(s -> login(password, s)) } You are looking for andThen operator. Returns a Completable that first runs this Completable and then the other completable.

RxJavaPlugins Error Didn't find class “com.google.devtools.build.android.desugar.runtime.ThrowableExtension”

旧街凉风 提交于 2019-11-28 18:15:36
After upgrading Android Studio 3.0 Beta 1 getting the following error. When I downgraded the error disappeared. Studio Build: Android Studio 3.0 Beta 1 Version of Gradle Plugin: 'com.android.tools.build:gradle:3.0.0-beta1' Version of Gradle:.0.0-beta1 Version of Java: 8 OS: MacOSX java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension; at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:364) at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:113) at android.os.Handler

RxJava 2.x: Should I use Flowable or Single/Completable?

[亡魂溺海] 提交于 2019-11-28 17:49:51
I'm developing an Android app using Clean Architecture and I'm migrating it to RxJava 2.x. I have to make some network requests to a soap service, so I defined the api interface in the domain module: public interface SiginterApi { Observable<User> login(String user, String password); ... Observable<List<Campaign>> getCampaigns(List<Long> campaignIds); } I've read that a network request should be made with " Flowable ", because of the backpressure management since it's a 'cold observable'. On the other hand, I know the result of the request will be success (with the response) or error, so I don