Search in sources :

Example 1 with VersionBean

use of com.eros.framework.model.VersionBean in project WeexErosFramework by bmfe.

the class VersionChecker method downloadCompleteZip.

/**
 * 下载全量包
 */
private void downloadCompleteZip() {
    VersionManager versionManager = ManagerFactory.getManagerService(VersionManager.class);
    versionManager.checkBundleUpdate(mContext, mUpdateUrl, false, new StringCallback() {

        @Override
        public void onError(Call call, Exception e, int id) {
            L.e(TAG, "检查全量包失败!,更新失败");
            mCurrentStatus = Constant.Version.SLEEP;
            postFailed("检查全量包失败!,更新失败");
        }

        @Override
        public void onResponse(String response, int id) {
            VersionBean version = ManagerFactory.getManagerService(ParseManager.class).parseObject(response, VersionBean.class);
            if (version != null && !TextUtils.isEmpty(version.data.path)) {
                L.e(TAG, "检查全量包成功!,开始下载");
                download(version, true);
            }
        }
    });
}
Also used : Call(okhttp3.Call) StringCallback(com.eros.framework.http.okhttp.callback.StringCallback) VersionManager(com.eros.framework.manager.impl.VersionManager) VersionBean(com.eros.framework.model.VersionBean) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with VersionBean

use of com.eros.framework.model.VersionBean in project WeexErosFramework by bmfe.

the class VersionChecker method readyUpdate.

private void readyUpdate(String path, boolean diff) {
    mUpdateUrl = BMWXEnvironment.mPlatformConfig.getUrl().getBundleUpdate();
    if (!TextUtils.isEmpty(path)) {
        mUpdateUrl = path;
    }
    if (TextUtils.isEmpty(mUpdateUrl))
        return;
    if (Constant.INTERCEPTOR_ACTIVE.equals(SharePreferenceUtil.getInterceptorActive(mContext))) {
        mCurrentStatus = Constant.Version.UPDATING;
        VersionManager versionManager = ManagerFactory.getManagerService(VersionManager.class);
        versionManager.checkBundleUpdate(mContext, mUpdateUrl, diff, new StringCallback() {

            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e(TAG, "获取更新失败");
                postFailed("获取更新失败");
                mCurrentStatus = Constant.Version.SLEEP;
            }

            @Override
            public void onResponse(String response, int id) {
                VersionBean version = ManagerFactory.getManagerService(ParseManager.class).parseObject(response, VersionBean.class);
                if (version == null) {
                    Log.e(TAG, "返回结果异常");
                    postFailed("返回结果异常");
                    mCurrentStatus = Constant.Version.SLEEP;
                    return;
                }
                switch(version.resCode) {
                    case // 需要更新
                    0:
                        if (!TextUtils.isEmpty(version.data.path)) {
                            if (version.data.diff) {
                                // 更新插分包
                                Log.e(TAG, "检查插分包");
                                download(version, false);
                            } else {
                                // 下载全量包
                                Log.e(TAG, "检查全量包");
                                downloadCompleteZip();
                            }
                        } else {
                            // 下载全量包
                            Log.e(TAG, "检查全量包");
                            downloadCompleteZip();
                        }
                        break;
                    case 401:
                        Log.e(TAG, "JS文件查询失败!");
                        postFailed("JS文件查询失败");
                        mCurrentStatus = Constant.Version.SLEEP;
                        break;
                    case 4000:
                        Log.e(TAG, "当前版本已是最新!");
                        postFailed("当前版本已是最新");
                        mCurrentStatus = Constant.Version.SLEEP;
                        break;
                    default:
                        Log.e(TAG, "resCode:" + version.resCode);
                        postFailed("resCode:" + version.resCode);
                        mCurrentStatus = Constant.Version.SLEEP;
                        break;
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) StringCallback(com.eros.framework.http.okhttp.callback.StringCallback) VersionManager(com.eros.framework.manager.impl.VersionManager) VersionBean(com.eros.framework.model.VersionBean) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

StringCallback (com.eros.framework.http.okhttp.callback.StringCallback)2 VersionManager (com.eros.framework.manager.impl.VersionManager)2 VersionBean (com.eros.framework.model.VersionBean)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Call (okhttp3.Call)2