rx-java

Combine RxTextView Observable and Retrofit Observable

ⅰ亾dé卋堺 提交于 2019-12-21 05:06:07
问题 As an example to getting started with RxAndroid I'm trying to implement a searchbox which triggers a rest call when the users inserts something. So far I have two working parts. The first observing the EditTextView ... RxTextView.textChangeEvents(searchEditText) .debounce(400, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<TextViewTextChangeEvent>() { @Override public void onCompleted() { Timber.d("onCompleted"); } @Override public void onError

Robolectric + rxJava + retrofit Second call throws java.io.InterruptedIOException

巧了我就是萌 提交于 2019-12-21 05:04:16
问题 I am developing and android app. I am using retrofit (with OkClient) for api requests and Robolectric for testing. My api looks like this: @GET("/v1/book/{bookId}") Observable<Book> getBook(@Path("bookId") int bookId); Just for Robolectric I am forcing api calls to be synchronous. The restAdapter builder looks like this: RestAdapter.Builder builder = new RestAdapter.Builder().setEndpoint(environment.getServerEndpoint()) .setClient(new OkClient(client)) .setExecutors(new ImmediateExecutor(),

Observer.onError firing off inconsistently

一世执手 提交于 2019-12-21 03:58:27
问题 I am using Retrofit to access my API as follows: public interface UserService { ... @POST("/user/login") public Observable<User> register(@Body() User user); } Here is how I access my API: mUserService.register(user) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<User>() { @Override public void onCompleted() { .... } @Override public void onError(Throwable e) { .... } @Override public void onNext(User user) { .... } }); This works

Get the latest value of an Observable and emit it immeditely

試著忘記壹切 提交于 2019-12-21 03:29:45
问题 I'm trying to get the latest value of a given Observable and get it to emit immediately once it's called. Given the code below as an example: return Observable.just(myObservable.last()) .flatMap(myObservable1 -> { return myObservable1; }) .map(o -> o.x) // Here I want to end up with a T object instead of Observable<T> object This does not work because by doing this the flatMap will emit myObservable1 which in turn will have to emit to reach the map . I don't know if doing such thing is even

InterruptedIOException while using Retrofit2 with rx when retryOn

喜你入骨 提交于 2019-12-20 23:20:10
问题 I'm using retrofit 2 with rx-android I have quite complex retry logic, which partially works . I cut off irrelevant code to simplify it. Here it is: public class RetryWithDelay implements Func1<Observable<? extends Throwable>, Observable<?>>, Constants { @Override public Observable<?> call(Observable<? extends Throwable> attempts) { return attempts.flatMap(new Func1<Throwable, Observable<?>>() { @Override public Observable<?> call(Throwable throwable) { int statusCode = 500; if (throwable

How to use Observable.fromCallable() with a checked Exception?

99封情书 提交于 2019-12-20 19:36:52
问题 Observable.fromCallable() is great for converting a single function into an Observable. But how do you handle checked exceptions that might be thrown by the function? Most of the examples I've seen use lambdas and "just work". But how would you do this without lambdas? For example, see the quote below from this great article: Observable.fromCallable(() -> downloadFileFromNetwork()); It's a one-liner now! It deals with checked exceptions, no more weird Observable.just() and Observable.error()

@DELETE method is not supporting(Non-body HTTP method cannot contain @Body or @TypedOutput.)

喜你入骨 提交于 2019-12-20 17:33:10
问题 @DELETE("/job/deletejob") Observable<JobDeleteResponseModel> jobDelete( @Body JobDeleteRequestModel model); am getting this error: Non-body HTTP method cannot contain @Body or @TypedOutput can any one help me to come out from this?? 回答1: I've used this official workaround recently: @HTTP(method = "DELETE", path = "/job/deletejob", hasBody = true) Observable<JobDeleteResponseModel> jobDelete(@Body JobDeleteRequestModel model); 回答2: try this it's work @HTTP(method = "DELETE", path = "api/v3

Getting started with RxJava with sqlite

我们两清 提交于 2019-12-20 14:23:52
问题 I'm in the process of learning RxJava and have went thru several articles and videos. I totally felt awesome of what RxJava can offer, so I think currently getting the sense of what Reactive Programming is all about. This tutorial by Dan Lew helped me somewhat to understand the basics of using RxJava. But I found out that the more I thought I've fully understood RxJava, the more questions come popping out of my mind. Since I'm a guy who learns most when writing code, here's what I'm trying to

Getting started with RxJava with sqlite

一笑奈何 提交于 2019-12-20 14:23:04
问题 I'm in the process of learning RxJava and have went thru several articles and videos. I totally felt awesome of what RxJava can offer, so I think currently getting the sense of what Reactive Programming is all about. This tutorial by Dan Lew helped me somewhat to understand the basics of using RxJava. But I found out that the more I thought I've fully understood RxJava, the more questions come popping out of my mind. Since I'm a guy who learns most when writing code, here's what I'm trying to

Android RxJava joining lists

独自空忆成欢 提交于 2019-12-20 14:16:20
问题 Trying to understand all that RxJava stuff. I was doing following example: private Observable<List<String>> query1() { List<String> urls = new ArrayList<>(); urls.add("1"); urls.add("2"); urls.add("3"); urls.add("4"); return Observable.just(urls); } private Observable<List<String>> query2() { List<String> urls = new ArrayList<>(); urls.add("A"); urls.add("B"); urls.add("C"); urls.add("D"); return Observable.just(urls); } and then tried to join two lists: Observable.zip( query1(), query2(),