|
|
@ -17,8 +17,11 @@ import io.reactivex.FlowableTransformer; |
|
|
|
import io.reactivex.Observable; |
|
|
|
import io.reactivex.Observable; |
|
|
|
import io.reactivex.ObservableSource; |
|
|
|
import io.reactivex.ObservableSource; |
|
|
|
import io.reactivex.ObservableTransformer; |
|
|
|
import io.reactivex.ObservableTransformer; |
|
|
|
|
|
|
|
import io.reactivex.Single; |
|
|
|
|
|
|
|
import io.reactivex.SingleSource; |
|
|
|
|
|
|
|
import io.reactivex.SingleTransformer; |
|
|
|
|
|
|
|
|
|
|
|
public class HttpResultTransformer<Upstream, Downstream, T extends Result<Upstream>> implements ObservableTransformer<T, Downstream>, FlowableTransformer<T, Downstream> { |
|
|
|
public class HttpResultTransformer<Upstream, Downstream, T extends Result<Upstream>> implements ObservableTransformer<T, Downstream>, FlowableTransformer<T, Downstream>, SingleTransformer<T, Downstream> { |
|
|
|
|
|
|
|
|
|
|
|
private final boolean mRequireNonNullData; |
|
|
|
private final boolean mRequireNonNullData; |
|
|
|
private final DataExtractor<Downstream, Upstream> mDataExtractor; |
|
|
|
private final DataExtractor<Downstream, Upstream> mDataExtractor; |
|
|
@ -57,6 +60,18 @@ public class HttpResultTransformer<Upstream, Downstream, T extends Result<Upstre |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public SingleSource<Downstream> apply(Single<T> upstream) { |
|
|
|
|
|
|
|
Single<Downstream> downstreamSingle = upstream.map(this::processData); |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
|
|
|
PostTransformer<Downstream> postTransformer = (PostTransformer<Downstream>) NetContext.get().netProvider().postTransformer(); |
|
|
|
|
|
|
|
if (postTransformer != null) { |
|
|
|
|
|
|
|
return downstreamSingle.compose(postTransformer); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return downstreamSingle; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Downstream processData(Result<Upstream> rResult) { |
|
|
|
private Downstream processData(Result<Upstream> rResult) { |
|
|
|
if (rResult == null) { |
|
|
|
if (rResult == null) { |
|
|
|
|
|
|
|
|
|
|
|