Search in sources :

Example 1 with FileCallBack

use of com.eros.framework.http.okhttp.callback.FileCallBack in project WeexErosFramework by bmfe.

the class VersionChecker method download.

/**
 * 下载包
 */
public void download(final VersionBean version, final boolean complete) {
    try {
        if (version == null) {
            mCurrentStatus = Constant.Version.SLEEP;
            return;
        }
        VersionManager versionManager = ManagerFactory.getManagerService(VersionManager.class);
        versionManager.downloadBundle(version.data.path, new FileCallBack(FileManager.getTempBundleDir(mContext).getAbsolutePath(), version.data.diff ? FileManager.PATCH_NAME : FileManager.TEMP_BUNDLE_NAME) {

            @Override
            public void onError(Call call, Exception e, int id) {
                Log.e(TAG, "下载插分包出错");
                if (!complete) {
                    downloadCompleteZip();
                } else {
                    postFailed("下载全量包失败");
                    mCurrentStatus = Constant.Version.SLEEP;
                }
            }

            @Override
            public void onResponse(File response, int id) {
                Log.e("version", "下载成功" + response.getAbsolutePath());
                if (version.data.diff) {
                    bsPatch();
                } else {
                    File download = new File(FileManager.getTempBundleDir(mContext), FileManager.TEMP_BUNDLE_NAME);
                    if (checkZipValidate(download)) {
                        RenameDeleteFile();
                        // 更改本地jsversion
                        SharePreferenceUtil.setDownLoadVersion(mContext, ManagerFactory.getManagerService(ParseManager.class).toJsonString(newVersion));
                        newVersion = null;
                        mCurrentStatus = Constant.Version.SLEEP;
                        notifyUpdate();
                    } else {
                        L.e(TAG, "更新包md5校验失败,更新失败");
                        FileManager.deleteFile(new File(FileManager.getTempBundleDir(mContext), FileManager.TEMP_BUNDLE_NAME));
                        newVersion = null;
                        mCurrentStatus = Constant.Version.SLEEP;
                        postFailed("更新包md5校验失败,更新失败");
                    }
                }
            }
        });
    } catch (Exception e) {
        mCurrentStatus = Constant.Version.SLEEP;
        e.printStackTrace();
    }
}
Also used : Call(okhttp3.Call) FileCallBack(com.eros.framework.http.okhttp.callback.FileCallBack) VersionManager(com.eros.framework.manager.impl.VersionManager) ParseManager(com.eros.framework.manager.impl.ParseManager) File(java.io.File) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with FileCallBack

use of com.eros.framework.http.okhttp.callback.FileCallBack in project WeexErosFramework by bmfe.

the class MultipleFileDownloader method execute.

public void execute() {
    if (mList == null)
        return;
    AxiosManager axiosManager = ManagerFactory.getManagerService(AxiosManager.class);
    for (final String url : mList) {
        final String fileName = createFileName(url);
        axiosManager.download(url, new FileCallBack(mPath, fileName) {

            @Override
            public void onError(Call call, Exception e, int id) {
                mSize++;
                Log.e("url", "error" + url);
                erros.add(new FileItem(new File(mPath, fileName).getAbsolutePath(), fileName));
                postResult(mSize);
            }

            @Override
            public void onResponse(File response, int id) {
                mSize++;
                Log.e("url", url);
                paths.add(new FileItem(new File(mPath, fileName).getAbsolutePath(), fileName));
                postResult(mSize);
            }
        });
    }
}
Also used : Call(okhttp3.Call) AxiosManager(com.eros.framework.manager.impl.AxiosManager) FileCallBack(com.eros.framework.http.okhttp.callback.FileCallBack) File(java.io.File)

Aggregations

FileCallBack (com.eros.framework.http.okhttp.callback.FileCallBack)2 File (java.io.File)2 Call (okhttp3.Call)2 AxiosManager (com.eros.framework.manager.impl.AxiosManager)1 ParseManager (com.eros.framework.manager.impl.ParseManager)1 VersionManager (com.eros.framework.manager.impl.VersionManager)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1