Java Code Examples for com.lzy.okgo.convert.StringConvert

The following examples show how to use com.lzy.okgo.convert.StringConvert. These examples are extracted from open source projects. 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 Project: okhttp-OkGo   Source File: UploadAdapter.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: okhttp-OkGo   Source File: UploadAdapter.java    License: Apache License 2.0 6 votes vote down vote up
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 3
Source Project: MyHearts   Source File: HomeFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 请求首页下面展示的图片的第一个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 4
Source Project: MyHearts   Source File: HomeFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 请求首页下面展示的图片的第一个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 5
Source Project: MyHearts   Source File: HomeFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 请求推荐咨询师数据
 */
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 6
Source Project: MyHearts   Source File: OrationActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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 7
Source Project: MyHearts   Source File: LordFragment.java    License: Apache License 2.0 6 votes vote down vote up
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 8
Source Project: MyHearts   Source File: LordFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 刷新数据
 */
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 9
Source Project: MyHearts   Source File: LordDetailActivity.java    License: Apache License 2.0 6 votes vote down vote up
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 10
Source Project: MyHearts   Source File: LordDetailActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 请求数据
 */
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 11
Source Project: MyHearts   Source File: CircleFriendsActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 请求内容数据
 */
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 12
Source Project: MyHearts   Source File: HotFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 请求数据
 */
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 13
Source Project: MyHearts   Source File: LivingFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 请求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 14
Source Project: MyHearts   Source File: CategoryFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 下拉刷新数据
 *
 * @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 15
Source Project: MyHearts   Source File: CategoryFragment.java    License: Apache License 2.0 6 votes vote down vote up
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 16
Source Project: DevUtils   Source File: OkGoCallback.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 拿到响应后, 将数据转换成需要的格式, 子线程中执行, 可以是耗时操作
     */
    @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 17
Source Project: okhttp-OkGo   Source File: RxCommonActivity.java    License: Apache License 2.0 5 votes vote down vote up
@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 18
Source Project: okhttp-OkGo   Source File: RxCommonActivity.java    License: Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.upString)
public void upString(View view) {
    OkGo.<String>post(Urls.URL_TEXT_UPLOAD)//
            .headers("aaa", "111")//
            .upString("上传的文本。。。")//
            .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 19
Source Project: okhttp-OkGo   Source File: SyncActivity.java    License: Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.sync)
    public void sync(View view) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
//                    //同步会阻塞主线程,必须开线程
//                    Response response = OkGo.get(Urls.URL_JSONOBJECT)//
//                            .tag(this)//
//                            .headers("header1", "headerValue1")//
//                            .params("param1", "paramValue1")//
//                            .execute();  //不传callback即为同步请求

                    Call<String> call = OkGo.<String>get(Urls.URL_JSONOBJECT)//
                            .tag(this)//
                            .headers("header1", "headerValue1")//
                            .params("param1", "paramValue1")//
                            .converter(new StringConvert())//
                            .adapt();
                    Response<String> response = call.execute();

                    Message message = Message.obtain();
                    message.obj = response.body();
                    handler.sendMessage(message);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
 
Example 20
Source Project: MyHearts   Source File: HomeFragment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 请求文档类型数据
 */
private void initData() {
    OkGo.post(HttpUrlPaths.SCAN_MORE)
            .params("userid", "54442")
            .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) {
                    mHomeNewsData = bean.getResults();
                    CustomPrograss.disMiss();
                    mHomeNewAdapter = new OrationAdapter(getContext(), mHomeNewsData);
                    mHotRecyclerView.setAdapter(mHomeNewAdapter);
                    mHomeNewAdapter.setOnItemClickListener((view, position) -> {
                        HomeNewsBean.ResultsBean resultsBean = mHomeNewsData.get(position);
                        Intent intent = new Intent(getActivity(), NewsActivity.class);
                        intent.putExtra("id", resultsBean.getId());
                        intent.putExtra("userid", "54442");
                        startActivity(intent);
                    });
                }
            }, throwable -> {

            });
}
 
Example 21
Source Project: MyHearts   Source File: HomeFragment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 请求跑马灯数据
 */
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 -> {  //出现错误的时候调用

            });


}
 
Example 22
Source Project: MyHearts   Source File: OrationActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void loadMoreData() {
    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) {
                    List<HomeNewsBean.ResultsBean> resultData = bean.getResults();

                    mOrationDatas.addAll(resultData);
                    mOrationAdapter.addData(mOrationAdapter.getDatas().size(),resultData);
                    mOrationAdapter.notifyDataSetChanged();
                    mMaterialRefreshLayout.finishRefreshLoadMore();
                }
            }, throwable -> {

            });

}
 
Example 23
Source Project: MyHearts   Source File: OrationActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void initRefresh(MaterialRefreshLayout materialRefreshLayout) {
    page = 1;
    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.clear();
                    mOrationDatas = bean.getResults();
                    mOrationAdapter.addData(mOrationDatas);
                    materialRefreshLayout.finishRefresh();

                }
            }, throwable -> {

            });
}
 
