|
@@ -49,6 +49,7 @@ import com.cooleshow.base.constanst.StyleConfig;
|
|
import com.cooleshow.base.data.net.RetrofitClientNoToken;
|
|
import com.cooleshow.base.data.net.RetrofitClientNoToken;
|
|
import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
import com.cooleshow.base.utils.AppUtils;
|
|
import com.cooleshow.base.utils.AppUtils;
|
|
|
|
+import com.cooleshow.base.utils.ClipboardUtils;
|
|
import com.cooleshow.base.utils.LOG;
|
|
import com.cooleshow.base.utils.LOG;
|
|
import com.cooleshow.base.utils.PermissionUtils;
|
|
import com.cooleshow.base.utils.PermissionUtils;
|
|
import com.cooleshow.base.utils.ToastUtil;
|
|
import com.cooleshow.base.utils.ToastUtil;
|
|
@@ -58,6 +59,7 @@ import com.cooleshow.base.utils.helper.GlideEngine;
|
|
import com.cooleshow.base.utils.helper.LogUploadManager;
|
|
import com.cooleshow.base.utils.helper.LogUploadManager;
|
|
import com.cooleshow.base.utils.helper.PermissionTipHelper;
|
|
import com.cooleshow.base.utils.helper.PermissionTipHelper;
|
|
import com.cooleshow.base.widgets.DialogUtil;
|
|
import com.cooleshow.base.widgets.DialogUtil;
|
|
|
|
+import com.cooleshow.base.widgets.dialog.DownloadFileTipDialog;
|
|
import com.cooleshow.teacher.R;
|
|
import com.cooleshow.teacher.R;
|
|
import com.cooleshow.teacher.api.APIService;
|
|
import com.cooleshow.teacher.api.APIService;
|
|
import com.cooleshow.teacher.bean.alipay.AuthResult;
|
|
import com.cooleshow.teacher.bean.alipay.AuthResult;
|
|
@@ -309,9 +311,12 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
|
|
downloadFile(url);
|
|
downloadFile(url);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+ public void downloadFile(String url) {
|
|
|
|
+ downloadFile(url,"");
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void downloadFile(String url) {
|
|
|
|
|
|
+ public void downloadFile(String url,String fileName) {
|
|
if (TextUtils.isEmpty(url)) {
|
|
if (TextUtils.isEmpty(url)) {
|
|
ToastUtil.getInstance().showShort("文件异常");
|
|
ToastUtil.getInstance().showShort("文件异常");
|
|
return;
|
|
return;
|
|
@@ -331,7 +336,14 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
String path = MyFileUtils.getPublicDirectory("file");
|
|
String path = MyFileUtils.getPublicDirectory("file");
|
|
- String name = "FILE_" + new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date()) + "." + type;
|
|
|
|
|
|
+ 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);
|
|
upDateNewsVideoFile(path, name, url, type);
|
|
} else {
|
|
} else {
|
|
String type = MyFileUtils.getBase64Type(url.split(",")[0]);
|
|
String type = MyFileUtils.getBase64Type(url.split(",")[0]);
|
|
@@ -705,7 +717,7 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
|
|
|
|
|
|
|
|
|
|
private void upDateNewsVideoFile(String filePath, String fileName, String url, String type) {
|
|
private void upDateNewsVideoFile(String filePath, String fileName, String url, String type) {
|
|
-// showUploadLoading("下载中");
|
|
|
|
|
|
+ showLoading("下载中");
|
|
RetrofitClientNoToken.getInstance().getRetrofit().create(APIService.class)
|
|
RetrofitClientNoToken.getInstance().getRetrofit().create(APIService.class)
|
|
.downloadFileWithFixedUrl(url)
|
|
.downloadFileWithFixedUrl(url)
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
@@ -729,28 +741,10 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
onSendMessage(jsonObject.toString());
|
|
onSendMessage(jsonObject.toString());
|
|
- getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(filePath + File.separator + fileName))));
|
|
|
|
- DialogUtil.showInCenter(getParentFragmentManager(), 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(getContext(), 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);
|
|
|
|
+ getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
|
|
|
|
+ String tip = "文件已保存到以下地址\n" + file.getAbsolutePath();
|
|
|
|
+ showDownloadTipDialog(file.getAbsolutePath(), "下载成功", tip);
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
runOnUiThread(() -> {
|
|
runOnUiThread(() -> {
|
|
@@ -789,6 +783,37 @@ public class MallFragment extends BaseMVPFragment<FragmentMallBinding, ShopMallP
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void showDownloadTipDialog(String filePath, String title, String content) {
|
|
|
|
+ if (UiUtils.isFastClick()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ DownloadFileTipDialog dialog = new DownloadFileTipDialog(getContext());
|
|
|
|
+ dialog.show();
|
|
|
|
+ dialog.setData(title,content);
|
|
|
|
+ dialog.setOnEventListener(new DownloadFileTipDialog.OnEventListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onConfirmClick() {
|
|
|
|
+ try {
|
|
|
|
+ Intent intent = MyFileUtils.startIntent(getContext().getApplicationContext(), filePath);
|
|
|
|
+ if (intent != null) {
|
|
|
|
+ startActivity(intent);
|
|
|
|
+ } else {
|
|
|
|
+ ToastUtil.getInstance().show(getContext().getApplicationContext(), "打开失败");
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ LOG.e(e.toString());
|
|
|
|
+ ToastUtil.getInstance().show(getContext().getApplicationContext(), "打开失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onCopy() {
|
|
|
|
+ ClipboardUtils.copyText(filePath);
|
|
|
|
+ ToastUtil.getInstance().showShort("复制成功");
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
//android获取一个用于打开PDF文件的intent
|
|
//android获取一个用于打开PDF文件的intent
|
|
public static Intent getPdfFileIntent(String Path) {
|
|
public static Intent getPdfFileIntent(String Path) {
|
|
File file = new File(Path);
|
|
File file = new File(Path);
|