|
@@ -47,6 +47,7 @@ import com.alipay.sdk.app.PayTask;
|
|
|
import com.cooleshow.base.BuildConfig;
|
|
|
import com.cooleshow.base.bean.DownloadTaskBean;
|
|
|
import com.cooleshow.base.bean.WxPayResult;
|
|
|
+import com.cooleshow.base.common.WebApi;
|
|
|
import com.cooleshow.base.common.WebConstants;
|
|
|
import com.cooleshow.base.constanst.Constants;
|
|
|
import com.cooleshow.base.constanst.UploadConstants;
|
|
@@ -74,6 +75,7 @@ import com.cooleshow.base.utils.helper.DownloadHelper;
|
|
|
import com.cooleshow.base.utils.helper.GlideEngine;
|
|
|
import com.cooleshow.base.utils.helper.PermissionTipHelper;
|
|
|
import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
|
|
|
+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;
|
|
@@ -165,6 +167,7 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
private boolean isNeedResetScreenOrientation = true;
|
|
|
private boolean isResetOrientation = false;
|
|
|
private DownloadHelper.OnEventListener mEventListener;
|
|
|
+ private DownloadHelper.OnEventListener saveFileListener;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
@@ -455,7 +458,7 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
ArrayList<DownloadTaskBean> downloadTaskBeans = new ArrayList<>();
|
|
|
downloadTaskBeans.add(downloadTaskBean);
|
|
|
showLoading("保存中:0%");
|
|
|
- DownloadHelper.getInstance().startDownload(key, downloadTaskBeans, getDownloadEventListener());
|
|
|
+ DownloadHelper.getInstance().startDownload(key, downloadTaskBeans, getSaveFileDownloadEventListener());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -464,6 +467,58 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
mEventListener = new DownloadHelper.OnEventListener() {
|
|
|
@Override
|
|
|
public void onProgress(String id, int progress) {
|
|
|
+ if (webView != null) {
|
|
|
+ webView.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ int downloadStatus = DownloadHelper.DOWNLOAD_STATUS_CALLBACK_ING;
|
|
|
+ if (progress >= 100) {
|
|
|
+ downloadStatus = DownloadHelper.DOWNLOAD_STATUS_CALLBACK_COMPLETE;
|
|
|
+ }
|
|
|
+ sendDownloadCoursewareProgress(progress, id, downloadStatus);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downloadError(String id) {
|
|
|
+ if (webView != null) {
|
|
|
+ webView.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ sendDownloadCoursewareProgress(0, id, DownloadHelper.DOWNLOAD_STATUS_CALLBACK_ERROR);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downloadCancel(String id) {
|
|
|
+ if (webView != null) {
|
|
|
+ webView.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ sendDownloadCoursewareProgress(0, id, DownloadHelper.DOWNLOAD_STATUS_CALLBACK_CANCEL);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onComplete(String id) {
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return mEventListener;
|
|
|
+ }
|
|
|
+
|
|
|
+ private DownloadHelper.OnEventListener getSaveFileDownloadEventListener() {
|
|
|
+ if (saveFileListener == null) {
|
|
|
+ saveFileListener = new DownloadHelper.OnEventListener() {
|
|
|
+ @Override
|
|
|
+ public void onProgress(String id, int progress) {
|
|
|
Log.i("pq", "html Download:" + progress);
|
|
|
if (webView != null) {
|
|
|
webView.post(new Runnable() {
|
|
@@ -489,6 +544,11 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void downloadCancel(String id) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void onComplete(String filePath) {
|
|
|
Log.i("pq", "download onComplete:" + filePath);
|
|
|
if (webView != null) {
|
|
@@ -511,7 +571,7 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
- return mEventListener;
|
|
|
+ return saveFileListener;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -1505,6 +1565,12 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
if (null != webView) {
|
|
|
webView.destroy();
|
|
|
}
|
|
|
+ if (mEventListener != null) {
|
|
|
+ mEventListener = null;
|
|
|
+ }
|
|
|
+ if (saveFileListener != null) {
|
|
|
+ saveFileListener = null;
|
|
|
+ }
|
|
|
EventBus.getDefault().unregister(this);
|
|
|
if (UserHelper.isAgreePrivacy()) {
|
|
|
UMShareAPI.get(HtmlActivity.this).release();
|
|
@@ -1560,6 +1626,90 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void checkCoursewareCache(JSONObject jsonObject) {
|
|
|
+ String [] permissions = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};
|
|
|
+ PermissionTipHelper.getInstance().showTipDialog(this,permissions);
|
|
|
+ new RxPermissions(this)
|
|
|
+ .request(permissions)
|
|
|
+ .subscribe(permission -> {
|
|
|
+ PermissionTipHelper.getInstance().dismissDialog();
|
|
|
+ if (permission) {
|
|
|
+ JSONObject jsonObject1 = WebLoadFileHelper.getInstance().checkCacheStatus(jsonObject);
|
|
|
+ onSendMessage(jsonObject1.toString());
|
|
|
+ replaceDownloadCallBackIfOnDownloading();
|
|
|
+ } else {
|
|
|
+ onSendMessage(jsonObject.toString());
|
|
|
+ UiUtils.showPermissionTipDialog(getSupportFragmentManager(), this, "提示", "缓存需要开启存储权限,去设置?");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 一次只能下载一个,如果有任务则替换当前callback
|
|
|
+ */
|
|
|
+ private void replaceDownloadCallBackIfOnDownloading() {
|
|
|
+ int size = DownloadHelper.getInstance().getDownloadTaskInfos().size();
|
|
|
+ if (size != 0) {
|
|
|
+ DownloadHelper.getInstance().replaceCallBack(getDownloadEventListener());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downloadCourseware(String data) {
|
|
|
+ if (!checkActivityExist()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String [] permissions = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};
|
|
|
+ PermissionTipHelper.getInstance().showTipDialog(this,permissions);
|
|
|
+ new RxPermissions(this)
|
|
|
+ .request(permissions)
|
|
|
+ .subscribe(permission -> {
|
|
|
+ PermissionTipHelper.getInstance().dismissDialog();
|
|
|
+ if (permission) {
|
|
|
+ boolean isWifi = NetworkUtil.isWifiNetwork(HtmlActivity.this);
|
|
|
+ if (isWifi) {
|
|
|
+ WebLoadFileHelper.getInstance().toDownload(data, getDownloadEventListener());
|
|
|
+ } else {
|
|
|
+ showWifiTipDialog(data);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ UiUtils.showPermissionTipDialog(getSupportFragmentManager(), this, "提示", "下载需要开启存储权限,去设置?");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showWifiTipDialog(String data) {
|
|
|
+ CommonConfirmDialog2 commonDialog2 = new CommonConfirmDialog2(this);
|
|
|
+ commonDialog2.show();
|
|
|
+ commonDialog2.setTitle("提示");
|
|
|
+ commonDialog2.setContent("当前非Wifi网络,确认下载?");
|
|
|
+ commonDialog2.setOnConfirmClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ commonDialog2.dismiss();
|
|
|
+ WebLoadFileHelper.getInstance().toDownload(data, getDownloadEventListener());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendDownloadCoursewareProgress(int progress, String id, int downloadStatus) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ JSONObject contentJson = new JSONObject();
|
|
|
+ try {
|
|
|
+ jsonObject.put("api", WebApi.DOWNLOAD_COURSEWARE_TO_CACHE);
|
|
|
+ contentJson.put("lessonCoursewareDetailId", id);
|
|
|
+ contentJson.put("progress", progress);
|
|
|
+ Log.i("pq", "下载lessonCoursewareDetailId:" + id);
|
|
|
+ Log.i("pq", "下载进度:" + progress);
|
|
|
+ contentJson.put("downloadStatus", downloadStatus);
|
|
|
+ jsonObject.put("content", contentJson);
|
|
|
+ onSendMessage(jsonObject.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
if (webView.canGoBack()) {
|