Example 24
Source Project: MyHearts   Source File: NewsActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void requestTitleData() {
        OkGo.post(HttpUrlPaths.NEWS_USER_DETAIL)
                .params("id", id)
                .params("userid", userid)
                .getCall(StringConvert.create(), RxAdapter.<String>create())
                .doOnSubscribe(() -> {

                }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(s -> {
                    Type type = new TypeToken<NewTitleBean>() {
                    }.getType();
                    NewTitleBean bean = new Gson().fromJson(s, type);
                    if (bean.getErrorCode() == 0 && bean.getErrorStr().equals("success")
                            && bean.getResultCount() > 0) {

                        mTvCategory.setText(bean.getResults().getCatg());
                        mTvViewCount.setText(bean.getResults().getViewCnt());
//                        Glide.with(NewsActivity.this)
//                                .load(bean.getResults().getIcon())
//                                .asBitmap()
//                                .error(R.mipmap.login_bg)
//                                .placeholder(R.mipmap.login_bg)
//                                .into(mImgBg);

                        mTvTitle.setText(bean.getResults().getTitle());
                        url = HttpUrlPaths.NEWS_DETAIL + "?id=" + bean.getResults().getId();
                        requestWebViewUrl(url);
                    }
                }, throwable -> {
                });
    }
 
Example 25
Source Project: MyHearts   Source File: GroupMemberActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initData() {
    super.initData();
    if (!TextUtils.isEmpty(groupid)) {
        OkGo.get(HttpUrlPaths.LORD_MEMBER_DETAILE_URL)
                .params("page", page)
                .params("groupid", groupid)
                .getCall(StringConvert.create(), RxAdapter.<String>create())
                .doOnSubscribe(() -> {
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(s -> {
                    Type type = new TypeToken<GroupMemberBean>() {
                    }.getType();
                    GroupMemberBean bean = new Gson().fromJson(s, type);
                    if (bean.getErrorCode() == 0
                            && bean.getErrorStr().equals("success")
                            && bean.getResultCount() > 0) {
                        mMemberDatas = bean.getResults();
                        mMemberAdapter.addData(mMemberDatas);
                    }

                }, throwable -> {
                });

    }
}
 
Example 26
Source Project: MyHearts   Source File: GroupMemberActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 加载下一页数据
 */
private void getMoreData() {
    page++;
    if (page > totalPage + 1) {
        Toast.makeText(this,
                getResources()
                        .getString(R.string.loading_finish),
                Toast.LENGTH_SHORT).show();
        return;
    }
    if (!TextUtils.isEmpty(groupid)) {
        OkGo.get(HttpUrlPaths.LORD_MEMBER_DETAILE_URL)
                .params("page", page)
                .params("groupid", groupid)
                .getCall(StringConvert.create(), RxAdapter.<String>create())
                .doOnSubscribe(() -> {
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(s -> {
                    Type type = new TypeToken<GroupMemberBean>() {
                    }.getType();
                    GroupMemberBean bean = new Gson().fromJson(s, type);
                    if (bean.getErrorCode() == 0
                            && bean.getErrorStr().equals("success")
                            && bean.getResultCount() > 0) {
                      //  int index = mMemberDatas.size()-1;
                        mMemberDatas = bean.getResults();
                      //  mRecyclerView.scrollToPosition(index);
                        mMemberAdapter.addData(mMemberDatas.size(),mMemberDatas);
                        mMemberAdapter.notifyDataSetChanged();
                    }

                }, throwable -> {
                });

    }

}
 
Example 27
Source Project: MyHearts   Source File: GroupMemberActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 刷新数据
 */
private void refreshData() {
    page = 1;
    if (!TextUtils.isEmpty(groupid)) {
        OkGo.get(HttpUrlPaths.LORD_MEMBER_DETAILE_URL)
                .params("page", page)
                .params("groupid", groupid)
                .getCall(StringConvert.create(), RxAdapter.<String>create())
                .doOnSubscribe(() -> {
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(s -> {
                    Type type = new TypeToken<GroupMemberBean>() {
                    }.getType();
                    GroupMemberBean bean = new Gson().fromJson(s, type);
                    if (bean.getErrorCode() == 0
                            && bean.getErrorStr().equals("success")
                            && bean.getResultCount() > 0) {
                        mMemberDatas.clear();
                        mMemberDatas = bean.getResults();
                        mMemberAdapter.addData(mMemberDatas);
                        mRefreshLayout.setRefreshing(false);
                    }

                }, throwable -> {
                });

    }
}
 
Example 28
Source Project: MyHearts   Source File: LordDetailActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 加载更多的数据
 */
private void loadMoreData() {

    page++; //重置  在刷新的时候
    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();
                    //mLordDetailDatas.addAll(bean.getResults());
                    detailAdapter.addData(mLordDetailDatas.size(),bean.getResults());
                    detailAdapter.notifyDataSetChanged();
                   // mLordRefresh.autoRefreshLoadMore();
                }
            }, throwable -> {
            });
}
 
Example 29
Source Project: MyHearts   Source File: GroupDetailActivity.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: MyHearts   Source File: UserDetailActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initData() {

    //以下注释的代码是请求网络的数据,但是这个网络的数据请求特别慢,可能他们后台做了手脚(哈哈)
    OkGo.post(HttpUrlPaths.USER_DETAIL_INFO)
            .params("userid", userid)
            .params("cuserid", cuserid)
            .getCall(StringConvert.create(), RxAdapter.<String>create())
            .doOnSubscribe(() -> {
            })
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(s -> {
                        Type type = new TypeToken<UserDetailBean>() {
                        }.getType();
                        UserDetailBean bean = new Gson().fromJson(s, type);
                        if (bean.getErrorCode() == 0
                                && bean.getErrorStr().equals("success")
                                && bean.getResultCount() > 0) {
                            mUserDatas = bean.getResults();

                            updateUi(mUserDatas);
                        }
                    }
                    , throwable -> {
                    });


}