Skip to content

Commit

Permalink
Add Single and Completable for RxJava1
Browse files Browse the repository at this point in the history
  • Loading branch information
amitshekhariitbhu committed Dec 19, 2017
1 parent 2274253 commit a70fdf0
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

import java.util.List;

import rx.Completable;
import rx.Observable;
import rx.Single;

/**
* Created by amitshekhar on 10/06/16.
Expand Down Expand Up @@ -66,6 +68,14 @@ public Observable<JSONObject> getJSONObjectObservable() {
}
}

public Single<JSONObject> getJSONObjectSingle() {
return getJSONObjectObservable().toSingle();
}

public Completable getJSONObjectCompletable() {
return getJSONObjectObservable().toCompletable();
}

public Observable<JSONArray> getJSONArrayObservable() {
this.setResponseAs(ResponseType.JSON_ARRAY);
if (this.getRequestType() == RequestType.SIMPLE) {
Expand All @@ -77,6 +87,14 @@ public Observable<JSONArray> getJSONArrayObservable() {
}
}

public Single<JSONArray> getJSONArraySingle() {
return getJSONArrayObservable().toSingle();
}

public Completable getJSONArrayCompletable() {
return getJSONArrayObservable().toCompletable();
}

public Observable<Bitmap> getBitmapObservable() {
this.setResponseAs(ResponseType.BITMAP);
if (this.getRequestType() == RequestType.SIMPLE) {
Expand All @@ -88,6 +106,14 @@ public Observable<Bitmap> getBitmapObservable() {
}
}

public Single<Bitmap> getBitmapSingle() {
return getBitmapObservable().toSingle();
}

public Completable getBitmapCompletable() {
return getBitmapObservable().toCompletable();
}

public Observable<String> getStringObservable() {
this.setResponseAs(ResponseType.STRING);
if (this.getRequestType() == RequestType.SIMPLE) {
Expand All @@ -99,10 +125,26 @@ public Observable<String> getStringObservable() {
}
}

public Single<String> getStringSingle() {
return getStringObservable().toSingle();
}

public Completable getStringCompletable() {
return getStringObservable().toCompletable();
}

public Observable<String> getDownloadObservable() {
return RxInternalNetworking.generateDownloadObservable(this);
}

public Single<String> getDownloadSingle() {
return getDownloadObservable().toSingle();
}

public Completable getDownloadCompletable() {
return getDownloadObservable().toCompletable();
}

public <T> Observable<T> getParseObservable(TypeToken<T> typeToken) {
this.setType(typeToken.getType());
this.setResponseAs(ResponseType.PARSED);
Expand All @@ -115,6 +157,14 @@ public <T> Observable<T> getParseObservable(TypeToken<T> typeToken) {
}
}

public <T> Single<T> getParseSingle(TypeToken<T> typeToken) {
return getParseObservable(typeToken).toSingle();
}

public <T> Completable getParseCompletable(TypeToken<T> typeToken) {
return getParseObservable(typeToken).toCompletable();
}

public <T> Observable<T> getObjectObservable(Class<T> objectClass) {
this.setType(objectClass);
this.setResponseAs(ResponseType.PARSED);
Expand All @@ -127,6 +177,14 @@ public <T> Observable<T> getObjectObservable(Class<T> objectClass) {
}
}

public <T> Single<T> getObjectSingle(Class<T> objectClass) {
return getObjectObservable(objectClass).toSingle();
}

public <T> Completable getObjectCompletable(Class<T> objectClass) {
return getObjectObservable(objectClass).toCompletable();
}

public <T> Observable<List<T>> getObjectListObservable(Class<T> objectClass) {
this.setType($Gson$Types.newParameterizedTypeWithOwner(null, List.class, objectClass));
this.setResponseAs(ResponseType.PARSED);
Expand All @@ -139,6 +197,14 @@ public <T> Observable<List<T>> getObjectListObservable(Class<T> objectClass) {
}
}

public <T> Single<List<T>> getObjectListSingle(Class<T> objectClass) {
return getObjectListObservable(objectClass).toSingle();
}

public <T> Completable getObjectListCompletable(Class<T> objectClass) {
return getObjectListObservable(objectClass).toCompletable();
}

public static class GetRequestBuilder extends ANRequest.GetRequestBuilder<GetRequestBuilder> {

public GetRequestBuilder(String url) {
Expand Down

0 comments on commit a70fdf0

Please sign in to comment.