Search in sources :

Example 1 with InternalVersionBean

use of com.mtm.mrecord.mvp.model.entity.InternalVersionBean 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;
}
Also used : DialogInterface(android.content.DialogInterface) StringCallback(com.zhy.http.okhttp.callback.StringCallback) Gson(com.google.gson.Gson) InternalVersionBean(com.mtm.mrecord.mvp.model.entity.InternalVersionBean)

Aggregations

DialogInterface (android.content.DialogInterface)1 Gson (com.google.gson.Gson)1 InternalVersionBean (com.mtm.mrecord.mvp.model.entity.InternalVersionBean)1 StringCallback (com.zhy.http.okhttp.callback.StringCallback)1