更新时间:2022-12-14 点击:
211
private void initTourPrice() {
OkHttpUtils
.post()
.url(Constants.getTourPriceUrl())
.addParams(“token”, Constants.token)
.addParams(“daynumber”, “1”)
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e, int id) {
//错误
LogUtil.e(TAG, “initTourPrice onError:” + e.getMessage());
ToastUtil.show(getActivity(), “获取团价失败”);
}
@Override
public void onResponse(String response, int id) {
LogUtil.e(TAG, “initTourPrice onResponse:” + response);
//正确
if (response != null) {
try {
JSONObject jsonObject = new JSONObject(response);
int status = jsonObject.optInt(“status”);
if (status == 0) {
JSONObject data = jsonObject.optJSONObject(“data”);
JSONArray jsonArray = data.optJSONArray(“list”);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.optJSONObject(i);
TourPriceBean tourPriceBean = new TourPriceBean();
tourPriceBean.setName(jsonObject1.optString(“name”));
tourPriceBean.setPrice(jsonObject1.optString(“price”));
datas.add(tourPriceBean);
}
mTourPriceAdapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
//获取视频列表
private void getVideoList() {
OkHttpUtils
.post()
.url(Constants.getVideoListUrl())
.addParams(“token”, Constants.token)
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e, int id) {
//错误
LogUtil.e(TAG, “getVideoList onError:” + e.getMessage());
ToastUtil.show(getActivity(), “获取视频列表失败”);
}
@Override
public void onResponse(String response, int id) {
LogUtil.e(TAG, “getVideoList onResponse:” + response);
//正确
if (response != null) {
try {
JSONObject jsonObject = new JSONObject(response);
int status = jsonObject.optInt(“status”);
if (status == 0) {
JSONObject data = jsonObject.optJSONObject(“data”);
JSONArray jsonArray = data.optJSONArray(“list”);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.optJSONObject(i);
VideoBean videoBean = new VideoBean();
videoBean.setVideo_id(jsonObject1.optString(“video_id”));
videoBean.setVideo_name(jsonObject1.optString(“video_name”));
videoBean.setVideo_url(jsonObject1.optString(“video_url”));
videoBean.setVideo_image(jsonObject1.optString(“video_image”));
videoBeans.add(videoBean);
}
mVideoAdapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
//获取资讯
private void getNews() {
OkHttpUtils
.post()
.url(Constants.getNewsListUrl())
.addParams(“token”, Constants.token)
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e, int id) {
//错误
LogUtil.e(TAG, “getNews onError:” + e.getMessage());
ToastUtil.show(getActivity(), “获取资讯失败”);
}
@Override
public void onResponse(String response, int id) {
LogUtil.e(TAG, “getNews onResponse:” + response);
//正确
if (response != null) {
try {
JSONObject jsonObject = new JSONObject(response);
int status = jsonObject.optInt(“status”);
if (status == 0) {
JSONObject data = jsonObject.optJSONObject(“data”);
JSONArray jsonArray = data.optJSONArray(“list”);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.optJSONObject(i);
NewsBean newsBean = new NewsBean();
newsBean.setNews_id(jsonObject1.optString(“news_id”));
newsBean.setNews_title(jsonObject1.optString(“news_title”));
newsBean.setNews_image(jsonObject1.optString(“news_image”));
newsBean.setNews_time(jsonObject1.optString(“news_time”));
newsBeans.add(newsBean);
}
mNewsAdapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
//获取VIP价格
private void initVipPrice() {
OkHttpUtils
.post()
.url(Constants.getVIPPriceUrl())
.addParams(“token”, Constants.token)
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e, int id) {
//错误
LogUtil.e(TAG, “initVipPrice onError:” + e.getMessage());
ToastUtil.show(getActivity(), “获取VIP价格失败”);
}
@Override
public void onResponse(String response, int id) {
LogUtil.e(TAG, “initVipPrice onResponse:” + response);
//正确
if (response != null) {
try {
JSONObject jsonObject = new JSONObject(response);
int status = jsonObject.optInt(“status”);
if (status == 0) {
JSONObject data = jsonObject.optJSONObject(“data”);
JSONArray list = data.optJSONArray(“list”);
for (int i = 0; i < list.length(); i++) {
JSONObject jsonObject1 = list.optJSONObject(i);
VipPriceBean vipPriceBean = new VipPriceBean();
vipPriceBean.setName(jsonObject1.optString(“name”));
vipPriceBean.setPrice(jsonObject1.optString(“price”));
vipPriceBeans.add(vipPriceBean);
}
mVipPriceAdapter.notifyDataSetChanged();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
}