use of com.zhy.http.okhttp.callback.StringCallback in project Mvp-Rxjava-Retrofit-dagger2 by pengMaster.
the class LoginUtils method initDeviceValid.
/**
* @param isTestIn true 测试入口的回调
* 验证设备是否有效:
* 过期/不可用 0
* 即将过期 1
*/
public LoginUtils initDeviceValid(LoadMode isTestIn, final Context context, String type) {
if (isTestIn == LoadMode.TEST && onInitDeviceValidCallListener != null) {
onInitDeviceValidCallListener.onTestIn();
return instance;
}
if (isAvilible("com.mtm.launcher2", "com.mtm.launcher3")) {
StringBuilder sb = new StringBuilder();
String deviceId = Md5Util.getMD5Str(getDeviceId());
final int[] versionCode = { getAppVersionCode() };
sb.append("http://60.247.49.230:7001/mtmdp/");
// .append("type=").append(appName).append("&imei=").append(deviceId);
sb.append("scjAction!getNewVersion.do?");
OkHttpUtils.post().url(sb.toString()).addParams("type", type).addParams("imei", deviceId).build().execute(new StringCallback() {
@Override
public void onError(com.squareup.okhttp.Request request, Exception e) {
if (onInitDeviceValidCallListener != null) {
if ("0".equals(SPUtils.i("deviceValid").getStringData("isDeviceValid", ""))) {
PopupWindow.showInfoDialog(context, "提示", "该设备服务不可用,请联系'系统服务商'.");
onInitDeviceValidCallListener.onError();
} else {
onInitDeviceValidCallListener.onResponse(0);
}
}
e.printStackTrace();
}
@Override
public void onResponse(String response) {
if (!TextUtils.isEmpty(response)) {
switch(response.trim().replaceAll("\r", "").replaceAll("\n", "")) {
case "/Exception":
case "/noApp":
case "/noDevice":
case // 过期/不可用
"/noUsed":
PopupWindow.showInfoDialog(context, "提示", "该设备服务不可用,请联系'系统服务商'.");
versionCode[0] = 0;
// 无效
SPUtils.i("deviceValid").saveStringData("isDeviceValid", "0");
break;
case // 即将过期
"/Warning":
versionCode[0] = 1;
new AlertDialog.Builder(context).setTitle("提示").setMessage("该设备服务即将过期,请联系'系统服务商'.").setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
if (onInitDeviceValidCallListener != null) {
onInitDeviceValidCallListener.onResponse(versionCode[0]);
}
}
}).show();
// 即将过期
SPUtils.i("deviceValid").saveStringData("isDeviceValid", "2");
return;
default:
InternalVersionBean internalVersionBean = new Gson().fromJson(response, InternalVersionBean.class);
if (internalVersionBean != null && !TextUtils.isEmpty(internalVersionBean.getInternalVersion())) {
versionCode[0] = Integer.valueOf(internalVersionBean.getInternalVersion());
// 有效
SPUtils.i("deviceValid").saveStringData("isDeviceValid", "1");
}
break;
}
}
if (onInitDeviceValidCallListener != null) {
if (versionCode[0] == 0 || "0".equals(SPUtils.i("deviceValid").getStringData("isDeviceValid", ""))) {
// 无效
PopupWindow.showInfoDialog(context, "提示", "该设备服务不可用,请联系'系统服务商'.");
onInitDeviceValidCallListener.onError();
} else {
onInitDeviceValidCallListener.onResponse(versionCode[0]);
}
}
}
});
} else {
ThreadUtils.runInMainThread(new Runnable() {
@Override
public void run() {
PopupWindow.showInfoDialog(context, "提示", "请安装安全认证中心后重试!");
}
});
}
return instance;
}
use of com.zhy.http.okhttp.callback.StringCallback in project DMGameApp by xiaohaibin.
the class GetForumListPresenter method getForumListData.
@Override
public void getForumListData(String fid) {
OkHttpUtils.postString().content(GsonUtil.newGson().toJson(new ForumContentEntity(fid, "forums"))).url(API.USER_API).build().execute(new StringCallback() {
@Override
public void onBefore(Request request, int id) {
getView().showLoading();
}
@Override
public void onError(Call call, Exception e, int id) {
getView().getForumListDataFailed(e.getMessage());
}
@Override
public void onResponse(String response, int id) {
if (!TextUtils.isEmpty(response)) {
try {
JsonResponse jsonResponse = new JsonResponse(new JSONObject(response));
if (jsonResponse.isSuccess()) {
List<ForumBean> dataList = new ArrayList<>();
JSONArray array = jsonResponse.getDataList();
JSONObject object = jsonResponse.getObject();
if (array != null && object != null) {
for (int i = 0; i < array.length(); i++) {
ForumBean forumBean = new ForumBean();
JSONObject jsonObject = object.getJSONObject(array.getString(i));
forumBean.setFid(jsonObject.getString("fid"));
forumBean.setName(jsonObject.getString("name"));
forumBean.setTodayposts(jsonObject.getString("todayposts"));
forumBean.setRank(jsonObject.getString("rank"));
forumBean.setType(jsonObject.getString("type"));
forumBean.setIcon(jsonObject.getString("icon"));
dataList.add(forumBean);
}
getView().getForumListDataSuccess(dataList);
} else {
getView().hideLoading();
getView().getForumListDataFailed(jsonResponse.getMsg());
}
} else {
getView().hideLoading();
getView().getForumListDataFailed(jsonResponse.getMsg());
}
} catch (JSONException e) {
getView().hideLoading();
getView().getForumListDataFailed(e.getMessage());
}
}
}
@Override
public void onAfter(int id) {
getView().hideLoading();
}
});
}
use of com.zhy.http.okhttp.callback.StringCallback in project GzuClassSchedule by mnnyang.
the class VersionUpdate method checkUpdate.
public void checkUpdate(final HttpCallback<Version> callback) {
OkHttpUtils.get().url(Url.URL_CHECK_UPDATE_APP).build().execute(new StringCallback() {
@Override
public void onError(Call call, Exception e, int id) {
e.printStackTrace();
callback.onFail(e.getMessage());
}
@Override
public void onResponse(String response, int id) {
try {
Gson gson = new Gson();
Version version = gson.fromJson(response, Version.class);
callback.onSuccess(version);
} catch (Exception e) {
e.printStackTrace();
callback.onFail("parse error");
}
}
});
}
use of com.zhy.http.okhttp.callback.StringCallback in project GzuClassSchedule by mnnyang.
the class HttpUtils method toImpt.
/**
* @param xh
* @param courseTime 格式: 2017-2018
* @param term 学期num
* @param callback
*/
public void toImpt(String xh, String courseTime, String term, final HttpCallback<String> callback) {
LogUtil.d("toImpt", "xh" + xh + "c" + courseTime + "t" + term);
OkHttpUtils.post().url(Url.URL_LOAD_COURSE + "?xh=" + xh + "&xm=%D1%EE%D3%D1%C1%D6&gnmkdm=N121603").addHeader("Referer", Url.URL_LOAD_COURSE + "?xh=" + xh + "&xm=%D1%EE%D3%D1%C1%D6&gnmkdm=N121603").addHeader("Connection", "keep-alive").addParams("__EVENTTARGET", "xnd").addParams("__EVENTARGUMENT", "").addParams("__VIEWSTATE", Url.VIEWSTATE_POST_CODE).addParams(Url.PARAM_XND, courseTime).addParams(Url.PARAM_XQD, term).build().execute(new StringCallback() {
@Override
public void onError(Call call, Exception e, int id) {
e.printStackTrace();
callback.onFail(ACCESS_ERR);
}
@Override
public void onResponse(String response, int id) {
Url.VIEWSTATE_POST_CODE = ParseCourse.parseViewStateCode(response);
callback.onSuccess(response);
}
});
}
Aggregations