use of com.androidwind.androidquick.module.exception.ApiException in project AndroidQuick by ddnosh.
the class Network2Fragment method initViewsAndEvents.
@Override
protected void initViewsAndEvents(Bundle savedInstanceState) {
showLoadingDialog("加载中...");
mTestBeanList = new ArrayList<>();
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.setHasFixedSize(true);
mCommonAdapter = new CommonAdapter<TestBean>(getActivity(), R.layout.item_common_adapter_2, mTestBeanList) {
@Override
public void convert(CommonViewHolder holder, final TestBean bean) {
holder.setText(R.id.tv_login, bean.getLogin());
holder.setText(R.id.tv_id, bean.getId() + "");
holder.setImageResourceWithGlide(R.id.iv_avatar, bean.getAvatar_url());
holder.setOnClickListener(R.id.ll_rv_common_adapter_item, new View.OnClickListener() {
@Override
public void onClick(View v) {
LogUtil.d(TAG, "onItemClick");
ToastUtil.showToast(bean.getLogin() + " clicked!");
bean.setLogin(bean.getLogin() + " clicked!");
notifyDataSetChanged();
}
});
}
};
mRecyclerView.setAdapter(mCommonAdapter);
// mCompositeSubscription = new CompositeSubscription();
// Subscription subscription =
RetrofitManager.INSTANCE.getRetrofit(Constants.GANK_API_URL).create(TestApis.class).getOctocat().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<List<TestBean>>() {
@Override
public void onError(ApiException exception) {
LogUtil.e(TAG, "error:" + exception.getMessage());
}
@Override
public void onSuccess(List<TestBean> testBeans) {
dismissLoadingDialog();
LogUtil.i(TAG, testBeans.toString());
// 不能这样赋值:mTestBeanList = list;
// 方法一
// mTestBeanList.clear();
// mTestBeanList.addAll(list);
// mCommonAdapter.notifyDataSetChanged();
// 方法二
mCommonAdapter.update(testBeans);
}
});
// mCompositeSubscription.add(subscription);
RetrofitManager.INSTANCE.getRetrofit(Constants.GANK_API_URL).create(TestApis.class).getTestData().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<List<NameBean>>() {
@Override
public void onError(ApiException exception) {
LogUtil.e(TAG, "error:" + exception.getMessage());
}
@Override
public void onSuccess(List<NameBean> testBeans) {
dismissLoadingDialog();
LogUtil.i(TAG, testBeans.toString());
ToastUtil.showToast(testBeans.toString());
}
});
}
use of com.androidwind.androidquick.module.exception.ApiException in project AndroidQuick by ddnosh.
the class Network3Fragment method clickSyncFlatMap.
public void clickSyncFlatMap() {
TestApis testApis = RetrofitManager.INSTANCE.getRetrofit(Constants.GANK_API_URL).create(TestApis.class);
// 先访问唐诗宋词接口
testApis.getTangShiSongCi().subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).flatMap(new Function<TSSCRes<TSSCResult>, ObservableSource<XHYRes<XHYResult>>>() {
@Override
public ObservableSource<XHYRes<XHYResult>> apply(TSSCRes<TSSCResult> listTSSCRes) throws Exception {
if (listTSSCRes != null && listTSSCRes.getResult() != null) {
// 再访问歇后语接口
return testApis.getXHY();
} else {
return null;
}
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseObserver<XHYRes<XHYResult>>() {
@Override
public void onError(ApiException exception) {
LogUtil.e(TAG, "error:" + exception.getMessage());
}
@Override
public void onSuccess(XHYRes<XHYResult> testBeans) {
LogUtil.i(TAG, testBeans.toString());
}
});
}
use of com.androidwind.androidquick.module.exception.ApiException in project AndroidQuick by ddnosh.
the class Network3Fragment method clickAsyncMerge.
private void clickAsyncMerge() {
TestApis testApis = RetrofitManager.INSTANCE.getRetrofit(Constants.GANK_API_URL).create(TestApis.class);
Observable<TSSCRes<TSSCResult>> o1 = testApis.getTangShiSongCi();
Observable<XHYRes<XHYResult>> o2 = testApis.getXHY();
Observable.merge(o1, o2).subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).subscribe(new BaseObserver<Object>() {
@Override
public void onError(ApiException exception) {
LogUtil.e(TAG, "error:" + exception.getMessage());
}
@Override
public void onSuccess(Object object) {
if (object instanceof TSSCRes) {
LogUtil.i(TAG, object.toString());
} else if (object instanceof XHYRes) {
LogUtil.i(TAG, object.toString());
}
}
});
}
use of com.androidwind.androidquick.module.exception.ApiException in project AndroidQuick by ddnosh.
the class Network3Fragment method clickAsyncZip.
private void clickAsyncZip() {
TestApis testApis = RetrofitManager.INSTANCE.getRetrofit(Constants.GANK_API_URL).create(TestApis.class);
Observable<TSSCRes<TSSCResult>> o1 = testApis.getTangShiSongCi();
Observable<XHYRes<XHYResult>> o2 = testApis.getXHY();
Observable.zip(o1, o2, new BiFunction<TSSCRes<TSSCResult>, XHYRes<XHYResult>, Integer>() {
@Override
public Integer apply(TSSCRes<TSSCResult> tsscRes, XHYRes<XHYResult> xhyRes) throws Exception {
return tsscRes.getResult().size() + xhyRes.getResult().size();
}
}).subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).subscribe(new BaseObserver<Integer>() {
@Override
public void onError(ApiException exception) {
LogUtil.e(TAG, "error:" + exception.getMessage());
}
@Override
public void onSuccess(Integer count) {
LogUtil.e(TAG, "count = " + count);
}
});
}
use of com.androidwind.androidquick.module.exception.ApiException in project AndroidQuick by ddnosh.
the class MainActivity method getSdkVersion.
private void getSdkVersion() {
Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.github.com").client(new OkHttpClient.Builder().build()).addConverterFactory(// 添加 string 转换器
ScalarsConverterFactory.create()).addCallAdapterFactory(// 添加 RxJava 适配器
RxJava2CallAdapterFactory.create()).build();
retrofit.create(TestApis.class).getSdkVersion().compose(RxUtil.<String>applySchedulers()).compose(lifecycleProvider.bindUntilEvent(Lifecycle.Event.ON_DESTROY)).subscribe(new BaseObserver<String>() {
@Override
public void onError(ApiException exception) {
}
@Override
public void onSuccess(String html) {
if (!StringUtil.isEmpty(html)) {
if (html.contains("</text></g> </svg>")) {
String[] sArray = html.split("</text></g> </svg>");
int position = sArray[0].lastIndexOf(">");
if (position > 0) {
String sdk = sArray[0].substring(position + 1);
String sdkVersion = getResources().getString(R.string.sdk_version);
String version = String.format(sdkVersion, sdk);
tvSdkVersion.setText(version);
}
}
}
}
});
}
Aggregations