use of com.benmu.framework.utils.MultipleFileDownloader in project WeexErosFramework by bmfe.
the class EventShare method downLoadResource.
private void downLoadResource(final Context context, final RelayBean bean, final int type) {
List<String> urls = bean.getUrls();
if (urls == null || urls.size() < 1) {
if (mFailedCallback != null) {
mFailedCallback.invoke(new BaseResultBean(WeChatRelayUtil.ERROR_ILLEGALARGUMENT, "参数有误"));
}
return;
}
List<String> safeUrls = new ArrayList<>();
for (String url : urls) {
Uri parse = Uri.parse(url);
if (!TextUtils.isEmpty(parse.getScheme()) && !TextUtils.isEmpty(parse.getHost())) {
safeUrls.add(url);
}
}
if (safeUrls.size() < 1) {
if (mFailedCallback != null) {
mFailedCallback.invoke(new BaseResultBean(WeChatRelayUtil.ERROR_ILLEGALARGUMENT, "参数有误"));
}
return;
}
ModalManager.BmLoading.showLoading(context, "资源下载中", false);
new MultipleFileDownloader(FileManager.getTempFilePath(context).getAbsolutePath(), safeUrls).setOnFinshListener(new MultipleFileDownloader.onDownloadFinish() {
@Override
public void onFinish(List<MultipleFileDownloader.FileItem> pathList, List<MultipleFileDownloader.FileItem> errorList) {
ModalManager.BmLoading.dismissLoading(context);
if (pathList.size() < 1) {
if (mFailedCallback != null) {
mFailedCallback.invoke(new BaseResultBean(WeChatRelayUtil.ERROR_DOWNLOAD, "下载失败"));
}
return;
}
List<MultipleFileDownloader.FileItem> files = new ArrayList<>();
if (WeChatRelayUtil.MEDIA_VIDEO.equals(bean.getMediaType())) {
files.add(pathList.get(0));
} else if (WeChatRelayUtil.MEDIA_IMAGE.equals(bean.getMediaType())) {
files.clear();
files.addAll(pathList);
} else {
if (mFailedCallback != null) {
mFailedCallback.invoke(new BaseResultBean(WeChatRelayUtil.ERROR_UNSUPPORT_MT, "不支持的媒体类型"));
}
return;
}
ArrayList<Uri> uris = new ArrayList<Uri>();
for (MultipleFileDownloader.FileItem s : files) {
Uri uri = ResourceUtil.getSafeUri(context, s.getPath(), s.getName());
uris.add(uri);
}
if (ACTION_FRIEND == type) {
WeChatRelayUtil.relayToFriend(context, bean.getDescription(), uris, bean.getMediaType(), mSuccessCallback, mFailedCallback);
} else if (ACTION_CRICLE == type) {
WeChatRelayUtil.relayToCircle(context, bean.getDescription(), uris, bean.getMediaType(), mSuccessCallback, mFailedCallback);
}
}
}).execute();
}
Aggregations