Search in sources :

Example 1 with GankRes

use of com.androidwind.androidquick.demo.features.module.network.retrofit.GankRes 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)

Example 2 with GankRes

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

the class JsonFragment method onClick.

@OnClick({ R.id.btn_tools_gsonhelper_common, R.id.btn_tools_gsonhelper_generic, R.id.btn_tools_fastjsonhelper })
public void onClick(View view) {
    mTvConsole.setText("");
    switch(view.getId()) {
        case R.id.btn_tools_gsonhelper_common:
            long startTime1 = System.nanoTime();
            GankFuliBean gsonObj = GsonUtil.fromJson(testJsonString, GankFuliBean.class);
            List<GankFuliBean.FuliBean> fulis = gsonObj.getResults();
            String desc = " ";
            for (GankFuliBean.FuliBean fuli : fulis) {
                desc += fuli.getDesc() + "\n";
            }
            ToastUtil.showToast(desc);
            mTvConsole.setText(gsonObj.toString());
            break;
        case R.id.btn_tools_gsonhelper_generic:
            long startTime2 = System.nanoTime();
            GankRes<List<FuliBean>> gsonObj2 = GsonUtil.fromJson(testJsonString, new TypeToken<GankRes<List<FuliBean>>>() {
            });
            long consumingTime2 = System.nanoTime() - startTime2;
            ToastUtil.showToast("耗时" + consumingTime2 / 1000 + "微秒");
            break;
        case R.id.btn_tools_fastjsonhelper:
            long startTime3 = System.nanoTime();
            GankRes<List<FuliBean>> fastObj = FastJsonHelper.parseObject(testJsonString, new TypeReference<GankRes<List<FuliBean>>>() {
            });
            long consumingTime3 = System.nanoTime() - startTime3;
            ToastUtil.showToast("耗时" + consumingTime3 / 1000 + "微秒");
            break;
    }
}
Also used : GankFuliBean(com.androidwind.androidquick.demo.bean.GankFuliBean) FuliBean(com.androidwind.androidquick.demo.bean.FuliBean) GankFuliBean(com.androidwind.androidquick.demo.bean.GankFuliBean) GankRes(com.androidwind.androidquick.demo.features.module.network.retrofit.GankRes) List(java.util.List) OnClick(butterknife.OnClick)

Aggregations

GankRes (com.androidwind.androidquick.demo.features.module.network.retrofit.GankRes)2 List (java.util.List)2 OnClick (butterknife.OnClick)1 FuliBean (com.androidwind.androidquick.demo.bean.FuliBean)1 GankFuliBean (com.androidwind.androidquick.demo.bean.GankFuliBean)1 Gank2Apis (com.androidwind.androidquick.demo.features.module.network.retrofit.Gank2Apis)1 ApiException (com.androidwind.androidquick.module.exception.ApiException)1