|
|
@@ -7,10 +7,18 @@ import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
import android.webkit.JavascriptInterface;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.liulishuo.okdownload.DownloadTask;
|
|
|
+import com.liulishuo.okdownload.OkDownload;
|
|
|
+import com.liulishuo.okdownload.StatusUtil;
|
|
|
import com.sheep.gamegroup.absBase.AbsObserver;
|
|
|
+import com.sheep.gamegroup.event.BigEvent;
|
|
|
+import com.sheep.gamegroup.event.EventTypes;
|
|
|
+import com.sheep.gamegroup.greendao.download.DownLoadInfo;
|
|
|
import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.DialogConfig;
|
|
|
+import com.sheep.gamegroup.model.entity.TaskEty;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.gamegroup.module.find.activity.ActFind;
|
|
|
import com.sheep.gamegroup.module.user.activity.ActVip;
|
|
|
@@ -22,18 +30,21 @@ import com.sheep.gamegroup.util.CommonUtil;
|
|
|
import com.sheep.gamegroup.util.ContactUtil;
|
|
|
import com.sheep.gamegroup.util.DataUtil;
|
|
|
import com.sheep.gamegroup.util.DeviceUtil;
|
|
|
+import com.sheep.gamegroup.util.DownloadUtil;
|
|
|
import com.sheep.gamegroup.util.Jump2View;
|
|
|
import com.sheep.gamegroup.util.LogUtil;
|
|
|
import com.sheep.gamegroup.util.MainTab;
|
|
|
import com.sheep.gamegroup.util.QQUtil;
|
|
|
import com.sheep.gamegroup.util.SMSUtil;
|
|
|
import com.sheep.gamegroup.util.SysAppUtil;
|
|
|
+import com.sheep.gamegroup.util.UMConfigUtils;
|
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
|
import com.sheep.gamegroup.util.share.ShareLinkConfig;
|
|
|
import com.sheep.gamegroup.view.activity.ActInvitation;
|
|
|
import com.sheep.gamegroup.view.activity.ActMain;
|
|
|
import com.sheep.gamegroup.view.activity.ChangeWxOrTelAct;
|
|
|
import com.sheep.gamegroup.view.activity.RealNameAuthenAct;
|
|
|
+import com.sheep.gamegroup.view.activity.TaskDetailAct;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
@@ -41,6 +52,8 @@ import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
+
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
|
|
|
@@ -418,4 +431,82 @@ public class KFZSJs {
|
|
|
public void getAllCallLog() {
|
|
|
SMSUtil.getCallLog(result -> activity.loadJs(String.format(Locale.CHINA, "onGetAllCallLog('%s')", result)));
|
|
|
}
|
|
|
+ @JavascriptInterface
|
|
|
+ public void updateDownloadBtn(String taskJson) {
|
|
|
+ new Thread(() -> {
|
|
|
+ TaskEty taskEty = JSON.parseObject(taskJson, TaskEty.class);
|
|
|
+ updateDownloadBtn(taskEty);
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+ public void updateDownloadBtn(TaskEty taskEty) {
|
|
|
+ if(downloadUtil == null)
|
|
|
+ downloadUtil = new DownloadUtil();
|
|
|
+ TaskDetailAct.setBtnStr(taskEty, downloadUtil, object -> activity.runOnUiThread(() -> {
|
|
|
+// String params = object.toString();
|
|
|
+// if (object instanceof Integer) {
|
|
|
+// activity.loadJs(String.format(Locale.CHINA, "onUpdateDownloadBtnType('%s')", params));
|
|
|
+// } else if (object instanceof String) {
|
|
|
+// activity.loadJs(String.format(Locale.CHINA, "onUpdateDownloadBtnText('%s')", params));
|
|
|
+// } else if (object instanceof Boolean) {
|
|
|
+// activity.loadJs(String.format(Locale.CHINA, "onUpdateDownloadBtnEnable('%s')", params));
|
|
|
+// }
|
|
|
+ if (object instanceof Integer) {
|
|
|
+ activity.loadJs(String.format(Locale.CHINA, "onUpdateDownloadBtnType(%d)", (int)object));
|
|
|
+ } else if (object instanceof String) {
|
|
|
+ activity.loadJs(String.format(Locale.CHINA, "onUpdateDownloadBtnText('%s')", (String)object));
|
|
|
+ } else if (object instanceof Boolean) {
|
|
|
+ activity.loadJs(String.format(Locale.CHINA, "onUpdateDownloadBtnEnable(%b)", (boolean)object));
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ private DownloadUtil downloadUtil;
|
|
|
+ @JavascriptInterface
|
|
|
+ public void downloadApk(String taskJson) {
|
|
|
+ new Thread(() -> {
|
|
|
+ TaskEty taskEty = JSON.parseObject(taskJson, TaskEty.class);
|
|
|
+ downloadApk(taskEty);
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+ private void downloadApk(TaskEty taskEty){
|
|
|
+ if(downloadUtil == null)
|
|
|
+ downloadUtil = new DownloadUtil();
|
|
|
+
|
|
|
+ final DownloadTask task;
|
|
|
+ if (TextUtils.isEmpty(taskEty.getDownload_link()) || !taskEty.getDownload_link().contains("http")) {
|
|
|
+ G.showToast(R.string.error_download_link);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ task = DownloadUtil.getTask(taskEty);
|
|
|
+ final StatusUtil.Status statusOnStore = StatusUtil.getStatus(task);
|
|
|
+ final DownLoadInfo downLoadInfo = downloadUtil.getDownloadTaskByUrl(taskEty);
|
|
|
+ switch (statusOnStore) {
|
|
|
+ case RUNNING:
|
|
|
+ case PENDING://等待的
|
|
|
+ OkDownload.with().downloadDispatcher().cancel(task);
|
|
|
+ break;
|
|
|
+ case IDLE://空闲的
|
|
|
+ case UNKNOWN:
|
|
|
+ downloadUtil.start(downLoadInfo);
|
|
|
+ break;
|
|
|
+ case COMPLETED://有可能之前已经下载完成,但是数据库里已经没有数据了,这时只需要修改状态
|
|
|
+ if (task.getFile() != null) {
|
|
|
+ if (downloadUtil.checkFinish(downLoadInfo)) {//检查文件是否真的完成
|
|
|
+ downloadUtil.setDownloadTaskFinish(task.getUrl(), task.getFile().getAbsolutePath());
|
|
|
+ } else {//重新开始下载
|
|
|
+ downloadUtil.delete(downLoadInfo);
|
|
|
+ downloadUtil.start(downloadUtil.getDownloadTaskByUrl(taskEty));
|
|
|
+ downloadUtil.setDownloadTaskStatus(taskEty.getDownload_link(), DownloadUtil.STATUS_INIT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updateDownloadBtn(taskEty);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ new Thread(() -> {
|
|
|
+ if (downloadUtil.addDownloadTask(downLoadInfo)) {
|
|
|
+ //发送红点信息
|
|
|
+ EventBus.getDefault().post(BigEvent.get().setEventTypes(EventTypes.TIPS_DOWN_ICON));
|
|
|
+ }
|
|
|
+ }).start();
|
|
|
+ UMConfigUtils.onEvent(UMConfigUtils.Event.TASK_DOWNLOAD);
|
|
|
+ }
|
|
|
}
|