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());
}
});
}
}
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;
}
}
Aggregations