rx-android

Retrofit API call receives “HTTP FAILED: java.io.IOException: Canceled”

爷,独闯天下 提交于 2019-11-30 17:05:08
Can't figure out why is this happening. Neither one of rx callbacks (onCompleted(), onError(), onNext()) not gets triggered by my call. The only thing i receive is this okhttp output: D/OkHttp: --> GET https://api.privatbank.ua/p24api/exchange_rates?json=true&date=20.11.2016 http/1.1 D/OkHttp: --> END GET D/OkHttp: <-- HTTP FAILED: java.io.IOException: Canceled Retrofit module: @Module public class RestModule { @Provides @Singleton public HttpLoggingInterceptor providesHttpLogginInterceptor() { return new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY); } @Provides

Unable to create call adapter for io.reactivex.Observable

醉酒当歌 提交于 2019-11-30 11:42:42
问题 I'm going to send a simple get method to my server(it is Rails app) and get the result using RxJava and Retrofit. The thing that I did is: My interface: public interface ApiCall { String SERVICE_ENDPOINT = "https://198.50.214.15"; @GET("/api/post") io.reactivex.Observable<Post> getPost(); } My model is this: public class Post { @SerializedName("id") private String id; @SerializedName("body") private String body; @SerializedName("title") private String title; public String getId () { return id

How can I make this rxjava zip to run in parallel?

房东的猫 提交于 2019-11-30 06:47:16
问题 I have a sleep method for simulating a long running process. private void sleep() { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } Then I have a method returns an Observable containing a list of 2 strings that is given in the parameters. It calls the sleep before return the strings back. private Observable<List<String>> getStrings(final String str1, final String str2) { return Observable.fromCallable(new Callable<List<String>>() { @Override public List

How to stop and resume Observable.interval emiting ticks

微笑、不失礼 提交于 2019-11-30 06:23:10
问题 This will emit a tick every 5 seconds. Observable.interval(5, TimeUnit.SECONDS, Schedulers.io()) .subscribe(tick -> Log.d(TAG, "tick = "+tick)); To stop it you can use Schedulers.shutdown(); But then all the Schedulers stops and it is not possible to resume the ticking later. How can I stop and resume the emiting "gracefully"`? 回答1: Here's one possible solution: class TickHandler { private AtomicLong lastTick = new AtomicLong(0L); private Subscription subscription; void resume() { System.out

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

Retrofit API call receives “HTTP FAILED: java.io.IOException: Canceled”

*爱你&永不变心* 提交于 2019-11-30 00:21:16
问题 Can't figure out why is this happening. Neither one of rx callbacks (onCompleted(), onError(), onNext()) not gets triggered by my call. The only thing i receive is this okhttp output: D/OkHttp: --> GET https://api.privatbank.ua/p24api/exchange_rates?json=true&date=20.11.2016 http/1.1 D/OkHttp: --> END GET D/OkHttp: <-- HTTP FAILED: java.io.IOException: Canceled Retrofit module: @Module public class RestModule { @Provides @Singleton public HttpLoggingInterceptor providesHttpLogginInterceptor()

Periodic HTTP Requests Using RxJava and Retrofit

本小妞迷上赌 提交于 2019-11-29 22:21:09
Is it possible to use RxJava/RxAndroid and Retrofit to perform periodic http requests to update data every x seconds? Currently I am using an IntentService and Recursive Handler/Runnable that fires every x seconds. I'd like to know if I could remove all that and let RxJava handle the requests instead. final RestClient client = new RestClient(); final ApiService service = client.getApiService(); public interface ApiService { @GET("/athletes") public Observable<List<Athlete>> getAthletes(); } service.getAthletes() .retry(3) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread())

Rx Java Android : How to convert this callback block to Observer

感情迁移 提交于 2019-11-29 17:40:20
I'm trying to upload a file via Amazon's S3 Android SDK. I've used RX Java a bit but I'm not sure how to convert this method to a method that returns an Observable because I want to chain the result of this method to another Observable call. It confuses me I suppose because of the fact that this does not return right away and can't return until either OnError or OnState changes. How do I handle these situations in an RX way? public void uploadFile(TransferObserver transferObserver){ transferObserver.setTransferListener(new TransferListener() { @Override public void onStateChanged(int id,

How to resolve Duplicate files copied in APK META-INF/rxjava.properties

风格不统一 提交于 2019-11-29 09:06:50
I am using rxjava and rxvolley on my android aplication. When I try to run it I get this error Execution failed for task ':testapp:transformResourcesWithMergeJavaResForDebug'. > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties File1: C:\Users\Daniel\.gradle\caches\modules-2\files-2.1\io.reactivex\rxjava\1.1.0\748f0546d5c3c27f1aef07270ffea0c45f0c42a4\rxjava-1.1.0.jar File2: C:\Users\Daniel\.gradle\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava\2.0.3

AsyncTask replacement with RXJava help needed

笑着哭i 提交于 2019-11-29 08:13:15
I am new to Reactive so go easy on me, but I am trying to replace an async task that is currently run on text changes for an auto suggest function. Below is where I am at with my RX: rest.getMemberList(etSearch.getText().toString())//rest interface .subscribeOn(Schedulers.io()) .observeOn(RxAndroidSchedulers.mainThread()) .subscribe(new Action1<List<Member>>() { @Override public void call(List<Member> results) { ListView ResultsListView = (ListView) findViewById(R.id.list); MemberAdapter = new ResultRowAdapter(mContext, getLayoutInflater()); MemberAdapter.setMemberList(results);