|
@@ -87,6 +87,7 @@ import com.cooleshow.base.utils.helper.WebLoadFileHelper;
|
|
|
import com.cooleshow.base.utils.helper.upload.UploadHelper;
|
|
|
import com.cooleshow.base.widgets.DialogUtil;
|
|
|
import com.cooleshow.base.widgets.dialog.CommonConfirmDialog2;
|
|
|
+import com.cooleshow.base.widgets.dialog.DownloadFileTipDialog;
|
|
|
import com.cooleshow.chatmodule.constants.TCChatRouterPath;
|
|
|
import com.cooleshow.chatmodule.utils.helper.ChatHelper;
|
|
|
import com.cooleshow.student.App;
|
|
@@ -407,13 +408,18 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public void downloadFile(String url) {
|
|
|
+ downloadFile(url, "");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downloadFile(String url, String fileName) {
|
|
|
if (TextUtils.isEmpty(url)) {
|
|
|
ToastUtil.getInstance().showShort("文件异常");
|
|
|
return;
|
|
|
}
|
|
|
- String[] permissions = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
|
|
+ String[] permissions = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.READ_EXTERNAL_STORAGE};
|
|
|
PermissionTipHelper.getInstance().showTipDialog(this, permissions);
|
|
|
new RxPermissions(this)
|
|
|
.request(permissions)
|
|
@@ -427,8 +433,15 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
ToastUtil.getInstance().showShort("文件异常");
|
|
|
return;
|
|
|
}
|
|
|
- String path = MyFileUtils.getPublicDirectory("file");
|
|
|
- String name = "FILE_" + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()) + "." + type;
|
|
|
+ String path = MyFileUtils.getPublicDirectoryDownload();
|
|
|
+ String name;
|
|
|
+ if (TextUtils.isEmpty(fileName)) {
|
|
|
+ name = "FILE_" + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()) + "." + type;
|
|
|
+ } else {
|
|
|
+ long timeStamp = System.currentTimeMillis();
|
|
|
+ name = timeStamp + "_" + fileName + "." + type;
|
|
|
+ }
|
|
|
+ LOG.e(path + name);
|
|
|
upDateNewsVideoFile(path, name, url, type);
|
|
|
} else {
|
|
|
String type = MyFileUtils.getBase64Type(url.split(",")[0]);
|
|
@@ -877,7 +890,7 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
|
|
|
|
|
|
private void upDateNewsVideoFile(String filePath, String fileName, String url, String type) {
|
|
|
-// showUploadLoading("下载中");
|
|
|
+ showLoading("下载中");
|
|
|
RetrofitClientNoToken.getInstance().getRetrofit().create(APIService.class)
|
|
|
.downloadFileWithFixedUrl(url)
|
|
|
.subscribeOn(Schedulers.io())
|
|
@@ -901,28 +914,10 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
onSendMessage(jsonObject.toString());
|
|
|
- sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(filePath + File.separator + fileName))));
|
|
|
- DialogUtil.showInCenter(getSupportFragmentManager(), com.cooleshow.base.R.layout.common_popu, "提示", "保存成功,文件保存位置:" + filePath + File.separator + fileName + ";是否打开?", new DialogUtil.OnDialogButtonClickListener() {
|
|
|
- @Override
|
|
|
- public void onCancel(View v) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onCommit(View v) {
|
|
|
- try {
|
|
|
- Intent intent = MyFileUtils.startIntent(getApplicationContext(), filePath + File.separator + fileName);
|
|
|
- if (intent != null) {
|
|
|
- startActivity(intent);
|
|
|
- } else {
|
|
|
- ToastUtil.getInstance().showShort("打开失败");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- ToastUtil.getInstance().showShort("打开失败");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
+ File file = new File(filePath + File.separator + fileName);
|
|
|
+ sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
|
|
|
+ String tip = "文件已保存到以下地址\n" + file.getAbsolutePath();
|
|
|
+ showDownloadTipDialog(file.getAbsolutePath(), "下载成功", tip);
|
|
|
});
|
|
|
} else {
|
|
|
runOnUiThread(() -> {
|
|
@@ -961,6 +956,38 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void showDownloadTipDialog(String filePath, String title, String content) {
|
|
|
+ if (UiUtils.isFastClick()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DownloadFileTipDialog dialog = new DownloadFileTipDialog(this);
|
|
|
+ dialog.show();
|
|
|
+ dialog.setData(title,content);
|
|
|
+ dialog.handleTitleBg(UserHelper.isTenantAccount());
|
|
|
+ dialog.setOnEventListener(new DownloadFileTipDialog.OnEventListener() {
|
|
|
+ @Override
|
|
|
+ public void onConfirmClick() {
|
|
|
+ try {
|
|
|
+ Intent intent = MyFileUtils.startIntent(getApplicationContext(), filePath);
|
|
|
+ if (intent != null) {
|
|
|
+ startActivity(intent);
|
|
|
+ } else {
|
|
|
+ ToastUtil.getInstance().show(getApplicationContext(), "打开失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.e(e.toString());
|
|
|
+ ToastUtil.getInstance().show(getApplicationContext(), "打开失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCopy() {
|
|
|
+ ClipboardUtils.copyText(filePath);
|
|
|
+ ToastUtil.getInstance().showShort("复制成功");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void saveFile(JSONObject jsonObject) {
|
|
@@ -1232,7 +1259,7 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
if (error.getErrorCode() == WebViewClient.ERROR_HOST_LOOKUP || error.getErrorCode() == WebViewClient.ERROR_CONNECT) {
|
|
|
showLoadErrorView();
|
|
|
} else {
|
|
|
- if(error.getErrorCode() == WebViewClient.ERROR_UNKNOWN){
|
|
|
+ if (error.getErrorCode() == WebViewClient.ERROR_UNKNOWN) {
|
|
|
return;
|
|
|
}
|
|
|
String errorMsg = "url:" + request.getUrl().toString() + " " + error.getDescription();
|