Search in sources :

Example 1 with Gank2Apis

use of com.androidwind.androidquick.demo.features.module.network.retrofit.Gank2Apis in project AndroidQuick by ddnosh.

the class Network1Presenter method initData.

@Override
public void initData(String type) {
    if ("get".equals(type)) {
        // 获取接口实例
        Gank2Apis gank2Apis = RetrofitManager.INSTANCE.getRetrofit(Constants.GANK_API_URL).create(Gank2Apis.class);
        // 调用方法得到一个Call
        Call<GankRes<List<String>>> call = gank2Apis.getHistoryDate();
        // 进行网络请求
        call.enqueue(new Callback<GankRes<List<String>>>() {

            @Override
            public void onResponse(Call<GankRes<List<String>>> call, Response<GankRes<List<String>>> response) {
                getView().updateView(response.body().getResults().toString());
            }

            @Override
            public void onFailure(Call<GankRes<List<String>>> call, Throwable t) {
                t.printStackTrace();
            }
        });
    } else {
        RetrofitManager.INSTANCE.getRetrofit(Constants.GANK_API_URL).create(GankApis.class).getHistoryDate().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<GankRes<List<String>>>() {

            @Override
            public void onError(ApiException exception) {
                LogUtil.e(TAG, "error:" + exception.getMessage());
            }

            @Override
            public void onSuccess(GankRes<List<String>> listGankRes) {
                LogUtil.i(TAG, listGankRes.getResults().toString());
                getView().updateView(listGankRes.getResults().toString());
            }
        });
    }
}
Also used : Gank2Apis(com.androidwind.androidquick.demo.features.module.network.retrofit.Gank2Apis) GankRes(com.androidwind.androidquick.demo.features.module.network.retrofit.GankRes) List(java.util.List) ApiException(com.androidwind.androidquick.module.exception.ApiException)

Aggregations

Gank2Apis (com.androidwind.androidquick.demo.features.module.network.retrofit.Gank2Apis)1 GankRes (com.androidwind.androidquick.demo.features.module.network.retrofit.GankRes)1 ApiException (com.androidwind.androidquick.module.exception.ApiException)1 List (java.util.List)1