RxAndroid 2.0.2订阅方法不起作用

时间:2019-05-01 01:52:50

标签: android rx-java2 rx-android

当我尝试使用

public Observable<String> list(Department department) {
        return departmentAPI.list(department)
                .flatMap((Function<ResponseBody, ObservableSource<String>>) responseBody -> Observable.just(responseBody.string()));
    }

private void initDepOptions() {
        final ProgressDialog progressDialog = new ProgressDialog(getContext());
        depDataManager.list(tDepartment)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnSubscribe(disposable -> {
                    progressDialog.setMessage(LOADING_MESSAGE);
                    progressDialog.show();
                })
                .doOnComplete(() -> progressDialog.dismiss())
                .subscribe(new RxSubscriber<String>() {
                    @Override
                    public void onNext(String s) {
                        ApiResponse response = GsonParser.fromJSONObject(s, ApiResponse.class);
                        if (response.success()) {
                            transform2DepartmentList(response.data);
                        } else {
                            Toasty.error(getContext(), response.message, Toast.LENGTH_LONG, true).show();
                        }
                    }
                });
    }

    private void transform2DepartmentList(String json) {
        JSONArray jsonArray = GsonParser.fromJSONObject(json, JSONArray.class);
        List<Department> departments = GsonParser.fromJSONArray(jsonArray, Department.class);

        departmentOptions = departments;
    }

从服务器反序列化json数据,但未调用onNext()

这是我的RxSubscribe类代码

public class RxSubscriber<T> extends DisposableObserver<T> {

    @Override
    public void onNext(@NonNull T t) {

    }

    @Override
    public void onError(@NonNull Throwable e) {

    }

    @Override
    public void onComplete() {

    }
}

那么,我需要做什么才能解决这个问题?

0 个答案:

没有答案