com.lzy.okgo.convert.StringConvert Java Examples
The following examples show how to use
com.lzy.okgo.convert.StringConvert.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UploadAdapter.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
public void updateData(int type) { //这里是将数据库的数据恢复 this.type = type; if (type == TYPE_ALL) values = OkUpload.restore(UploadManager.getInstance().getAll()); if (type == TYPE_FINISH) values = OkUpload.restore(UploadManager.getInstance().getFinished()); if (type == TYPE_ING) values = OkUpload.restore(UploadManager.getInstance().getUploading()); //由于Converter是无法保存下来的,所以这里恢复任务的时候,需要额外传入Converter,否则就没法解析数据 //至于数据类型,统一就行,不一定非要是String for (UploadTask<?> task : values) { //noinspection unchecked Request<String, ? extends Request> request = (Request<String, ? extends Request>) task.progress.request; request.converter(new StringConvert()); } notifyDataSetChanged(); }
Example #2
Source File: CategoryFragment.java From MyHearts with Apache License 2.0 | 6 votes |
private void refreshData(String url) { OkGo.get(url) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<RoomInfo>() { }.getType(); RoomInfo roomInfo = new Gson().fromJson(s, type); if (roomInfo.getData().size() > 0) { mDataEntities.clear(); mDataEntities.addAll(roomInfo.getData()); mCategoryAdapter.setDataEntities(mDataEntities); } }, throwable -> { }); }
Example #3
Source File: CategoryFragment.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 下拉刷新数据 * * @param url url */ private void requestData(String url) { limit = lordMoreNum; offset = 0; if (mIndex == 0) { url = HttpUrlPaths.getDouyuLiveChannel(limit, offset); } else { url = HttpUrlPaths.getDouyuSubChannelBaseTag(mIndex, limit, offset); } OkGo.get(url) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<RoomInfo>() { }.getType(); RoomInfo roomInfo = new Gson().fromJson(s, type); if (roomInfo.getData().size() > 0) { mDataEntities.addAll(roomInfo.getData()); mCategoryAdapter.setDataEntities(mDataEntities); } }, throwable -> { }); }
Example #4
Source File: LivingFragment.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 请求banner图片 */ private void initBannerData() { OkGo.get(HttpUrlPaths.LIVING_STREAMING_BANNER_URL) .params("type", "live") .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<LivingBannerBean>() { }.getType(); LivingBannerBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getErrorStr().equals("success") && bean.getResultCount() > 0) { beanResults = bean.getResults(); updateBannerUI(beanResults); } }, throwable -> { }); }
Example #5
Source File: HotFragment.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 请求数据 */ private void initData() { OkGo.post(HttpUrlPaths.THOUGHTS_URL) .params("userid",54442) .params("labelid",catgId) .params("type",1) .params("page",page) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(()->{}) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s->{ Type type = new TypeToken<ThoughtsBean>(){}.getType(); ThoughtsBean bean = new Gson().fromJson(s,type); if (bean.getErrorCode()==0 &&bean.getResultCount()>0 &&bean.getErrorStr().equals("success")){ mThroughtDatas = bean.getResults(); mThroughtAdapter.setResultsBeen(mThroughtDatas); /// mRefreshLayout.setClickable(true); // mRefreshLayout.setLoadMore(true); } },throwable -> {}); }
Example #6
Source File: CircleFriendsActivity.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 请求内容数据 */ private void initContent() { OkGo.get(HttpUrlPaths.THOUGHTS_DETAIL_URL) .params("userid", 0) .params("eventid", eventid) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<CircleFriendsUserBean>() { }.getType(); CircleFriendsUserBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getErrorStr().equals("success") && bean.getResultCount() > 0) { mResultsEntity = bean.getResults(); initUI(mResultsEntity); } }, throwable -> { }); }
Example #7
Source File: LordDetailActivity.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 请求数据 */ private void initLordDetailData() { OkGo.post(HttpUrlPaths.LORD_DETAIL_URL) .params("catgId", catgId) .params("page", page) .params("userid", 0) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<LordDetailBean>() { }.getType(); LordDetailBean bean = new Gson().fromJson(s, type); if (bean.getErrorStr().equals("success") && bean.getErrorCode() == 0 && bean.getResultCount() > 0) { mLordDetailDatas = bean.getResults(); detailAdapter.addData(mLordDetailDatas); } }, throwable -> { }); }
Example #8
Source File: LordDetailActivity.java From MyHearts with Apache License 2.0 | 6 votes |
private void initRefresh(MaterialRefreshLayout materialRefreshLayout) { page = 1; //重置 在刷新的时候 OkGo.post(HttpUrlPaths.LORD_DETAIL_URL) .params("catgId", catgId) .params("page", page) .params("userid", 0) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<LordDetailBean>() { }.getType(); LordDetailBean bean = new Gson().fromJson(s, type); if (bean.getErrorStr().equals("success") && bean.getErrorCode() == 0 && bean.getResultCount() > 0) { mLordDetailDatas.clear(); detailAdapter.notifyDataSetChanged(); mLordRefresh.finishRefresh(); } }, throwable -> { }); }
Example #9
Source File: LordFragment.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 刷新数据 */ private void refreshData() { OkGo.post(HttpUrlPaths.LORD_CATEGORY) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<LordBean>() { }.getType(); LordBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getErrorStr().equals("success") && bean.getResultCount() > 0) { mLordDatas.clear(); mLordDatas = bean.getResults(); //mLordAdapter.a(mLordDatas); mLordAdapter.setDatas(mLordDatas); mLordRefresh.setRefreshing(false); } }, throwable -> { }); }
Example #10
Source File: LordFragment.java From MyHearts with Apache License 2.0 | 6 votes |
private void initLordData() { OkGo.post(HttpUrlPaths.LORD_CATEGORY) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<LordBean>() { }.getType(); LordBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getErrorStr().equals("success") && bean.getResultCount() > 0) { mLordDatas = bean.getResults(); mLordAdapter.setDatas(mLordDatas); mLordAdapter.notifyDataSetChanged(); } }, throwable -> { }); }
Example #11
Source File: OrationActivity.java From MyHearts with Apache License 2.0 | 6 votes |
@Override public void initData() { super.initData(); OkGo.post(HttpUrlPaths.SCAN_MORE) .params("userid", "54442") .params("page", page + "") .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<HomeNewsBean>() { }.getType(); HomeNewsBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getErrorStr().equals("success") && bean.getResults().size() > 0) { mOrationDatas = bean.getResults(); mOrationAdapter.addData(mOrationDatas); } }, throwable -> { }); }
Example #12
Source File: HomeFragment.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 请求推荐咨询师数据 */ private void initAdvisoryData() { OkGo.post(HttpUrlPaths.HOME_RECOMMENT) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<AdvisoryBean>() { }.getType(); AdvisoryBean bean = new Gson().fromJson(s, type); if (bean != null && bean.getErrorCode() == 0 && bean.getErrorStr().equals("success")) { mAdvisoryBean = bean.getResults(); if (mAdvisoryBean != null && mAdvisoryBean.size() > 0) { initAdvisory(mAdvisoryBean); } } }, throwable -> { }); }
Example #13
Source File: HomeFragment.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 请求首页下面展示的图片的第一个banner */ private void initRecommentOne() { OkGo.post(HttpUrlPaths.HOME_RECOMMENT_ONE_BANNER) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<HomeBannerOne>() { }.getType(); HomeBannerOne homeBannerOne = new Gson().fromJson(s, type); if (homeBannerOne.getErrorStr().equals("success") && homeBannerOne.getErrorCode() == 0) { Glide.with(getContext()) .load(homeBannerOne.getResults().getBanner()) .asBitmap() .into(mRecommentImgOne); } }, throwable -> { }); }
Example #14
Source File: UploadAdapter.java From okhttp-OkGo with Apache License 2.0 | 6 votes |
public List<UploadTask<?>> updateData(List<ImageItem> images) { this.type = -1; this.images = images; values = new ArrayList<>(); if (images != null) { Random random = new Random(); for (int i = 0; i < images.size(); i++) { ImageItem imageItem = images.get(i); //这里是演示可以传递任何数据 PostRequest<String> postRequest = OkGo.<String>post(Urls.URL_FORM_UPLOAD)// .headers("aaa", "111")// .params("bbb", "222")// .params("fileKey" + i, new File(imageItem.path))// .converter(new StringConvert()); UploadTask<String> task = OkUpload.request(imageItem.path, postRequest)// .priority(random.nextInt(100))// .extra1(imageItem)// .save(); values.add(task); } } notifyDataSetChanged(); return values; }
Example #15
Source File: HomeFragment.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 请求首页下面展示的图片的第一个banner */ private void initRecommentTwo() { OkGo.post(HttpUrlPaths.HOME_RECOMMENT_TWO_BANNER) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<HomeBannerTwo>() { }.getType(); HomeBannerTwo homeBannerTwo = new Gson().fromJson(s, type); if (homeBannerTwo.getErrorStr().equals("success") && homeBannerTwo.getErrorCode() == 0) { Glide.with(getContext()) .load(homeBannerTwo.getResults().getImage()) .asBitmap() .into(mImageView); mTvDesTrecomment.setText(homeBannerTwo.getResults().getTitle()); } }, throwable -> { }); }
Example #16
Source File: CircleFriendsActivity.java From MyHearts with Apache License 2.0 | 5 votes |
/** * 请求评论数据 */ private void initComment() { OkGo.get(HttpUrlPaths.THOUGHTS_DETAIL_COMMENT_URL) .params("type", "user_event") .params("eventid", eventid) .params("page", page) .params("userid", 0) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<CircleFriendsCommentBean>() { }.getType(); CircleFriendsCommentBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getResultCount() > 0 && bean.getErrorStr().equals("success")) { mCircleFriendsComments = bean.getResults(); mRefreshLayout.setRefreshing(false); mScrollView.setVisibility(View.VISIBLE); if (mCircleFriendsComments.size() > 0) { //Toast.makeText(this, "mCircleFriendsComments.size():" + mCircleFriendsComments.size(), Toast.LENGTH_SHORT).show(); mRecomment.setVisibility(View.VISIBLE); mCommentAdapter.setDatas(mCircleFriendsComments); } else { mRecomment.setVisibility(View.GONE); } } }, throwable -> { }); }
Example #17
Source File: NewsDetailActivity.java From MyHearts with Apache License 2.0 | 5 votes |
@Override public void initData() { super.initData(); if (!TextUtils.isEmpty(id)) { String url = HttpUrlPaths.getNewsDetailUrl(id); OkGo.get(url) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<NewsDetailBean>() { }.getType(); NewsDetailBean bean = new Gson().fromJson(s, type); String htmlData = bean.getContent() .replace("<img", "<img style='max-width:100%;height:auto;'"); mTvname.setText(bean.getTitle()); if (bean.getEditorName() != null) { mTvauthor.setText(bean.getEditorName() + ""); } mTvpublishtime.setText(bean.getPublishTime()); mWebview.loadData(htmlData, "text/html; charset=UTF-8", null); }, throwable -> { }); } }
Example #18
Source File: OkGoCallback.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 拿到响应后, 将数据转换成需要的格式, 子线程中执行, 可以是耗时操作 */ @Override public String convertResponse(okhttp3.Response response) throws Throwable { // HttpUrl httpUrl = response.request().url(); // DevLogger.e("url: " + httpUrl); DevLogger.dTag(TAG, "响应成功, 转换数据: " + url); String json = new StringConvert().convertResponse(response); DevLogger.json(json); response.close(); return json; }
Example #19
Source File: CategoryFragment.java From MyHearts with Apache License 2.0 | 5 votes |
/** * 获取到更多数据 上拉刷新 */ private void getMoreData() { offset += limit; limit += lordMoreNum; if (mIndex == 0) { url = HttpUrlPaths.getDouyuLiveChannel(limit, offset); } else { url = HttpUrlPaths.getDouyuSubChannelBaseTag(mIndex, limit, offset); } OkGo.get(url) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<RoomInfo>() { }.getType(); RoomInfo roomInfo = new Gson().fromJson(s, type); if (roomInfo.getData().size() > 0) { mDataEntities.addAll(roomInfo.getData()); mCategoryAdapter.setDataEntities(mDataEntities); mCategoryAdapter.notifyItemRemoved(mCategoryAdapter.getItemCount()); } }, throwable -> { }); }
Example #20
Source File: LivingFragment.java From MyHearts with Apache License 2.0 | 5 votes |
private void getMoreData() { if (isHasMore) { mLivingAdapter.notifyItemRemoved(mLivingAdapter.getItemCount()); Toast.makeText(getActivity(), getActivity().getResources() .getString(R.string.loading_finish), Toast.LENGTH_SHORT).show(); return; } page++; OkGo.post(HttpUrlPaths.LIVING_STREAMING_URL) .params("userid", "54442") .params("page", page) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<LivingBean>() { }.getType(); LivingBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getErrorStr().equals("success")) { if (bean.getResultCount() < 30) { //没有下一页数据了 isHasMore = true; } List<LivingBean.ResultsEntity> results = bean.getResults(); mRecyclerView.setVisibility(View.VISIBLE); mResultsEntities.addAll(results); mLivingAdapter.setEntities(mResultsEntities); //mRefreshLayout.setRefreshing(false); } }, throwable -> { }); }
Example #21
Source File: LivingFragment.java From MyHearts with Apache License 2.0 | 5 votes |
/** * 进入就刷新 */ private void delayInitData() { //mRefreshLayout.setRefreshing(true); //自动刷新 OkGo.get(HttpUrlPaths.LIVING_STREAMING_URL) .params("userid", "54442") .params("page", page) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<LivingBean>() { }.getType(); LivingBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getResultCount() > 0 && bean.getErrorStr().equals("success")) { List<LivingBean.ResultsEntity> results = bean.getResults(); mRecyclerView.setVisibility(View.VISIBLE); mResultsEntities = results; mLivingAdapter.setEntities(mResultsEntities); mRefreshLayout.setRefreshing(false); } }, throwable -> { }); }
Example #22
Source File: HotFragment.java From MyHearts with Apache License 2.0 | 5 votes |
private void getMoreData() { page++; OkGo.post(HttpUrlPaths.THOUGHTS_URL) .params("userid",54442) .params("labelid",catgId) .params("type",1) .params("page",1) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(()->{}) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s->{ Type type = new TypeToken<ThoughtsBean>(){}.getType(); ThoughtsBean bean = new Gson().fromJson(s,type); if (bean.getErrorCode()==0 &&bean.getResultCount()>0 &&bean.getErrorStr().equals("success")){ // mThroughtDatas.clear(); List<ThoughtsBean.ResultsBean> beens = bean.getResults(); // mRefreshLayout.finishRefresh(); mThroughtDatas.addAll(mThroughtDatas.size(),beens); //mThroughtAdapter.notifyDataSetChanged(); mThroughtAdapter.setResultsBeen(mThroughtDatas); } },throwable -> {}); }
Example #23
Source File: HotFragment.java From MyHearts with Apache License 2.0 | 5 votes |
/** * 当点击popup的时候,根据所选择的分类,来展示不同分类下面的空间消息内容 * * @param id catgId */ private void refreshId(int id) { page = 1; OkGo.post(HttpUrlPaths.THOUGHTS_URL) .params("userid",54442) .params("labelid",catgId) .params("type",1) .params("page",1) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(()->{}) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s->{ Type type = new TypeToken<ThoughtsBean>(){}.getType(); ThoughtsBean bean = new Gson().fromJson(s,type); if (bean.getErrorCode()==0 &&bean.getResultCount()>0 &&bean.getErrorStr().equals("success")){ mThroughtDatas.clear(); // mRefreshLayout.finishRefresh(); mThroughtDatas = bean.getResults(); //mThroughtAdapter.notifyDataSetChanged(); mThroughtAdapter.setResultsBeen(mThroughtDatas); mRefreshLayout.setRefreshing(false); } },throwable -> {}); }
Example #24
Source File: NewFragment.java From MyHearts with Apache License 2.0 | 5 votes |
private void getMoreData() { page++; OkGo.post(HttpUrlPaths.THOUGHTS_URL) .params("userid", 54442) .params("labelid", catgId) .params("type", 2) .params("page", 1) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<ThoughtsBean>() { }.getType(); ThoughtsBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getResultCount() > 0 && bean.getErrorStr().equals("success")) { // mThroughtDatas.clear(); List<ThoughtsBean.ResultsBean> beens = bean.getResults(); // mRefreshLayout.finishRefresh(); mThroughtDatas.addAll(mThroughtDatas.size(), beens); //mThroughtAdapter.notifyDataSetChanged(); mThroughtAdapter.setResultsBeen(mThroughtDatas); } }, throwable -> { }); }
Example #25
Source File: NewFragment.java From MyHearts with Apache License 2.0 | 5 votes |
/** * 当点击popup的时候,根据所选择的分类,来展示不同分类下面的空间消息内容 * * @param id catgId */ private void refreshId(int id) { OkGo.post(HttpUrlPaths.THOUGHTS_URL) .params("userid", 54442) .params("labelid", catgId) .params("type", 2) .params("page", 1) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<ThoughtsBean>() { }.getType(); ThoughtsBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getResultCount() > 0 && bean.getErrorStr().equals("success")) { mThroughtDatas.clear(); // mRefreshLayout.finishRefresh(); mThroughtDatas = bean.getResults(); //mThroughtAdapter.notifyDataSetChanged(); mThroughtAdapter.setResultsBeen(mThroughtDatas); mRefreshLayout.setRefreshing(false); } }, throwable -> { }); }
Example #26
Source File: NewFragment.java From MyHearts with Apache License 2.0 | 5 votes |
/** * 请求数据 */ private void initData() { //labelid=0&type=1&page=1&userid=0 OkGo.post(HttpUrlPaths.THOUGHTS_URL) .params("userid", 54442) .params("labelid", catgId) .params("type", 2) .params("page", 1) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<ThoughtsBean>() { }.getType(); ThoughtsBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getResultCount() > 0 && bean.getErrorStr().equals("success")) { mThroughtDatas = bean.getResults(); mThroughtAdapter.setResultsBeen(mThroughtDatas); // mRefreshLayout.setLoadMore(true); // mRefreshLayout.setClickable(true); } }, throwable -> { }); }
Example #27
Source File: CircleFriendsActivity.java From MyHearts with Apache License 2.0 | 5 votes |
/** * 加载更多数据 */ private void getMoreData() { page++; if (page >= totalPage + 1) { Toast.makeText(this, getResources().getString(R.string.loading_finish), Toast.LENGTH_SHORT).show(); CustomPrograss.disMiss(); return; } OkGo.get(HttpUrlPaths.THOUGHTS_DETAIL_COMMENT_URL) .params("type", "user_event") .params("eventid", eventid) .params("page", page) .params("userid", 0) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<CircleFriendsCommentBean>() { }.getType(); CircleFriendsCommentBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getResultCount() > 0 && bean.getErrorStr().equals("success")) { List<CircleFriendsCommentBean.ResultsEntity> results = bean.getResults(); mCircleFriendsComments.addAll(results); //Toast.makeText(this, "mCircleFriendsComments.size():" + mCircleFriendsComments.size(), Toast.LENGTH_SHORT).show(); mCommentAdapter.setDatas(mCircleFriendsComments); CustomPrograss.disMiss(); mScrollView.loadingComponent(); } }, throwable -> { }); }
Example #28
Source File: RxCommonActivity.java From okhttp-OkGo with Apache License 2.0 | 5 votes |
@OnClick(R.id.commonRequest) public void commonRequest(View view) { OkGo.<String>post(Urls.URL_METHOD)// .headers("aaa", "111")// .params("bbb", "222")// .converter(new StringConvert())// .adapt(new ObservableResponse<String>())// .subscribeOn(Schedulers.io())// .doOnSubscribe(new Consumer<Disposable>() { @Override public void accept(@NonNull Disposable disposable) throws Exception { showLoading(); } })// .observeOn(AndroidSchedulers.mainThread())// .subscribe(new Observer<Response<String>>() { @Override public void onSubscribe(@NonNull Disposable d) { addDisposable(d); } @Override public void onNext(@NonNull Response<String> response) { handleResponse(response); } @Override public void onError(@NonNull Throwable e) { e.printStackTrace(); showToast("请求失败"); handleError(null); } @Override public void onComplete() { dismissLoading(); } }); }
Example #29
Source File: GroupDetailActivity.java From MyHearts with Apache License 2.0 | 5 votes |
@Override public void initData() { super.initData(); if (id != 0) { OkGo.post(HttpUrlPaths.LORD_GROUP_DETAIL_URL) .params("groupid", id) .params("userid", 0) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<GroupDetailBean>() { }.getType(); GroupDetailBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getErrorStr().equals("success") && bean.getResultCount() > 0) { mResults = bean.getResults(); setData(mResults); } }, throwable -> { }); } }
Example #30
Source File: HomeFragment.java From MyHearts with Apache License 2.0 | 5 votes |
/** * 请求跑马灯数据 */ private void initMarqueeData() { OkGo.post(HttpUrlPaths.HOME_MARQUEE) .getCall(StringConvert.create(), RxAdapter.<String>create()) .doOnSubscribe(() -> { //可以显示dialog }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(s -> { Type type = new TypeToken<MarqueeBean>() { }.getType(); MarqueeBean bean = new Gson().fromJson(s, type); if (bean.getErrorCode() == 0 && bean.getErrorStr().equals("success")) { mResultsBeen = bean.getResults(); if (mResultsBeen != null && mResultsBeen.size() > 0) { List<String> info = new ArrayList<>(); for (MarqueeBean.ResultsBean resultsBean : mResultsBeen) { info.add(resultsBean.getLabel()); } mMarqueeView.startWithList(info); } } }, throwable -> { //出现错误的时候调用 }); }